A GUIDE TO PROGRAMMING IN JAVA

3y ago
106 Views
11 Downloads
7.51 MB
408 Pages
Last View : 1d ago
Last Download : 1m ago
Upload by : Mariam Herr
Transcription

A GUIDE TOPROGRAMMING INJava 2 Platform Standard Edition 5Beth BrownJAVA

A Guide to Programmingin Java Java 2 Platform Standard Edition 5Beth Brown

Copyright 2005byFirst EditionISBN 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 usedin any form or by any means—graphic, electronic, or mechanical, including photocopying,recording, taping, or information storage and retrieval systems—without the written permissionof the publisher, with the exception of programs, which may be entered, stored, and executedin a computer system, but not reprinted for publication or resold in any other form.Printed in the United States of AmericaAll orders including educational, Canadian, foreign,FPO, and APO may be placed by contacting:Lawrenceville Press, Inc.P.O. Box 704Pennington, NJ 08534-0704(609) 737-1148(609) 737-8564 faxThis text is available in hardcover and softcover editions.16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1The text is written and published by Lawrenceville Press, Inc. and is in no wayconnected with the Sun Corporation.Sun , Sun Microsystems, and Java are trademarks or registered trademarks ofSun Microsystems, Inc. in the United States and other countries.Microsoft Microsoft Windows , Visual Basic , and Microsoft Calculator areeither registered trademarks or trademarks of Microsoft Corporation in the UnitedStates and/or other countries. Screen Shots and Icons reprinted with permissionfrom Microsoft Corporation.Mac OS and Tiger are registered trademarks of Apple Computer, Inc. in theUnited 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 purposesonly and may be trademarks of their respective owners.

PrefaceWe have strived to make this the clearest and most comprehensiveJava 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, andsuggestions from other experienced instructors to determine how best topresent programming concepts.For the best classroom experience for both the student and the instructor,our comprehensive text book includes hands-on reviews, critical-thinkingquestions, and exercises of varying difficulty levels. Additionally, ourTeacher Resource Materials correlate directly to the text book and offerteaching hints for explaining difficult concepts, additional lessons andexercises, 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 toall the reviews and exercises.It is our belief that learning to program offers the student an invaluableopportunity to develop problem-solving skills. The process of defining aproblem, breaking it down into a series of smaller problems, and finallywriting 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 humanelement—is more important than the machine.A Guide to Programming in Java is written for a one-term or two-termcourse. No previous programming experience is required or assumed. Itis our goal that this text provide students the best possible introductionto programming using Java and to prepare them for further study in theIT/programming/computer science field.Prefaceiii

Design and FeaturesProgramming Concepts This text emphasizes the fundamental conceptsof 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 codeconventions.Programming Style Throughout the text, proper programming styleis 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 shownboth proper programming techniques and the output actually producedby an application.Reviews Numerous reviews are presented throughout each chapter toprovide immediate reinforcement of newly learned concepts. Solutions tothe reviews are included on the Teacher Resource Materials CD.Case Studies Most chapters end by stating a problem, developing anappropriate algorithm, and then implementing the solution. The processof specification, design, implementation, and debugging and testing isclearly outlined.Chapter Summaries Each chapter ends by summarizing the conceptsand statements covered in the chapter.Vocabulary Sections Each chapter contains a vocabulary section thatdefines 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. Mostexercises include a demonstration run to help make clear what output isexpected from the student’s application. Exercises based on previous workare marked with a ö symbol. Answers to the exercises are included onthe Teacher Resource Materials CD.Indexes In addition to a standard index, an index of the applicationspresented in the text is also included.Appendix A chart of Unicode symbols is included.Online Resources Materials that complement and extend this text are freefor download and distribution in your class. Information about variousJava compilers is available. Supplemental chapters cover operating systems,personal finances, introduction to computers, and keyboarding skills arealso provided. Students can download all the files needed to complete thereviews and exercises from www.lpdatafiles.com.ivA Guide to Programming in Java

