Write the Programes at Notepad Or Dos Edit:
This is First Demo Program:
class demo
{
public static void main(String st[])
{
System.out.println(“Welcome to java programes”);
}
}
After This Code go at dos C:\>
and compile c:\>javac Demo.java
after compile to run the program purpose
c:\>java Demo
One more Example using with if condition:
For Loop program:
Do- while loop:
after result will be
Break Program:
import java.io.*;
class bbreak
{
public static void main(String str[])
throws IOException
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println(“Enter Option 1-3 : “);
int n=Integer.parseInt(dis.readLine());
first:
{
if(n==1)
break first;
System.out.println(“first block”);
second:
{
if(n==2)
break second;
System.out.println(“second block”);
third:
{
if(n==3)
break third;
System.out.println(“Third block”);
}
System.out.println(“End of Third block”);
}
System.out.println(“End of second block”);
}
System.out.println(“End of first block”);
}
}
getting info from Keyboard:
import java.io.*;
class demo1
{
public static void main(String str[])
throws IOException
{
DataInputStream dis=new DataInputStream(System.in);
String st=new String();
System.out.println(“Enter 1st no :”);
st=dis.readLine();
int n=Integer.parseInt(st);
System.out.println(“Enter 2nd no :”);
st=dis.readLine();
int n1=Integer.parseInt(st);
System.out.println(n+n1);
}
}
Function class:
/*function over loading */
import java.io.*;
class demo
{
public int add(int a,int b)
{
return a+b;
}
public float add(float a,float b)
{
return a+b;
}
public String add(String a,String b)
{
return a+b;
}
public static void main(String str[])
{
demo d=new demo();
int n=d.add(100,200);
float f=d.add(23.23f,34.344f);
String s=d.add(“meher”,”babu”);
System.out.println(n+” “+f+” “+s);
}
}
file:
import java.io.*;
class ffile1
{
public static void main(String str[])
throws IOException
{
File f=new File(“c:\\temp.dat”);
if(f.exists())
System.out.println(“File already exists”);
else
System.out.println(“file not found”);
}
}




