You are on page 1of 3

UNIT 03 – BASIC ELEMENTS OF A JAVA PROGRAM

LESSON # 3.1
TITLE: Understanding the Java Codes

Terminologies
Comments – are additional information added to the code. They are used to describe the program or
portions of the program.
Class Declaration – contains the code that defines the access specifier, class name, and a pair of
curly brackets which contain the body of the class.
Access Specifier – defines the visibility of the class and how other classes can access the class.
Interface – is a common method that the class supports.
Main() Method – Starts the execution of a Java program.
Public Keyword – is an access specifier which indicates the main() method can be called outside the program.
Statements – is a form of a complete command to be executed and can also include one or more expression.
Delimeter – is character or string used to separate or mark the start and end of a program construction or items
of data.
Expression – A type of statement that includes assignment statements, method invocation, object creation,
expressions, and increment statements.
Declaration – A type of statement that is used to declare variables.
Control Statements – A type of statement which determines the order of statements to be executed.
Special Control Statements – a type of statement that includes return, continue and break statements. It is also
known as branching statements.
Reserved Words – are words that have special meaning and function to the Java programming language.

Discussion
Java comments are denoted in three ways:

1. Single line comment is preceded by two forward slashes ( / / )


Example:
weight_lbs = 2.2 * weight_kg; //formula of conversion.

2. Multi-line comment is enclosed by /* */


Example:
/* declare variables for name, weight in kg and weight
* in lbs */

3. Java documentation is enclosed by /** **/


Example:
/**
* @ (#) SampleProgram.java
* @author : Mik Reyes
* @version 1.00 2019/07/22
*/

Class Declaration
The body of the class contains the declaration of class variables and definition of class methods.
Example:
public javacode() {
}
public static void main(String[] args) {
String name;
String label;
double weight_kg;
double weight_lbs;
}
}

The main() method


Example:
public static void main(String[] args) {

String name;
String label;
double weight_kg;
double weight_lbs;
}

Statements
//declaration statement
int number;
//expression statement
number = 4;
//control flow statement
if (number < 10 )
{
//expression statement
System.out.println(number + " is less than ten");
}

Delimeters
Common Delimeters: Curly Braces {}, Parenthesis (), Bracket [], Semi-colon ;

Reserved words
abstract const finally interface return throws

assert default float long short transient

boolean do for native static true

break double goto new strictfp try

byte else if null super void

case enum implements package switch volatile

catch extends import private synchronized while

char false instanceof protected this continue

class final int public throw

You might also like