Title: Introduction%20to%20Java%20Programming
1Lecture 2
- Introduction to Java Programming
2(No Transcript)
3(No Transcript)
4(No Transcript)
5Java Class Format
public class userDefinedName public static
void main(String args)
6(No Transcript)
72.2 Primitive Data Types
8(No Transcript)
9(No Transcript)
10(No Transcript)
11(No Transcript)
12(No Transcript)
13(No Transcript)
14(No Transcript)
15(No Transcript)
16Lexical Elements
- Keywords
- Literals
- Identifiers
- Operators
- Punctuation
17Keywords
abstract default if private this boolean
do implements protected throw break
double import public throws byte else
instanceof return transient case extends
int short try catch final interface
static void char finally long strictfp
volatile class float native super while
const for new switch continue goto
package synchronized
- Can not be used for any other purpose
- All lowercase letters
18Literal
- A literal is the source code representation of a
value of a primitive type or the String type
Data type Literal Examples int -4501
double 35.271d char b
boolean true String Hello World
19Identifiers
- An identifier is an unlimited-length sequence of
Java letters and Java digits, the first of which
must be a Java letter. An identifier cannot have
the same spelling as a keyword or boolean literal.
Example identifierssumprodroot1isLeapYear
QuadraticLeapYearMAX
20Operators
21Punctuation
- The following nine ASCII characters are the
separators (punctuators) ( )
, .
22White Space
- White space is defined as the ASCII space,
horizontal tab, and form feed characters, as well
as line terminators
23Comments
- There are two kinds of comments
- / text / A traditional comment all the text
from the ASCII characters / to the ASCII
characters / is ignored by the compiler - // text A end-of-line comment all the text from
the ASCII characters // to the end of the line is
ignored by the compiler.
24All variables must be defined
- Tell the compiler the
- name of each variable
- type of each variable
int xint yboolean isLeapYearboolean
isPerflickdouble root1double root2
int x, yboolean isLeapYear, isPerflickdouble
root1, root2
25Initializing variables
int x 5int y //y need not be
initialized y 2x 1