Académique Documents
Professionnel Documents
Culture Documents
Comments
Program
Reserved words
Modifiers
Statements
Blocks
Classes
Methods
The main method
1
a) Comments
Comments ignored during program execution
Include a summary at the beginning of the
b) Reserved Words
Words that have a specific meaning to the compiler
Cannot be used for other purposes in the program.
Key words examples are:
public
class
static
void
int
double
boolean
continue
return
private
protected
package
language).
goto and const are C++ keywords, but not currently used
in Java. If they appear in Java, Java compilers will produce
error messages.
c) Modifiers
Java uses certain reserved words called
protected.
d) Statements
A statement represents an action or a
sequence of actions.
The statement System.out.println("Welcome
to Java!") in the program is a statement to
display the greeting "Welcome to Java!"
Every statement in Java ends with a
semicolon (;).
e) Blocks
A pair of braces in a program forms a block
Class block
Method block
f) Classes
The class is the essential Java construct.
A class is a template or blueprint for objects.
g) Method
System.out.println is a method.
Method is a collection of statements that
h) main () Method
The main method provides the control of
style
Comments Style
A block comment is placed between /* and
*/ marks:
of the line:
weight *= 2.2046;
// Convert to kilograms
Javadoc Comments
(contd)
/** indicates a javadoc
comment
/**
*
*
*
*
*
*/
Common
style
Can use
HTML tags
b) Naming Conventions
Choose meaningful and descriptive names.
Variables and method names:
Use lowercase. If the name consists of
radius and
area, and the method computeArea.
Cont..
Class names:
Capitalize the first letter of each word in the
name.
For example, the class name ComputeArea.
Constants:
Capitalize all letters in constants, and use
Spacing
Use blank line to separate segments of the
code.
15
d) Block Styles
Next-line
style
16
End-of-line
style