100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Summary Software Development To IT And Computer Science E-book Cooding $20.49   Add to cart

Summary

Summary Software Development To IT And Computer Science E-book Cooding

 8 views  0 purchase
  • Course
  • Institution

Software Development To IT And Computer Science BOOK

Preview 4 out of 781  pages

  • July 10, 2024
  • 781
  • 2023/2024
  • Summary
avatar-seller
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 web site includes
source code for all example programs, answers to quizzes,
and discussions and solutions for the exercises.

,ii




©1996–2022, 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 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 xiii

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

iii

, iv CONTENTS


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

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller annisapurwanto. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $20.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

62555 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$20.49
  • (0)
  Add to cart