Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary I am selling you future books (programming).

Rating
-
Sold
-
Pages
773
Uploaded on
07-10-2023
Written in
2023/2024

I am selling you future books (programming). I will present to you everything you will need in terms of knowledge of any programming language in the form of a book with a lot of useful information for you, and as you also know that programmers have very high salaries, I will help you to be great programmers I wish you a pleasant reading and learning.

Show more Read less
Institution
Course

Content preview

Introduction to Programming Using Java
Version 9, JavaFX Edition
May, 2022




David J. Eck
Hobart and William Smith Colleges




This is a PDF version of a free on-line book that is available at
https://math.hws.edu/javanotes/. The PDF does not include
source code files, solutions to exercises, or answers to quizzes, but
it does have external links to these resources, shown in blue.
The PDF also has internal links, shown in red. These links can
be used in Acrobat Reader and some other PDF reader programs.

, ii




©1996–2022, 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 for non-commercial purposes.
Modified versions can be made and distributed for non-commercial purposes
provided they are distributed under the same license as the original. More
specifically: This work is licensed under the Creative Commons Attribution-
NonCommercial-ShareAlike 4.0 License. To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/4.0/. Other uses require
permission from the author.

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

,Contents

Preface xi

1 The Mental Landscape 1
1.1 Machine Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Asynchronous Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 The Java Virtual Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.4 Building Blocks of Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.5 Object-oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.6 The Modern User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.7 The Internet and Beyond . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Quiz on Chapter 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

2 Names and Things 19
2.1 The Basic Java Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.2 Variables and Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.2.1 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.2.2 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.2.3 Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.2.4 Strings and String Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.2.5 Variables in Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.3 Objects and Subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.3.1 Built-in Subroutines and Functions . . . . . . . . . . . . . . . . . . . . . . 30
2.3.2 Classes and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.3.3 Operations on Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.3.4 Text Blocks: Multiline Strings . . . . . . . . . . . . . . . . . . . . . . . . 36
2.3.5 Introduction to Enums . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.4 Text Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.4.1 Basic Output and Formatted Output . . . . . . . . . . . . . . . . . . . . . 39
2.4.2 A First Text Input Example . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.4.3 Basic TextIO Input Functions . . . . . . . . . . . . . . . . . . . . . . . . . 42
2.4.4 Introduction to File I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.4.5 Other TextIO Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.4.6 Using Scanner for Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
2.5 Details of Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
2.5.1 Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.5.2 Increment and Decrement . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.5.3 Relational Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
2.5.4 Boolean Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

i

, CONTENTS ii


2.5.5 Conditional Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
2.5.6 Assignment Operators and Type Conversion . . . . . . . . . . . . . . . . 53
2.5.7 Precedence Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
2.6 Programming Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
2.6.1 Getting a JDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
2.6.2 Command Line Environment . . . . . . . . . . . . . . . . . . . . . . . . . 57
2.6.3 Eclipse IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
2.6.4 BlueJ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
2.6.5 The Problem of Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
2.6.6 About jshell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
2.6.7 JavaFX on the Command Line . . . . . . . . . . . . . . . . . . . . . . . . 66
2.6.8 Using JavaFX in Eclipse . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Exercises for Chapter 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Quiz on Chapter 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

3 Control 75
3.1 Blocks, Loops, and Branches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
3.1.1 Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
3.1.2 The Basic While Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
3.1.3 The Basic If Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.1.4 Control Abstractiont . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.1.5 Definite Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
3.2 Algorithm Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
3.2.1 Pseudocode and Stepwise Refinement . . . . . . . . . . . . . . . . . . . . 83
3.2.2 The 3N+1 Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
3.2.3 Coding, Testing, Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . 89
3.3 while and do..while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
3.3.1 The while Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
3.3.2 The do..while Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
3.3.3 break and continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
3.4 The for Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
3.4.1 For Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
3.4.2 Example: Counting Divisors . . . . . . . . . . . . . . . . . . . . . . . . . . 100
3.4.3 Nested for Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
3.5 The if Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
3.5.1 The Dangling else Problem . . . . . . . . . . . . . . . . . . . . . . . . . . 106
3.5.2 Multiway Branching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
3.5.3 If Statement Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
3.5.4 The Empty Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
3.6 The switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
3.6.1 The Basic switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . 113
3.6.2 Menus and switch Statements . . . . . . . . . . . . . . . . . . . . . . . . . 115
3.6.3 Enums in switch Statements . . . . . . . . . . . . . . . . . . . . . . . . . 116
3.6.4 Definite Assignment and switch Statements . . . . . . . . . . . . . . . . . 117
3.6.5 Switch Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
3.6.6 The Traditional switch Statement . . . . . . . . . . . . . . . . . . . . . . 118
3.7 Exceptions and try..catch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

Written for

Institution
Course

Document information

Uploaded on
October 7, 2023
Number of pages
773
Written in
2023/2024
Type
SUMMARY

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
Michael2030

Also available in package deal

Get to know the seller

Seller avatar
Michael2030 Published
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
44
Last sold
-
programming books

I am selling you future books (programming). I will present to you everything you will need in terms of knowledge of any programming language in the form of a book with a lot of useful information for you, and as you also know that programmers have very high salaries, I will help you to be great programmers I wish you a pleasant reading and learning.

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

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions