Big Java 4

Chapter 1 – Introduction

Chapter Goals

What Is Programming?

Self Check 1.1

What is required to play a music CD on a computer?

Self Check 1.2

Why is a CD player less flexible than a computer?

Self Check 1.3

Can a computer program develop the initiative to execute tasks in a better way than its programmers envisioned?

The Anatomy of a Computer

Central Processing Unit

A Memory Module with Memory Chips

A Hard Disk

A Motherboard

Schematic Diagram of a Computer

The ENIAC

Self Check 1.4

Where is a program stored when it is not currently running?

Self Check 1.5

Which part of the computer carries out arithmetic operations, such as addition and multiplication?

Machine Code

Self Check 1.6

What is the code for the Java virtual machine instruction Load the contents of memory location 100?

Self Check 1.7

Does a person who uses a computer for office work ever run a compiler?

The Java Programming Language

Applet on a Web Page

Applet on a Web Page

Java Versions

Version Year Important New Features
1.0 1996  
1.1 1997 Inner classes
1.2 1998 Swing, Collections
1.3 2000 Performance enhancements
1.4 2002 Assertions, XML
5 2004 Generic classes, enhanced for loop, auto-boxing, enumerations
6 2006 Library improvements
7 2010 Small language changes and library improvements

Self Check 1.8

What are the two most important benefits of the Java language?

Self Check 1.9

How long does it take to learn the entire Java library?

ch01/hello/HelloPrinter.java

Your browser does not support the <object> tag. Program Run:

The Structure of a Simple Program: Class Declaration

The Structure of a Simple Program: main Method

The Structure of a Simple Program: Comment

The Structure of a Simple Program: Statements

The Structure of a Simple Program: Method Call

Syntax 1.1 Method Call

Syntax 1.1 Method Call

The Structure of a Simple Program: Strings

Self Check 1.10

How would you modify the HelloPrinter program to print the words "Hello," and "World!" on two lines?

Self Check 1.11

Would the program continue to work if you omitted the line starting with //?

Self Check 1.12

What does the following set of statements print?
System.out.print("My lucky number is");
System.out.println(3 + 4 + 5);

Editing a Java Program

Compiling and Running a Java Program

HelloPrinter in a Console Window

HelloPrinter in a Console Window

HelloPrinter in an IDE

HelloPrinter in an IDE

From Source Code to Running Program

From Source Code to Running Program

Self Check 1.13

Can you use a word processor for writing Java programs?

Self Check 1.14

What do you expect to see when you load a class file into your text editor?

Errors

Error Management Strategy

Self Check 1.15

Suppose you omit the // characters from the HelloPrinter.java program but not the remainder of the comment. Will you get a compile-time error or a run-time error?

Self Check 1.16

When you used your computer, you may have experienced a program that crashed (quit spontaneously) or hung (failed to respond to your input). Is that behavior a compile-time error or a run-time error?

Self Check 1.17

Why can't you test a program for run-time errors when it has compiler errors?

Algorithms

Pseudocode

Program Development Process

Program Development Process

Self Check 1.18

Investment Problem: You put $10,000 into a bank account that earns 5 percent interest per year. How many years does it take for the account balance to be double the original?

Algorithm:

Start with a year value of 0 and a balance of $10,000. 
Repeat the following steps while the balance is less than $20,000. 
   Add 1 to the year value. 
   Multiply the balance value by 1.05 (a 5 percent increase).

Suppose the interest rate was 20 percent. How long would it take for the investment to double?

Self Check 1.19

Suppose your cell phone carrier charges you $29.95 for up to 300 minutes of calls, and $0.45 for each additional minute, plus 12.5 percent taxes and fees. Give an algorithm to compute the monthly charge for a given number of minutes.