Download presentation
Presentation is loading. Please wait.
1
Introduction to Java Programming
Lecture 2 Introduction to Java Programming
5
Java Class Format public class userDefinedName { public static void main(String[] args){ } }
7
2.2 Primitive Data Types
16
Lexical Elements Keywords Literals Identifiers Operators Punctuation
17
Can not be used for any other purpose All lowercase letters
Keywords 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
18
Literal A literal is the source code representation of a value of a primitive type or the String type Data type Literal Examples int double d char ‘b’ boolean true String “Hello World”
19
variable names class names constants Identifiers
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 identifiers sum prod root1 isLeapYear Quadratic LeapYear MAX variable names class names constants
20
Operators
21
Punctuation The following nine ASCII characters are the separators (punctuators): ( ) { } [ ] ; ,
22
White Space White space is defined as the ASCII space, horizontal tab, and form feed characters, as well as line terminators
23
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.
24
All variables must be defined
Tell the compiler the name of each variable type of each variable int x; int y; boolean isLeapYear; boolean isPerflick; double root1; double root2; int x, y; boolean isLeapYear, isPerflick; double root1, root2;
25
Initializing variables
int x = 5; int y; //y need not be initialized y = 2*x + 1; …
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.