Sun. Dec 22nd, 2024
package statement;
import statements
class ClassName{
variables
methods
public static void main(String[] args){
statements;
}
}

Specifying the package statement in a java program is optional. A java program can contain at most one package statement. The package statement should be the first executable statement in a program.

Specifying the import statement in java program is optional. A java program can contain any number of import statements of the import statements. The import statements should be specified after the package statement and before the class.

A Java program can contain any number of classes and every class can contain variables and methods, which are together called as member of the class. A class can contain any number of members.

Execution of java program is done by JVM and begins from method, whose syntax must be as follows:

Public —->access Specifier

static—->modifier

void—->return type

main—>method name

(String[] args)—>parameter

The main method can contain any number of statements and every statement must be terminated by a semicolon.

A java program can contain any number of comments, and they can be specified anywhere in the program. The comments are executable statements.

Procedure to develop, save,compile,and execute a java program

Step1 Developing a java program:

To develop a java program we require an editor like notepad, wordpad, vi editor etc.

Program1:

Class FirstProgram{
   public static void main(String[] args){
     System.out.println("Welcome to AndroIndian");
  }
}

Step2 Saving a java program:

A java program can be saved with any name but the extension must be .java

Step3 Compiling a java program:

To compile a java program we require a command prompt and we use javac command.

Syntax: javac programname/filename with extention

Example: javac FirtsProgram.java

Java compiler will take the java program and verifies whether the java code is valid or not, if valid the compiler generates .class file generated by the compiler will be given to the JVM for execution.

Step 4 executing a java program:

To execute a java program we require a command prompt and we use java command.

Syntax: java ClassName without extention

Example: java Firstprogram

Output: Welcome to AndroIndian

By Rajashekar

I’m (Rajashekar) a core Android developer with complimenting skills as a web developer from India. I cherish taking up complex problems and turning them into beautiful interfaces. My love for decrypting the logic and structure of coding keeps me pushing towards writing elegant and proficient code, whether it is Android, PHP, Flutter or any other platforms. You would find me involved in cuisines, reading, travelling during my leisure hours.

Leave a Reply

Your email address will not be published. Required fields are marked *