Teacher Resource MaterialsOur Teacher Resource Materials correlate directly to the text book andprovide all the additional materials required to offer students an excellentcomputer applications course. The Teacher Resource Materials feature: START HERE.htm Help files and a guide for using the text andresource materials. Lesson Plans Lessons in PDF format keyed to the chapters in thetext. Each lesson includes assignments, teaching notes, worksheets,and additional topics. Tutorials Flash movie files that provide animations to illustratesearching and sorting concepts. Each movie is keyed to the text. PowerPoint Presentations Topics keyed to the text are inPowerPoint 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 thinkingquestions presented in the text. Data files All the files the student needs to complete the reviewsand exercises in the text, as well as the files needed to completethe worksheets and tests. ExamView Software Question banks keyed to the text and thepopular ExamView software are included to create tests, quizzes,and additional assessment materials. Answer files Answers to the reviews, exercises, worksheets, andtests.AcknowledgmentsSpecial thanks to the many instructors who used this text in theirclassroom as it was being written. I would especially like to thank thefollowing instructors for their many comments and suggestions:Paul MasseyHanna-Westside Extension CampusEdward Sapienza Peabody Veterans Memorial High SchoolTimothy StrohmChurchville-Chili Senior High SchoolJackie KygerMarine Military AcademyJan Marrelli, a Lawrenceville Press author and editor, has contributedmuch to this text. She has used this text as it was being written in herclassroom. The many comments and suggestions from her and her students have helped to make this text so clearly written. Jan, an experiencedinstructor, has also written many of the critical thinking questions, exercises, and reviews.Prefacev

Elaine Malfas, senior technical editor at Lawrenceville Press, has produced the format and layout for this text. The many illustrations have beencreated by Elaine as well.Thanks also to Joseph Dupree in our Customer Relations Departmentfor 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 andChristina Albanesius run our Customer Relations Department and handlethe thousands of orders we receive in a friendly and efficient manner.Michael Porter is responsible for the excellent service Lawrenceville Pressoffers in the shipping of orders.About the AuthorBeth A. Brown, a Computer Science graduate of Florida AtlanticUniversity, is director of development at Lawrenceville Press where shehas coauthored a number of programming and applications texts andtheir accompanying Teacher Resource Materials. She has taught computerapplications and programming at the high school level.viA Guide to Programming in Java

Chapter ExpectationsChapter 1 – An Introduction toComputersAfter completing Chapter 1, studentswill be able to:1. Compare and contrast various input, output,and storage devices.2. Identify hardware components and explaintheir function.3. Demonstrate knowledge of operating systems.4. Discuss different computer classifications andcompatibility issues.5. Differentiate among the levels of programminglanguages.6. Describe communication and networkingcomponents.7. Understand the binary number system.8. Describe how data is stored in memory and infiles.9. Use Internet services to access information andshare resources.10. Demonstrate proper etiquette and knowledgeof acceptable use policies when using anetwork.11. Discuss social and ethical issues associatedwith computer use.Chapter 2 – Applets and WebProgrammingAfter completing Chapter 2, studentswill be able to:1. Define terminology associated with the WorldWide Web.2. Discuss the impact of programming on theWorld Wide Web community.3. Create HTML documents.4. Explain how a web browser interprets anHTML document.5. Use JavaScript to demonstrate how scripts canenhance a website.6. Create simple Java applets.7. Specify custom values for a Java applet that hasbeen placed in an HTML document.8. Apply a style sheet to an HTML document.Chapter 3 – Introducing JavaAfter completing Chapter 3, studentswill be able to:1. Define terminology associated with objectoriented programming.2. Explain why Java is a widely usedprogramming language.3. Create Java applications.4. Describe the process involved in executing aJava application.5. Display and format program output.6. Annotate code properly with comments,formatting, and indentation.7. Explain the importance of using codeconventions.8. Demonstrate algorithm design as a problemsolving strategy.9. Use visual organizers to design solutions.Chapter 4 – Variables and ConstantsAfter completing Chapter 4, studentswill be able to:1. Declare and initialize variables and constantsusing the appropriate data type.2. Choose legal identifiers that follow goodprogramming style.3. Differentiate between primitive and abstractdata types.4. Explain how to access Java packages.5. Demonstrate how to read data from an inputstream.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.Prefacevii

