KEMBAR78
Implementing a Java Program.pptx
Implementing a Java
Program
Prof. Yashoda M B
Assistant Professor in Computer Science (UG)
Kristu Jayanti College, Autonomous
(Reaccredited A++ Grade by NAAC with CGPA 3.78/4)
Bengaluru – 560077, India
Implementation of a java application
program involves a series of steps:
Creating a program
Compiling a program
Running a program
17/11/2023
Prof. Yashoda M B
2
Creating a program
 We can create program using any text editor.
 Assume that we have entered the following program.
Class Sample
{
public static void main(String args [] )
{
int a=10,b=20;
System.out.println(“The sum of two numbers=” + (a + b));
}
}
17/11/2023
Prof. Yashoda M B
3
Compiling the program
 We must rum the java compiler javac, with the source file on the
command line as shown below:
javac Sample.java
 If everything is OK, the javac compiler creates a file called
Sample.class containing the bytecodes of the program.
 The compiler automatically names the bytecode file as
<classname>.class 17/11/2023
Prof. Yashoda M B
4
Running a program
 We need to use java interpreter to run a standalone program.
 At the command prompt, type
Java Sample
 Now interpreter looks for the main method in the program and begins execution from
there.
 When executed, our program displays the following:
The sum of two numbers=30
 Java compiler converts the source code files into machine independent bytecode files
that can run on any machine.
 Java interpreter reads the bytecode files and translates them into machine code for the
specific machine on which java program is running. 17/11/2023
Prof. Yashoda M B
5

Implementing a Java Program.pptx

  • 1.
    Implementing a Java Program Prof.Yashoda M B Assistant Professor in Computer Science (UG) Kristu Jayanti College, Autonomous (Reaccredited A++ Grade by NAAC with CGPA 3.78/4) Bengaluru – 560077, India
  • 2.
    Implementation of ajava application program involves a series of steps: Creating a program Compiling a program Running a program 17/11/2023 Prof. Yashoda M B 2
  • 3.
    Creating a program We can create program using any text editor.  Assume that we have entered the following program. Class Sample { public static void main(String args [] ) { int a=10,b=20; System.out.println(“The sum of two numbers=” + (a + b)); } } 17/11/2023 Prof. Yashoda M B 3
  • 4.
    Compiling the program We must rum the java compiler javac, with the source file on the command line as shown below: javac Sample.java  If everything is OK, the javac compiler creates a file called Sample.class containing the bytecodes of the program.  The compiler automatically names the bytecode file as <classname>.class 17/11/2023 Prof. Yashoda M B 4
  • 5.
    Running a program We need to use java interpreter to run a standalone program.  At the command prompt, type Java Sample  Now interpreter looks for the main method in the program and begins execution from there.  When executed, our program displays the following: The sum of two numbers=30  Java compiler converts the source code files into machine independent bytecode files that can run on any machine.  Java interpreter reads the bytecode files and translates them into machine code for the specific machine on which java program is running. 17/11/2023 Prof. Yashoda M B 5