You are on page 1of 4

First Program

public class Hello {

//data

//methods or functions

public static void main(String[] args)

//create object of class

//call methods through object

System.out.println("hello my first program");

class Hello

String msg="hello world"; //data

public void showMsg() //function

System.out.println(msg);

public static void main(String ar[])

Hello h1=new Hello(); //creating object of hello class with name h1

h1.showMsg(); //function call through object

**/*

Second Program
public class Calc

{
int a,b,r; //data members

public void setData(int i,int j)

a=i;

b=j;

public void add()

r=a+b;

System.out.println("sum="+r);

public void sub()

r=a-b;

System.out.println("substraction="+r);

public static void main(String[] args)

Calc c1=new Calc();

c1.setData(10, 20);

c1.add();

c1.sub();

output

Sum=30

Substraction=-10
Main function in java -

public static void main(String[] args)

Public :because main is called from outside of the class by jvm

Static : because main is called without help of object

Void: because main does not return any value.

main : name of function /method

String arg[]: is array of string elements which main function take as parameter and it is called command line
arguments/parameters.

How java is platform independent:

Java Program run in 2 steps

1- Compile (take source code and generate byte code)

2- Interpreted and execute (take byte code and generate machine code of particular platform)

upadhyaydhiraj@gmail.com

9009874373
Windows 10

We need to develop interpreter (JVM ) for windows 10 to run java applications on it.

Byte code--- > JVM for windows 10- machine code for windows 10 (86 bit machine code)

You might also like