Chapter 2: Basic Elements of Java
[Pages:90]Chapter 2: Basic Elements of Java
Java Programming: From Problem
Analysis to Program Design, Third
Edition
Thursday, October 21, 2010
1
Chapter Objectives
Become familiar with the basic components of a Java program, including methods, special symbols, and identifiers.
Explore primitive data types.
Discover how to use arithmetic operators. Examine how a program evaluates arithmetic
expressions.
Explore how mixed expressions are evaluated.
Java Programming: From Problem Analysis to Program Design, Third Edition
Thursday, October 21, 2010
2
2
Chapter Objectives
Learn about type casting.
Become familiar with the String type.
Learn what an assignment statement is and what it does.
Discover how to input data into memory by using input statements.
Become familiar with the use of increment and decrement operators.
Java Programming: From Problem Analysis to Program Design, Third Edition
Thursday, October 21, 2010
3
3
Chapter Objectives
Examine ways to output results using output statements.
Learn how to import packages and why they are necessary.
Discover how to create a Java application program.
Explore how to properly structure a program, including using comments to document a program.
Java Programming: From Problem Analysis to Program Design, Third Edition
Thursday, October 21, 2010
4
4
Recall...
Computer program: A sequence of statements (instructions) designed to accomplish a task.
Programming: The process of planning and creating a program.
Java Programming: From Problem Analysis to Program Design, Third Edition
Thursday, October 21, 2010
5
5
Syntax and Semantic Rules
How can we learn French!! Alphabet Words Grammar
How can we learn Java!!
Symbols Words Syntax
Java Programming: From Problem Analysis to Program Design, Third Edition
Thursday, October 21, 2010
6
6
Syntax and Semantic Rules
Syntax rules tell you which statements (instructions) are legal, or accepted by the programming language and which are not:
? A compiler will complain about programs with invalid syntax.
Semantic rules determine the meaning of the instruction:
? A compiler will complain about many (but not all) semantic errors in
programs.
Why cant the compiler "catch" all errors? So a program may compile without errors But not run correctly - i.e., do the right thing Don't become reliant on the compiler. NOTE: A syntactically valid program is not necessarily meaningful!
Java Programming: From Problem Analysis to Program Design, Third Edition
Thursday, October 21, 2010
7
7
Syntax and Semantic Examples
Some Java syntax rules:
? Statements must be terminated by a semicolon.
? Parentheses, braces and brackets must balance.
3 + 4 + 6 is valid, but,
3 + 4 + is invalid.
Some semantic rules:
Subtraction is only meaningful on numbers so:
3 - 5
is valid, but
3 - "five" is invalid.
Java Programming: From Problem Analysis to Program Design, Third Edition
Thursday, October 21, 2010
8
8
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- 4 basic elements of communication
- basic elements of argument
- 5 basic elements of a story
- basic elements of organizational design
- basic elements of strategic planning
- basic elements of a system
- basic elements of culture
- 5 basic elements of life
- basic elements of earth
- basic elements of financial reporting
- basic elements of nature
- basic elements of the universe