100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Class notes

Java programing complete Notes

Rating
-
Sold
-
Pages
699
Uploaded on
18-06-2024
Written in
2023/2024

Part of O'Reilly's definitive set of Java documentation, Learning Java introduces the basics of Java, the object-oriented programming language for networked applications from Sun Microsystems. This book provides a broad survey of the Java 2 Standard Edition and contains everything necessary to get up to speed quickly. It covers the essentials of hot topics like Swing and JFC; describes new tools for signing applets and other Java classes; and shows how to write networked clients and servers, servlets, JavaBeans, and state-of-the-art user interfaces. Java started out as a tool for creating animated web pages, but it's proven to be much more. Java is now used for everything from sophisticated web clients to mission-critical enterprise applications. In the future, Java will become the basis for a new generation of distributed software that runs on devices ranging from cell phones to supercomputers. In the practical, hands-on approach characteristic of O'Reilly, Learning Java demonstrates why Java is now the language of choice for building the next generation of computer software. Includes a CD-ROM containing the example code and JBuilder for Windows and Solaris. Learning Java covers:

Show more Read less
Institution
Course











Whoops! We can’t load your doc right now. Try again or contact support.

Connected book

Written for

Institution
Secondary school
Course
School year
5

Document information

Uploaded on
June 18, 2024
Number of pages
699
Written in
2023/2024
Type
Class notes
Professor(s)
Mr. rahul sharma
Contains
All classes

Subjects

Content preview

Introduction to Programming Using Java
Version 5.0, December 2006

(Version 5.0.2, with minor corrections, November 2007)




David J. Eck
Hobart and William Smith Colleges

,ii




c 1996–2007, David J. Eck

David J. Eck ()
Department of Mathematics and Computer Science
Hobart and William Smith Colleges
Geneva, NY 14456

This book can be distributed in unmodified form with no restrictions.
Modified versions can be made and distributed provided they are distributed
under the same license as the original. More specifically: This work is
licensed under the Creative Commons Attribution-Share Alike 2.5 License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-
sa/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th
Floor, San Francisco, California, 94105, USA.

The web site for this book is: http://math.hws.edu/javanotes

,Contents

Preface xiii

1 The Mental Landscape 1
1.1 Machine Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Asynchronous Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 The Java Virtual Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.4 Building Blocks of Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.5 Object-oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.6 The Modern User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.7 The Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Quiz on Chapter 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

2 Names and Things 19
2.1 The Basic Java Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.2 Variables and Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.2.1 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.2.2 Types and Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.2.3 Variables in Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.3 Objects and Subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.3.1 Built-in Subroutines and Functions . . . . . . . . . . . . . . . . . . . . . . 29
2.3.2 Operations on Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2.3.3 Introduction to Enums . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.4 Text Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.4.1 A First Text Input Example . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.4.2 Text Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.4.3 TextIO Input Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.4.4 Formatted Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.4.5 Introduction to File I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.5 Details of Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.5.1 Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
2.5.2 Increment and Decrement . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.5.3 Relational Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.5.4 Boolean Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
2.5.5 Conditional Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
2.5.6 Assignment Operators and Type-Casts . . . . . . . . . . . . . . . . . . . . 48
2.5.7 Type Conversion of Strings . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.5.8 Precedence Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.6 Programming Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

iii

, iv CONTENTS


2.6.1 Java Development Kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
2.6.2 Command Line Environment . . . . . . . . . . . . . . . . . . . . . . . . . 52
2.6.3 IDEs and Eclipse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
2.6.4 The Problem of Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Exercises for Chapter 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Quiz on Chapter 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

3 Control 61
3.1 Blocks, Loops, and Branches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
3.1.1 Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
3.1.2 The Basic While Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
3.1.3 The Basic If Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
3.2 Algorithm Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
3.2.1 Pseudocode and Stepwise Refinement . . . . . . . . . . . . . . . . . . . . 66
3.2.2 The 3N+1 Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
3.2.3 Coding, Testing, Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . 72
3.3 while and do..while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
3.3.1 The while Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
3.3.2 The do..while Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
3.3.3 break and continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.4 The for Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.4.1 For Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
3.4.2 Example: Counting Divisors . . . . . . . . . . . . . . . . . . . . . . . . . . 83
3.4.3 Nested for Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
3.4.4 Enums and for-each Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
3.5 The if Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
3.5.1 The Dangling else Problem . . . . . . . . . . . . . . . . . . . . . . . . . . 89
3.5.2 The if...else if Construction . . . . . . . . . . . . . . . . . . . . . . . . . . 89
3.5.3 If Statement Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
3.5.4 The Empty Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
3.6 The switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
3.6.1 The Basic switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . 96
3.6.2 Menus and switch Statements . . . . . . . . . . . . . . . . . . . . . . . . . 97
3.6.3 Enums in switch Statements . . . . . . . . . . . . . . . . . . . . . . . . . 98
3.6.4 Definite Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
3.7 Exceptions and try..catch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
3.7.1 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
3.7.2 try..catch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
3.7.3 Exceptions in TextIO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
3.8 GUI Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Exercises for Chapter 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Quiz on Chapter 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114

4 Subroutines 117
4.1 Black Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
4.2 Static Subroutines and Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
4.2.1 Subroutine Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
4.2.2 Calling Subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
$2.99
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
sanketray2010

Get to know the seller

Seller avatar
sanketray2010
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
1 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions