|
We will explore these concept further in this webpage.
|
|
(You cannot execute a portion of a statement)
A statement is like a sentence: it is the smallest unit that you write in a book.
System.out.println("Hello Class"); |
|
|
|
|
|
We will discuss a simplified syntax on how to define a method here and discuss the details on how to define methods later
MethodProperties METHOD_NAME( ... ) { statements contained in the method } |
Explanation:
|
|
|
|
|
|
|
Graphically explained:
|
|
Examples: public, static and void
|
Example:
|
|
There are some rules in Java that you must follow to form the identifier name
|
age Age (is different from age) greaterCommonDivisor R2D2 radius_of_the_circle |
3cpo (cannot start with a digit) radius-of-the-circle (cannot have minus sign in an identifier) public (cannot use a keyword !) |
|
|
ClassProperties class CLASSNAME { methodDefinitions } |
Explanation:
|
|
Because this block is part of a class definition, it is called a class block
Example:
The outer block is a class block
The inner block is the body of a method and it is called a method block
|
Meaning:
|
|
|
How to run the program:
|
|
|
public class Hello2 { public static void main(String[] args) { System.out.println("Hello Class"); System.out.println(" How is everyone doing so far ?"); } } |
Same program with many insignificant white spaces:
public class Hello3 { public static void main (String[] args) { System.out.println ( "Hello Class"); System.out.println( " How is everyone doing so far ?"); }} |
(But... I had to call it Hello3 because the name Hello2 is already used)
How to run the program:
|
|
|
|
|
Each class is identified by a class name which is an identifier
public class CLASSNAME { (method definitions) } |
public static void main(String[] args) { (statements) } |