A GUIDE TO PROGRAMMING IN JAVA - Mr. Barrett's Class

JAVA A GUIDE TO

TM

PROGRAMMING IN

JavaTM 2 Platform Standard Edition 5

Beth Brown

A Guide to Programming in JavaTM

JavaTM 2 Platform Standard Edition 5

Beth Brown

Copyright 2005 by

First Edition

ISBN 1-58003-071-8 (softcover) ISBN 1-58003-072-6 (hardcover)

All rights reserved. No part of this work covered by the copyright may be reproduced or used in any form or by any means--graphic, electronic, or mechanical, including photocopying, recording, taping, or information storage and retrieval systems--without the written permission of the publisher, with the exception of programs, which may be entered, stored, and executed in a computer system, but not reprinted for publication or resold in any other form.

Printed in the United States of America

All orders including educational, Canadian, foreign, FPO, and APO may be placed by contacting:

Lawrenceville Press, Inc. P.O. Box 704 Pennington, NJ 08534-0704 (609) 737-1148 (609) 737-8564 fax

This text is available in hardcover and softcover editions.

16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

The text is written and published by Lawrenceville Press, Inc. and is in no way connected with the Sun? Corporation. Sun?, Sun? Microsystems, and JavaTM are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. Microsoft? Microsoft? Windows?, Visual Basic?, and Microsoft? Calculator are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Screen Shots and Icons reprinted with permission from Microsoft? Corporation. Mac OS? and TigerTM are registered trademarks of Apple Computer, Inc. in the United States and other countries. ExamView is a registered trademark of FSCreations, Inc. "JUNE BUGS" poem by Avis Harley used with permission from Boyds Mills Press. Names of all other products mentioned herein are used for identification purposes only and may be trademarks of their respective owners.

Preface

We have strived to make this the clearest and most comprehensive

Java text available. Our primary objective in this text is to present material in clear language with easy to follow examples. To meet this objective, we use our teaching experiences as well as the feedback, comments, and suggestions from other experienced instructors to determine how best to present programming concepts.

For the best classroom experience for both the student and the instructor, our comprehensive text book includes hands-on reviews, critical-thinking questions, and exercises of varying difficulty levels. Additionally, our Teacher Resource Materials correlate directly to the text book and offer teaching hints for explaining difficult concepts, additional lessons and exercises, and a comprehensive question bank for creating tests, quizzes, and reviews. The Teacher Resource Materials include the applications, Case Studies, and vocabulary from the text book, as well as answers to all the reviews and exercises.

It is our belief that learning to program offers the student an invaluable opportunity to develop problem-solving skills. The process of defining a problem, breaking it down into a series of smaller problems, and finally writing an application to solve it exercises a student's logical abilities. Additionally, the student is made aware of the capabilities and limitations of a computer and soon realizes that the programmer--the human element--is more important than the machine.

A Guide to Programming in Java is written for a one-term or two-term course. No previous programming experience is required or assumed. It is our goal that this text provide students the best possible introduction to programming using Java and to prepare them for further study in the IT/programming/computer science field.

Preface

iii

Design and Features

Programming Concepts This text emphasizes the fundamental concepts of programming so that this knowledge can be applied to other programming languages.

Problem Solving From the very beginning, students are taught to implement programming solutions with proper algorithm design and code conventions.

Programming Style Throughout the text, proper programming style is emphasized so that students can make their applications easy to read, modify, and debug.

Demonstration Applications and Runs Many demonstration applications are included, complete with sample runs, so that students are shown both proper programming techniques and the output actually produced by an application.

Reviews Numerous reviews are presented throughout each chapter to provide immediate reinforcement of newly learned concepts. Solutions to the reviews are included on the Teacher Resource Materials CD.

Case Studies Most chapters end by stating a problem, developing an appropriate algorithm, and then implementing the solution. The process of specification, design, implementation, and debugging and testing is clearly outlined.

Chapter Summaries Each chapter ends by summarizing the concepts and statements covered in the chapter.

Vocabulary Sections Each chapter contains a vocabulary section that defines new terms. A separate section lists Java keywords, statements, and classes.

Critical Thinking Written response questions that require critical thinking from the student are included at the end of each chapter.

Exercises Each chapter includes a large set of exercises of varying difficulty, making them appropriate for students with a range of abilities. Most exercises include a demonstration run to help make clear what output is expected from the student's application. Exercises based on previous work are marked with a ? symbol. Answers to the exercises are included on the Teacher Resource Materials CD.

Indexes In addition to a standard index, an index of the applications presented in the text is also included.

Appendix A chart of Unicode symbols is included.

Online Resources Materials that complement and extend this text are free for download and distribution in your class. Information about various Java compilers is available. Supplemental chapters cover operating systems, personal finances, introduction to computers, and keyboarding skills are also provided. Students can download all the files needed to complete the reviews and exercises from .

iv

A Guide to Programming in Java

Teacher Resource Materials

