Lesson 4 - Java Environment
Lesson 4 - Java Environment
Lesson 4 - Java Environment
Part II
Lesson 4
NEIL A. MUTIA, MIT
Creating and Running a Java Program in
Android Phone
There’s a lot of free application available in the Google
Play Store that allows aspiring programmers to create,
compile, and execute a Java Program.
Using the AIDE
Java Program Basic Structure
Here are the most important points to note about the
Java programs:
You have to keep in mind that, Java code is case
sensitive.
To write a Java program, you must have to define class
first.
The name of the class in Java (which holds the main
method) is the name of the Java program, and the same
name will be given in the filename.
Java Program Basic Structure
This must be the exact
filename when saving the
program, Hello.java
This is the
This is a print statement, use
main
to print the value inside this
method
symbols (“ ”)
Java Program Basic Structure
public class Hello This creates a class called Hello.
All class names must not contain spaces
The public word means that it is accessible from any other classes.
/* Comments */ The compiler ignores comment block. Comment can be used anywhere in the
Or program to add info about the program or code block, which will be helpful for
// Comment developers to understand the existing code in the future easily.
Braces Two curly brackets {...} are used to group all the commands, so it is known that the
commands belong to that class or method.
public static void main When the main method is declared public, it means that it can also be used by
code outside of its class, due to which the main method is declared public.
The word static used when we want to access a method without creating its
object, as we call the main method, before creating any class objects.
The word void indicates that a method does not return a value. main() is declared
as void because it does not return a value.
main is a method; this is a starting point of a Java program.
You will notice that the main method code has been moved to some spaces left.
It is called indentation which used to make a program easier to read and
understand.
Java Program Basic Structure
String[] args It is an array where each element of it is a string, which has been named as "args". If
your Java program is run through the console, you can pass the input parameter, and
main() method takes it as input.
System.out.println(); This statement is used to print text on the screen as output, where the system is a
predefined class, and out is an object of the PrintWriter class defined in the system.
The method println prints the text on the screen with a new line. You can also
use print() method instead of println() method. All Java statement ends with a
semicolon.
Saving a Java Program
BLOCK COMMENT