Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
4Activity
0 of .
Results for:
No results containing your search query
P. 1
introduction to java programming

introduction to java programming

Ratings: (0)|Views: 247|Likes:
Published by jonas1964
Uploaded from Google Docs
Uploaded from Google Docs

More info:

Published by: jonas1964 on May 08, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

01/30/2013

pdf

text

original

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
This is a PDF version of an on-line book that is available at
http://math.hws.edu/javanotes/. The PDF does not include

source code \ufb01les, solutions to exercises, or answers to quizzes, but
it does have external links to these resources, shown in blue.
In addition, each section has a link to the on-line version.
The PDF also has internal links, shown in red. These links can
be used inAcrobat Reader and some other PDF reader programs.

ii
c
\ue0001996\u20132007, David J. Eck

David J. Eck (eck@hws.edu)
Department of Mathematics and Computer Science
Hobart and William Smith Colleges

Geneva, NY 14456
This book can be distributed in unmodi\ufb01ed form with no restrictions.
Modi\ufb01ed versions can be made and distributed provided they are distributed
under the same license as the original. More speci\ufb01cally: 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
x
1 The Mental Landscape
1

1.1 Machine Language. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 1.2 AsynchronousEvents. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .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 TheInternet. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14 Quiz on Chapter 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17

2 Names and Things
18
2.1 The Basic Java Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
2.2 Variables and Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21
2.2.1 Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22

2.2.2 Types and Literals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23
2.2.3 Variables in Programs. . . . . . . . . . . . . . . . . . . . . . . . . . . . .26
2.3 Objects and Subroutines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27
2.3.1 Built-in Subroutines and Functions. . . . . . . . . . . . . . . . . . . . . .28
2.3.2 Operations on Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . .31
2.3.3 Introduction to Enums. . . . . . . . . . . . . . . . . . . . . . . . . . . . .33
2.4 Text Input and Output. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35
2.4.1 A First Text Input Example. . . . . . . . . . . . . . . . . . . . . . . . . .36

2.4.2 TextOutput. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37 2.4.3 TextIO Input Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . .38 2.4.4 FormattedOutput. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40 2.4.5 Introduction to File I/O. . . . . . . . . . . . . . . . . . . . . . . . . . . .42

2.5 Details of Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43 2.5.1 ArithmeticOperators. . . . . . . . . . . . . . . . . . . . . . . . . . . . .44 2.5.2 Increment and Decrement. . . . . . . . . . . . . . . . . . . . . . . . . . .45 2.5.3 RelationalOperators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45 2.5.4 BooleanOperators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46 2.5.5 ConditionalOperator. . . . . . . . . . . . . . . . . . . . . . . . . . . . .47 2.5.6 Assignment Operators and Type-Casts. . . . . . . . . . . . . . . . . . . .47 2.5.7 Type Conversion of Strings. . . . . . . . . . . . . . . . . . . . . . . . . .49 2.5.8 PrecedenceRules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49

2.6 ProgrammingEnvironments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .50
i

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->