Chapter 5 – Conditional ControlStructuresChapter 8 – Classes and ObjectOriented DevelopmentAfter completing Chapter 5, studentswill be able to:1. Demonstrate the use of decision structures tocontrol the flow of a program.2. Describe how a roundoff error can occur.3. Generate random numbers.4. Write compound Boolean expressions.5. Access methods in the Math class.6. Modify existing code.7. Develop code with correct and efficient use ofconditional control structures.8. Select appropriate test data.9. Create and modify solutions to problems.After completing Chapter 8, studentswill be able to:1. Understand and instantiate objects.2. Design and implement a class.3. Apply functional decomposition.4. Apply appropriate naming conventions to aclass.5. Explain the difference between accessor,modifier, and helper methods.6. Write constructors.7. Compare and contrast instance and classmembers.8. Understand class specifications and therelationships among the classes.9. Understand and implement a given classhierarchy.10. Apply encapsulation.11. Identify reusable code from existing code.Chapter 6 – Loop Structures andStringsAfter completing Chapter 6, studentswill be able to:1. Demonstrate the use of repetition controlstructures.2. Explain how infinite loops can occur.3. Differentiate between counters andaccumulators.4. Use various tools and techniques to debug anapplication.5. Manipulate and compare strings using theString class and its methods.6. Develop code with correct and efficient use ofrepetitive control structures.7. Apply problem solving strategies.Chapter 7 – Chapter MethodsAfter completing Chapter 7, studentswill be able to:1. Use top-down development and proceduralabstraction to develop problem solutions.2. Write methods.3. Use method parameters.4. Demonstrate the use of method overloading.5. Return values from a method.6. Write appropriate method documentation,including pre- and post-conditions.7. Identify boundary cases and generateappropriate test data.8. Describe code conventions that apply tomethods.viiiA Guide to Programming in JavaChapter 9 – Inheritance andPolymorphismAfter completing Chapter 9, studentswill be able to:1. Extend a class using inheritance.2. Explain an is-a relationship.3. Implement a subclass.4. Define and demonstrate polymorphism.5. Understand abstract classes.6. Declare and implement an interface.7. Extend existing code using inheritance.Chapter 10 – ArraysAfter completing Chapter 10, studentswill be able to:1. Describe types of problems that benefit fromthe use of arrays.2. Create one and two dimensional arrays.3. Include array parameters in a methoddeclaration.4. Understand how to implement arrays withmeaningful indexes.5. Apply offset array indexes.6. Manipulate characters in a string.7. Understand the digital code, Unicode.8. Apply search algorithms to an array.9. Use methods in the ArrayList class.10. Demonstrate the use of the Wrapper classes.

Chapter 11 – GUIS and Event-DrivenProgrammingAfter completing Chapter 11, studentswill be able to:1. Design graphical user interfaces.2. Use component classes in the Java swingpackage.3. Create event-driven applications.4. Control the layout of an interface using layoutmanagers.5. Use text fields and combo boxes to obtain userinput.6. Apply color and add images to an interface.Chapter 14 – Data StructuresAfter completing Chapter 14, studentswill be able to:1. Explain how data structures, such as stacksand queues, can be used to organize data.2. Use and implement well known datastructures.3. Describe standard operations associated withdata structures.4. Choose appropriate data structures.5. Differentiate between a LIFO and FIFOstructure.Chapter 12 – Files and ExceptionHandlingAfter completing Chapter 12, studentswill be able to:1. Use the File class to create objects thatrepresent a file.2. Write exception handlers.3. Understand file streams.4. Read the contents of an existing file.5. Process numeric data.6. Create an output file stream.7. Explain the object serialization anddeserialization processes.Chapter 13 – Recursion andAdvanced AlgorithmsAfter completing Chapter 13, studentswill be able to:1. Implement the selection sort algorithms.2. Sort objects using the Comparable interface.3. Implement the insertion sort algorithm.4. Define and demonstrate recursion.5. Implement the mergesort algorithm.6. Implement the binary search algorithm.7. Explain the recursive technique, depth-firstsearching.8. Analyze algorithms for efficiency.9. Design and document sequential searchalgorithms.Prefaceix

xA Guide to Programming in Java

Table of ContentsChapter 1 – An Introduction toComputersChapter 2 – Applets and WebProgrammingDesktop Computing .1Operating Systems and Environment .2Mobile Computing .4Programming Languages .5Networks . 6Number Systems .9Storing Data in Memory . 10What is a File? . 11Storage Devices. 12Intranet, Extranet, Internet . 13Telecommunications . 14Internet Services: Web, E-mail, andMailing Lists . 15Finding Information on the Web andDownloading Files . 16Internet Privacy Issues . 18Internet Acceptable Use Policy . 19The Social and Ethical Implications ofComputer Use . 19Protecting Computer Software and Data . 20The Ethical Responsibilities of an ITProfessional .22Chapter Summary .22Vocabulary . 25Review Questions . 29Exercises . 32The World Wide Web. 35HTML . 36Creating an HTML Document . 37Review: hello world.htm . 38Review: Computer Viruses Website –part 1 of 6 . 38JavaScript . 38Review: welcome.htm. 39Review: Computer Viruses Website –part 2 of 6 . 39Using Scripts to Enhance a Website . 40Review: Computer Viruses Website –part 3 of 6 . 41Review: System Check – part 1 of 2 . 41Java Applets . 41Creating Java Applets . 41Drawing Shapes and Adding Color .43Review: Hot Air Balloon .44Placing an Applet in an HTML Document .44Applet Parameters .44Review: System Check – part 2 of 2 . 45HTML Tags . 45Review: Computer Viruses Website –part 4 of 6 . 47Hyperlinks, Tables, and Images . 47Review: Computer Viruses Website –part 5 of 6 .

A Guide to Programming in Java is written for a one-term or two-term course. No previous programming experience is required or assumed. . ment programming solutions with proper algorithm design and code conventions. Programming Style Throughout the text, proper programming style . Each lesson includes assignments, teaching notes, worksheets,

Related Documents:

work/products (Beading, Candles, Carving, Food Products, Soap, Weaving, etc.) ⃝I understand that if my work contains Indigenous visual representation that it is a reflection of the Indigenous culture of my native region. ⃝To the best of my knowledge, my work/products fall within Craft Council standards and expectations with respect to

Object Oriented Programming 7 Purpose of the CoursePurpose of the Course To introduce several programming paradigms including Object-Oriented Programming, Generic Programming, Design Patterns To show how to use these programming schemes with the C programming language to build “good” programs.

Functional programming paradigm History Features and concepts Examples: Lisp ML 3 UMBC Functional Programming The Functional Programming Paradigm is one of the major programming paradigms. FP is a type of declarative programming paradigm Also known as applicative programming and value-oriented

1 1 Programming Paradigms ØImperative Programming – Fortran, C, Pascal ØFunctional Programming – Lisp ØObject Oriented Programming – Simula, C , Smalltalk ØLogic Programming - Prolog 2 Parallel Programming A misconception occurs that parallel

About this Programming Manual The PT Programming Manual is designed to serve as a reference to programming the Panasonic Hybrid IP-PBX using a Panasonic proprietary telephone (PT) with display. The PT Programming Manual is divided into the following sections: Section 1, Overview Provides an overview of programming the PBX. Section 2, PT Programming

Programming paradigms Structured programming: all programs are seen as composed of control structures Object-oriented programming (OOP): Java, C , C#, Python Functional programming: Clojure, Haskell Logic programming based on formal logic: Prolog, Answer set programming (ASP), Datalog

Programming is the key word here because you make the computer do what you want by programming it. Programming is like putting the soul inside a body. This book intends to teach you the basics of programming using GNU Smalltalk programming language. GNU Smalltalk is an implementation of the Smalltalk-80 programming language and

akuntansi musyarakah (sak no 106) Ayat tentang Musyarakah (Q.S. 39; 29) لًََّز ãَ åِاَ óِ îَخظَْ ó Þَْ ë Þٍجُزَِ ß ا äًَّ àَط لًَّجُرَ íَ åَ îظُِ Ûاَش