Task - Java Overview - Compilation and Execution of a Java Program #77
akash-coded
started this conversation in
Tasks
Replies: 15 comments
0 replies
FactorialMain.javaclass Factorial {
int calcFactorial(int n) {
int f = 1, i;
for (i = 1; i <= n; i++) {
f = f * i;
}
return f;
}
}
public class FactorialMain {
public static void main(String[] args) {
Factorial f = new Factorial();
System.out.println("Factorial of 5 is " + f.calcFactorial(5));
}
}Before compilationAfter compilationInterpretation |
0 replies
DEMONSTRATING THE EXECUTION OF A JAVA PROGRAMVehicleDemo.javaclass Car
{
static void run1()
{
System.out.println("CAR IS RUNNING");
}
}
class Bike
{
static void run2()
{
System.out.println("BIKE IS RUNNING");
}
}
class Bus
{
static void run3()
{
System.out.println("BUS IS RUNNING");
}
}
public class VehicleDemo
{
public static void main(String ar[])
{
Car.run1();
Bike.run2();
Bus.run3();
}
}OUTPUTCOMPILATIONINTERPRETATIONEXECUTION OF A JAVA PROGRAMFILESBEFORE COMPILATION-Java file is presentAFTER COMPILATION-Class files generated |
0 replies
Compilation and Executionclass MySample{
public static void method(){
System.out.println("Hello");
}
}
class Test{
public void service(){
System.out.println("Welcome all!");
}
}
class Example{
private void run(){
System.out.println("java program");
}
}
public class SampleProgm{
public static void main(String[] args) {
MySample.method();
System.out.println("Sample is compiled");
}
}OUTPUT:Before CompilationAfter CompilationInterpretationFiles |
0 replies
Shape.javaclass Rectangle{
static void display(){
System.out.println("Shape of the object is rectangle...");
}
}
class Triangle{
static void display1(){
System.out.println("Shape of the object is triangle...");
}
}
class Circle{
static void display2(){
System.out.println("Shape of the object is circle...");
}
}
public class Shape{
public static void main(String[] args){
System.out.println("Shapes...");
Rectangle.display();
Triangle.display1();
Circle.display2();
}
}Before CompilationAfter CompilationInterpretation |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

































Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Create a Java program, such as HelloWorld.java, or any other simple Java program.
Demonstrate compiling the source code with the
javaccommand.Demonstrate executing the generated bytecode using the
javacommand.Bonus
Include multiple classes in a Java program file, and compile it. Run the program using the bytecode containing the
main()method.All reactions