Outline
2.1 Introduction
2.2 A First Program in Java: Printing a Line of Text
2.2.1 Compiling and Executing your First Java Application2.3 Modifying Our First Java Program
2.3.1 Displaying a Single Line of Text with Multiple Statements 2.3.2 Displaying Multiple Lines of Text with a Single Statement2.4 Displaying Text in a Dialog Box
2.5 Another Java Application: Adding Integers
2.6 Memory Concepts
2.7 Arithmetic
2.8 Decision Making: Equality and Relational Operators
2.9 (Optional Case Study) Thinking About Objects: Examining the Problem Statement
2.1 Introduction
In this chapter......
Introduce examples to illustrate features of Java
Two program styles - applications and applets
2.2 A Simple Program: Printing a Line of Text
Application........
Program that executes using the java interpreter
Sample program.........
Show program, then analyze each line
2.2 A Simple Program: Printing a Line of Text
Blank line.......
Makes program more readable
Blank lines, spaces, and tabs are white-space characters
Ignored by compiler
Begins class definition for class Welcome1
Every Java program has at least one user-defined class
Keyword: words reserved for use by Java
class keyword followed by class name
Naming classes: capitalize every word
SampleClassName
2.2 A Simple Program: Printing a Line of Text
Name of class called identifier.........
Series of characters consisting of letters, digits, underscores ( _ ) and dollar signs ( $ )
Does not begin with a digit, has no spaces
Examples: Welcome1, $value, _value, button7
7button is invalid
Java is case sensitive (capitalization matters)
a1 and A1 are different
For chapters 2 to 7, use public keyword..........
Certain details not important now
Mimic certain features, discussions later
2.2 A Simple Program: Printing a Line of Text
Saving files......................
File name must be class name with .java extension
Welcome1.java
Left brace {
Begins body of every class
Right brace ends definition (line 13)
Part of every Java application
Applications begin executing at main
Parenthesis indicate main is a method (ch. 6)
Java applications contain one or more methods
2.2 A Simple Program: Printing a Line of Text
Exactly one method must be called main
Methods can perform tasks and return information
void means main returns no information
For now, mimic main's first line
Left brace begins body of method definition
Ended by right brace } (line 11)
2.2 A Simple Program: Printing a Line of Text
Instructs computer to perform an action
Prints string of characters
String - series characters inside double quotes
White-spaces in strings are not ignored by compiler
System.out
Standard output object
Print to command window (i.e., MS-DOS prompt)
Method System.out.println
Displays line of text
Argument inside parenthesis
This line known as a statement
Statements must end with semicolon ;
2.2.1 Compiling and Executing your First Java Application
Executing a program
Type java Welcome1
Interpreter loads .class file for class Welcome1
.class extension omitted from command
Interpreter calls method main
No comments:
Post a Comment