Our Teacher Resource Materials correlate directly to the text book and provide all the additional materials required to offer students an excellent computer applications course. The Teacher Resource Materials feature:

? START_HERE.htm Help files and a guide for using the text and resource materials.

? Lesson Plans Lessons in PDF format keyed to the chapters in the text. Each lesson includes assignments, teaching notes, worksheets, and additional topics.

? Tutorials Flash movie files that provide animations to illustrate searching and sorting concepts. Each movie is keyed to the text.

? PowerPoint Presentations Topics keyed to the text are in PowerPoint files for presentation.

? Vocabulary Word files of the vocabulary presented in the text.

? Rubrics Rubrics keyed to exercises in the text for assessment.

? Worksheets Programming assignments that supplement the exercises in the text provide additional reinforcement of concepts.

? Critical Thinking Answers Answers for the critical thinking questions presented in the text.

? Data files All the files the student needs to complete the reviews and exercises in the text, as well as the files needed to complete the worksheets and tests.

? ExamView? Software Question banks keyed to the text and the popular ExamView? software are included to create tests, quizzes, and additional assessment materials.

? Answer files Answers to the reviews, exercises, worksheets, and tests.

Acknowledgments

Special thanks to the many instructors who used this text in their classroom as it was being written. I would especially like to thank the following instructors for their many comments and suggestions:

Paul Massey

Hanna-Westside Extension Campus

Edward Sapienza Peabody Veterans Memorial High School

Timothy Strohm Churchville-Chili Senior High School

Jackie Kyger

Marine Military Academy

Jan Marrelli, a Lawrenceville Press author and editor, has contributed much to this text. She has used this text as it was being written in her classroom. The many comments and suggestions from her and her students have helped to make this text so clearly written. Jan, an experienced instructor, has also written many of the critical thinking questions, exercises, and reviews.

Preface

v

Elaine Malfas, senior technical editor at Lawrenceville Press, has produced the format and layout for this text. The many illustrations have been created by Elaine as well.

Thanks also to Joseph Dupree in our Customer Relations Department for some of the original drawings included in this text.

The success of this and all of our texts is due to the efforts of Heidi Crane, Vice President of Marketing at Lawrenceville Press. Joseph Dupree and Christina Albanesius run our Customer Relations Department and handle the thousands of orders we receive in a friendly and efficient manner. Michael Porter is responsible for the excellent service Lawrenceville Press offers in the shipping of orders.

About the Author

Beth A. Brown, a Computer Science graduate of Florida Atlantic University, is director of development at Lawrenceville Press where she has coauthored a number of programming and applications texts and their accompanying Teacher Resource Materials. She has taught computer applications and programming at the high school level.

vi

A Guide to Programming in Java

Chapter Expectations

Chapter 1 ? An Introduction to Computers

After completing Chapter 1, students will be able to: 1. Compare and contrast various input, output,

and storage devices. 2. Identify hardware components and explain

their function. 3. Demonstrate knowledge of operating systems. 4. Discuss different computer classifications and

compatibility issues. 5. Differentiate among the levels of programming

languages. 6. Describe communication and networking

components. 7. Understand the binary number system. 8. Describe how data is stored in memory and in

files. 9. Use Internet services to access information and

share resources. 10. Demonstrate proper etiquette and knowledge

of acceptable use policies when using a network. 11. Discuss social and ethical issues associated with computer use.

Chapter 2 ? Applets and Web Programming

After completing Chapter 2, students will be able to: 1. Define terminology associated with the World

Wide Web. 2. Discuss the impact of programming on the

World Wide Web community. 3. Create HTML documents. 4. Explain how a web browser interprets an

HTML document. 5. Use JavaScript to demonstrate how scripts can

enhance a website. 6. Create simple Java applets. 7. Specify custom values for a Java applet that has

been placed in an HTML document. 8. Apply a style sheet to an HTML document.

Chapter 3 ? Introducing Java

After completing Chapter 3, students will be able to: 1. Define terminology associated with object-

oriented programming. 2. Explain why Java is a widely used

programming language. 3. Create Java applications. 4. Describe the process involved in executing a

Java application. 5. Display and format program output. 6. Annotate code properly with comments,

formatting, and indentation. 7. Explain the importance of using code

conventions. 8. Demonstrate algorithm design as a problem-

solving strategy. 9. Use visual organizers to design solutions.

Chapter 4 ? Variables and Constants

After completing Chapter 4, students will be able to: 1. Declare and initialize variables and constants

using the appropriate data type. 2. Choose legal identifiers that follow good

programming style. 3. Differentiate between primitive and abstract

data types. 4. Explain how to access Java packages. 5. Demonstrate how to read data from an input

stream. 6. Write numeric expressions. 7. Apply type casting. 8. Format numeric output. 9. Identify Java keywords. 10. Differentiate between syntax and logic errors. 11. Understand run-time exceptions. 12. Read and understand a problem description,

purpose, and goals.

Preface

vii

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download