SlideShare a Scribd company logo
Program 1 
Program: WAP in java to print “Hello World”. 
class Hello 
{ 
public static void main(String args[ ]) 
{ 
System.out.println("Hello World"); 
} 
}
Java Programs Lab File
Program 2 
Program: WAP in java to implement programs to define a class and 
instantiate its object. 
import java.io.*; 
class Student 
{ 
int sid; 
String sname,sadr,sfname,smname; 
BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
public void input()throws IOException 
{ 
System.out.println("please input sid,name,fname and mname"); 
sid=Integer.parseInt(br.readLine()); 
sname=br.readLine(); 
sfname=br.readLine(); 
smname=br.readLine(); 
} 
public void display() 
{ 
System.out.println("Student's id="+sid); 
System.out.println("Student's name="+sname); 
System.out.println("Student's father name="+sfname); 
System.out.println("Student's mother name="+smname); 
} 
} 
class object 
{ 
public static void main(String args[ ])throws IOException 
{ 
Student s=new Student(); 
s.input(); 
s.display(); 
} 
}
Java Programs Lab File
Program 3 
Program: WAP in java to implement constructor and method overloading. 
class demo 
{ 
int area(int a) 
{ 
return(a*a); 
} 
int area(int a,int b) 
{ 
return(a*b); 
} 
double area(double a) 
{ 
return(3.14*a*a); 
} 
} 
class room 
{ 
public static void main(String args[]) 
{ 
demo d=new demo(); 
System.out.println("Area of square="+d.area(5)); 
System.out.println("Area of rectangle="+d.area(6,4)); 
System.out.println("Area of circle="+d.area(1.25)); 
} 
}
Java Programs Lab File
Program 4 
Program: WAP in java to implement Command line argument. 
class ComLineTest 
{ 
public static void main(String args[ ]) 
{ 
int count,i=0; 
String s; 
count=args.length; 
System.out.println("Number of arguments="+count); 
while(i<count) 
{ 
s=args[i]; 
i=i+1; 
System.out.println(i+":"+"java is"+s+"!"); 
} 
} 
}
Java Programs Lab File
Program 5 
Program: WAP in java to implement String class. 
class abc 
{ 
public static void main(String args[]) 
{ 
int n,i,j; 
String s=new String("manju"); 
System.out.println(" Length of String="+s.length()); 
int l=s.length(); 
for(i=0;i<l;i++) 
{ 
for(j=0;j<=i;j++) 
System.out.print(s.charAt(j)); 
System.out.print("n"); 
} 
} 
}
Java Programs Lab File
Program 6 
Program: WAP in java to implement 2D-Arrays. 
import java .io.*; 
class element 
{ 
public static void main(String args[ ])throws IOException 
{ 
int a[ ][ ]=new int[3][3]; 
int i,j; 
BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
System.out.println("please input nine elements for matrices"); 
for(i=0;i<3;i++) 
for(j=0;j<3;j++) 
a[i ][ j]=Integer.parseInt(br.readLine()); 
System.out.println("the matrices"); 
for(i=0;i<3;i++) 
{ 
for(j=0;j<3;j++) 
System.out.println(a[i][j]+"t"); 
System.out.println("n"); 
} 
} 
}
Java Programs Lab File
Program 7 
Program: WAP in java to implement Multi-level inheritance. 
import java.util.*; 
class multilevel 
{ 
static Scanner sc=new Scanner(System.in); 
static class A 
{ 
int a1,a2; 
void getdata() 
{ 
System.out.println("Enter the value of a1 is:"); 
a1=sc.nextInt(); 
System.out.println("Enter the value of a2 is:"); 
a2=sc.nextInt(); 
} 
void putdata() 
{ 
System.out.println("n The value of a1 is:"+ a1 +" and a2:"+ a2); 
} 
} 
static class B extends A 
{ 
int b1; 
void add() 
{ 
b1=a1+a2; 
System.out.println("n The Sum is:"+b1); 
} 
} 
static class C extends B 
{ 
int c1; 
void mul() 
{ 
c1=b1*a1; 
System.out.println("The product is :"+c1); 
} 
} 
public static void main(String args[]) 
{ 
C obj=new C(); 
obj.getdata(); 
obj.add(); 
obj.mul(); 
} 
}
Java Programs Lab File
Program 8 
Program: WAP in java implement the use of interface. 
interface my 
{ 
public void show(); 
} 
class demo implements my 
{ 
public void show() 
{ 
System.out.println("This is interface program"); 
} 
} 
class sks 
{ 
public static void main(String args[]) 
{ 
demo d=new demo(); 
d.show(); 
} 
}
Java Programs Lab File
Program 9 
Program: WAP in java implement method overriding. 
class One 
{ 
void display() 
{ 
System.out.println("I am class One"); 
} 
} 
class Two extends One 
{ 
void display() 
{ 
System.out.println("I am class Two"); 
} 
} 
class Overriding 
{ 
void display() 
{ 
System.out.println("I am from class override"); 
} 
public static void main(String args[]) 
{ 
Overriding obj=new Overriding(); 
obj.display(); 
Two t=new Two(); 
t.display(); 
} 
}
Java Programs Lab File
Program 10 
Program: WAP in java to implement Multithreading. 
class A extends Thread 
{ 
public void run() 
{ 
for(int i=1;i<5;i++) 
{ 
System.out.println("t from Thread A:"+i); 
} 
System.out.println("Exit from Thread A"); 
} 
} 
class B extends Thread 
{ 
public void run() 
{ 
for(int j=0;j<5;j++) 
{ 
System.out.println("t from Thread B:"+j); 
} 
System.out.println("Exit from Thread B"); 
} 
} 
class threadtest 
{ 
public static void main(String args[]) 
{ 
A ob=new A(); 
B ob1=new B(); 
ob.start(); 
ob1.start(); 
} 
}
Java Programs Lab File
Program 11 
Program: WAP in java to implement Exception Handling. 
class Error 
{ 
public static void main(String args[]) 
{ 
int a=10,b=5,c=5,x,y; 
try 
{ 
x=a/b-c; 
} 
catch(Exception e) 
{} 
{ 
System.out.println("Division by zero"); 
} 
y=a/b+c; 
System.out.println("y="+y); 
} 
}
Java Programs Lab File
Program 12 
Program: WAP in java to implement User-defined and pre-defined packages. 
package package1; 
public class A 
{ 
public void display() 
{ 
System.out.println("This is class A"); 
} 
} 
import package1.A; 
class Packagetest1 
{ 
public static void main(String args[]) 
{ 
A obj=new A(); 
obj.display(); 
} 
}
Java Programs Lab File
Program 13 
Program: WAP in java to implement applet using Graphics class. 
import java.awt.*; 
import java.applet.*; 
import java.net.*; 
public class star extends Applet 
{ 
public void paint(Graphics g) 
{ 
g.setColor(Color.green); 
int x[ ]={80,100,150,120,150,80,0,30,0,50}; 
int y[ ]={10,40,40,70,120,90,120,70,40,40}; 
g.drawPolygon(x,y,10); 
g.fillPolygon(x,y,10); 
} 
} 
/*<applet code="star.class"width=500 height=500></applet>*/
Java Programs Lab File
Program 14 
Program: WAP in java to implement the use of I/O Streams. 
import java.io.*; 
class First 
{ 
public static InputStreamReader input=new InputStreamReader(System.in); 
public static BufferedReader keyboardInput=new BufferedReader(input); 
static PrintWriter screenOutput=new PrintWriter(System.out,true); 
public static void main(String[] args)throws IOException 
{ 
String name; 
screenOutput.print("What is your name?"); 
screenOutput.flush(); 
name=keyboardInput.readLine(); 
screenOutput.print("nHello"+name); 
screenOutput.println("java is based on independent platform"); 
} 
}
Java Programs Lab File
Program 15 
Program: WAP in java to implement swing program. 
import javax.swing.*; 
class program extends JFrame 
{ 
program() 
{ 
setTitle("first form"); 
setSize(300,300); 
setVisible(true); 
} 
} 
class form 
{ 
public static void main (String args[ ]) 
{ 
program p=new program(); 
} 
}
Java Programs Lab File

More Related Content

What's hot (20)

PDF
Algorithm Analysis.pdf
MemMem25
 
DOCX
Java PRACTICAL file
RACHIT_GUPTA
 
PPTX
Algorithm Complexity and Main Concepts
Adelina Ahadova
 
PPT
stack presentation
Shivalik college of engineering
 
DOC
Final JAVA Practical of BCA SEM-5.
Nishan Barot
 
PPT
GUI Programming In Java
yht4ever
 
PPT
Java Arrays
Jussi Pohjolainen
 
PPTX
Divide and Conquer - Part 1
Amrinder Arora
 
PPTX
Knapsack problem algorithm, greedy algorithm
HoneyChintal
 
PPTX
Types of Parser
SomnathMore3
 
PPT
Chapter 11 - Sorting and Searching
Eduardo Bergavera
 
PPTX
Insertion Sorting
FarihaHabib123
 
PPTX
Operator overloading
ramya marichamy
 
PPTX
C# Loops
Hock Leng PUAH
 
PDF
CS6611 Mobile Application Development Lab Manual-2018-19
Gobinath Subramaniam
 
PPT
Asymptotic notation
Dr Shashikant Athawale
 
PPT
03 algorithm properties
Lincoln School
 
PPTX
String In C Language
Simplilearn
 
PPTX
Structure & Union in C++
Davinder Kaur
 
DOCX
Java practical
shweta-sharma99
 
Algorithm Analysis.pdf
MemMem25
 
Java PRACTICAL file
RACHIT_GUPTA
 
Algorithm Complexity and Main Concepts
Adelina Ahadova
 
Final JAVA Practical of BCA SEM-5.
Nishan Barot
 
GUI Programming In Java
yht4ever
 
Java Arrays
Jussi Pohjolainen
 
Divide and Conquer - Part 1
Amrinder Arora
 
Knapsack problem algorithm, greedy algorithm
HoneyChintal
 
Types of Parser
SomnathMore3
 
Chapter 11 - Sorting and Searching
Eduardo Bergavera
 
Insertion Sorting
FarihaHabib123
 
Operator overloading
ramya marichamy
 
C# Loops
Hock Leng PUAH
 
CS6611 Mobile Application Development Lab Manual-2018-19
Gobinath Subramaniam
 
Asymptotic notation
Dr Shashikant Athawale
 
03 algorithm properties
Lincoln School
 
String In C Language
Simplilearn
 
Structure & Union in C++
Davinder Kaur
 
Java practical
shweta-sharma99
 

Similar to Java Programs Lab File (20)

DOCX
Java programs
Dr.M.Karthika parthasarathy
 
PPTX
Java Programs
vvpadhu
 
PPTX
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Ayes Chinmay
 
PDF
Core java pract_sem iii
Niraj Bharambe
 
DOC
Object oriented programming la bmanual jntu
Khurshid Asghar
 
PPTX
java input & output statements
VigneshManikandan11
 
PDF
Object Oriented Solved Practice Programs C++ Exams
MuhammadTalha436
 
PDF
Java Practical File Diploma
mustkeem khan
 
PDF
Java and j2ee_lab-manual
hanumanthu mothukuru
 
PPTX
Java oops features
VigneshManikandan11
 
DOCX
JAVAPGMS.docx
Mgm Mallikarjun
 
ODT
Java practical
william otto
 
PDF
Java 5 and 6 New Features
Jussi Pohjolainen
 
PDF
Java doc Pr ITM2
Aram Mohammed
 
PDF
Java ppt Gandhi Ravi ([email protected])
Gandhi Ravi
 
PPTX
Java Language fundamental
Infoviaan Technologies
 
DOC
Java final lab
Vivek Kumar Sinha
 
PDF
Sam wd programs
Soumya Behera
 
Java Programs
vvpadhu
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Ayes Chinmay
 
Core java pract_sem iii
Niraj Bharambe
 
Object oriented programming la bmanual jntu
Khurshid Asghar
 
java input & output statements
VigneshManikandan11
 
Object Oriented Solved Practice Programs C++ Exams
MuhammadTalha436
 
Java Practical File Diploma
mustkeem khan
 
Java and j2ee_lab-manual
hanumanthu mothukuru
 
Java oops features
VigneshManikandan11
 
JAVAPGMS.docx
Mgm Mallikarjun
 
Java practical
william otto
 
Java 5 and 6 New Features
Jussi Pohjolainen
 
Java doc Pr ITM2
Aram Mohammed
 
Java ppt Gandhi Ravi ([email protected])
Gandhi Ravi
 
Java Language fundamental
Infoviaan Technologies
 
Java final lab
Vivek Kumar Sinha
 
Sam wd programs
Soumya Behera
 
Ad

More from Kandarp Tiwari (12)

DOCX
Artificial Intelligence Lab File
Kandarp Tiwari
 
DOCX
Speed Detecting Camera by Kandarp Tiwari
Kandarp Tiwari
 
PPTX
Speed Detecting Camera by Kandarp Tiwari
Kandarp Tiwari
 
DOCX
Web Technology Lab File
Kandarp Tiwari
 
DOCX
Web Technology Front Page
Kandarp Tiwari
 
DOCX
Web technology
Kandarp Tiwari
 
DOCX
Compiler design front page
Kandarp Tiwari
 
DOCX
Computer Networks Front Page
Kandarp Tiwari
 
DOCX
Computer Networks Lab File
Kandarp Tiwari
 
DOCX
Compiler Design Lab File
Kandarp Tiwari
 
DOCX
Os lab file c programs
Kandarp Tiwari
 
DOCX
Computer Graphics Lab File C Programs
Kandarp Tiwari
 
Artificial Intelligence Lab File
Kandarp Tiwari
 
Speed Detecting Camera by Kandarp Tiwari
Kandarp Tiwari
 
Speed Detecting Camera by Kandarp Tiwari
Kandarp Tiwari
 
Web Technology Lab File
Kandarp Tiwari
 
Web Technology Front Page
Kandarp Tiwari
 
Web technology
Kandarp Tiwari
 
Compiler design front page
Kandarp Tiwari
 
Computer Networks Front Page
Kandarp Tiwari
 
Computer Networks Lab File
Kandarp Tiwari
 
Compiler Design Lab File
Kandarp Tiwari
 
Os lab file c programs
Kandarp Tiwari
 
Computer Graphics Lab File C Programs
Kandarp Tiwari
 
Ad

Recently uploaded (20)

PDF
Información de microsoft purview herramienta de microsoft
macarenabenitez6
 
PPTX
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
PDF
Authentication Devices in Fog-mobile Edge Computing Environments through a Wi...
ijujournal
 
PPTX
Unit_I Functional Units, Instruction Sets.pptx
logaprakash9
 
PDF
Clustering Algorithms - Kmeans,Min ALgorithm
Sharmila Chidaravalli
 
PDF
Digital water marking system project report
Kamal Acharya
 
PPTX
Fundamentals of Quantitative Design and Analysis.pptx
aliali240367
 
PPSX
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
PPTX
Explore USA’s Best Structural And Non Structural Steel Detailing
Silicon Engineering Consultants LLC
 
PDF
Module - 5 Machine Learning-22ISE62.pdf
Dr. Shivashankar
 
PPTX
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
 
PDF
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
PPT
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
PDF
LLC CM NCP1399 SIMPLIS MODEL MANUAL.PDF
ssuser1be9ce
 
PDF
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
PPTX
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
PPTX
template.pptxr4t5y67yrttttttttttttttttttttttttttttttttttt
SithamparanaathanPir
 
PDF
Artificial Neural Network-Types,Perceptron,Problems
Sharmila Chidaravalli
 
PPTX
Seminar Description: YOLO v1 (You Only Look Once).pptx
abhijithpramod20002
 
PPT
FINAL plumbing code for board exam passer
MattKristopherDiaz
 
Información de microsoft purview herramienta de microsoft
macarenabenitez6
 
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
Authentication Devices in Fog-mobile Edge Computing Environments through a Wi...
ijujournal
 
Unit_I Functional Units, Instruction Sets.pptx
logaprakash9
 
Clustering Algorithms - Kmeans,Min ALgorithm
Sharmila Chidaravalli
 
Digital water marking system project report
Kamal Acharya
 
Fundamentals of Quantitative Design and Analysis.pptx
aliali240367
 
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
Explore USA’s Best Structural And Non Structural Steel Detailing
Silicon Engineering Consultants LLC
 
Module - 5 Machine Learning-22ISE62.pdf
Dr. Shivashankar
 
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
 
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
LLC CM NCP1399 SIMPLIS MODEL MANUAL.PDF
ssuser1be9ce
 
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
template.pptxr4t5y67yrttttttttttttttttttttttttttttttttttt
SithamparanaathanPir
 
Artificial Neural Network-Types,Perceptron,Problems
Sharmila Chidaravalli
 
Seminar Description: YOLO v1 (You Only Look Once).pptx
abhijithpramod20002
 
FINAL plumbing code for board exam passer
MattKristopherDiaz
 

Java Programs Lab File

  • 1. Program 1 Program: WAP in java to print “Hello World”. class Hello { public static void main(String args[ ]) { System.out.println("Hello World"); } }
  • 3. Program 2 Program: WAP in java to implement programs to define a class and instantiate its object. import java.io.*; class Student { int sid; String sname,sadr,sfname,smname; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); public void input()throws IOException { System.out.println("please input sid,name,fname and mname"); sid=Integer.parseInt(br.readLine()); sname=br.readLine(); sfname=br.readLine(); smname=br.readLine(); } public void display() { System.out.println("Student's id="+sid); System.out.println("Student's name="+sname); System.out.println("Student's father name="+sfname); System.out.println("Student's mother name="+smname); } } class object { public static void main(String args[ ])throws IOException { Student s=new Student(); s.input(); s.display(); } }
  • 5. Program 3 Program: WAP in java to implement constructor and method overloading. class demo { int area(int a) { return(a*a); } int area(int a,int b) { return(a*b); } double area(double a) { return(3.14*a*a); } } class room { public static void main(String args[]) { demo d=new demo(); System.out.println("Area of square="+d.area(5)); System.out.println("Area of rectangle="+d.area(6,4)); System.out.println("Area of circle="+d.area(1.25)); } }
  • 7. Program 4 Program: WAP in java to implement Command line argument. class ComLineTest { public static void main(String args[ ]) { int count,i=0; String s; count=args.length; System.out.println("Number of arguments="+count); while(i<count) { s=args[i]; i=i+1; System.out.println(i+":"+"java is"+s+"!"); } } }
  • 9. Program 5 Program: WAP in java to implement String class. class abc { public static void main(String args[]) { int n,i,j; String s=new String("manju"); System.out.println(" Length of String="+s.length()); int l=s.length(); for(i=0;i<l;i++) { for(j=0;j<=i;j++) System.out.print(s.charAt(j)); System.out.print("n"); } } }
  • 11. Program 6 Program: WAP in java to implement 2D-Arrays. import java .io.*; class element { public static void main(String args[ ])throws IOException { int a[ ][ ]=new int[3][3]; int i,j; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("please input nine elements for matrices"); for(i=0;i<3;i++) for(j=0;j<3;j++) a[i ][ j]=Integer.parseInt(br.readLine()); System.out.println("the matrices"); for(i=0;i<3;i++) { for(j=0;j<3;j++) System.out.println(a[i][j]+"t"); System.out.println("n"); } } }
  • 13. Program 7 Program: WAP in java to implement Multi-level inheritance. import java.util.*; class multilevel { static Scanner sc=new Scanner(System.in); static class A { int a1,a2; void getdata() { System.out.println("Enter the value of a1 is:"); a1=sc.nextInt(); System.out.println("Enter the value of a2 is:"); a2=sc.nextInt(); } void putdata() { System.out.println("n The value of a1 is:"+ a1 +" and a2:"+ a2); } } static class B extends A { int b1; void add() { b1=a1+a2; System.out.println("n The Sum is:"+b1); } } static class C extends B { int c1; void mul() { c1=b1*a1; System.out.println("The product is :"+c1); } } public static void main(String args[]) { C obj=new C(); obj.getdata(); obj.add(); obj.mul(); } }
  • 15. Program 8 Program: WAP in java implement the use of interface. interface my { public void show(); } class demo implements my { public void show() { System.out.println("This is interface program"); } } class sks { public static void main(String args[]) { demo d=new demo(); d.show(); } }
  • 17. Program 9 Program: WAP in java implement method overriding. class One { void display() { System.out.println("I am class One"); } } class Two extends One { void display() { System.out.println("I am class Two"); } } class Overriding { void display() { System.out.println("I am from class override"); } public static void main(String args[]) { Overriding obj=new Overriding(); obj.display(); Two t=new Two(); t.display(); } }
  • 19. Program 10 Program: WAP in java to implement Multithreading. class A extends Thread { public void run() { for(int i=1;i<5;i++) { System.out.println("t from Thread A:"+i); } System.out.println("Exit from Thread A"); } } class B extends Thread { public void run() { for(int j=0;j<5;j++) { System.out.println("t from Thread B:"+j); } System.out.println("Exit from Thread B"); } } class threadtest { public static void main(String args[]) { A ob=new A(); B ob1=new B(); ob.start(); ob1.start(); } }
  • 21. Program 11 Program: WAP in java to implement Exception Handling. class Error { public static void main(String args[]) { int a=10,b=5,c=5,x,y; try { x=a/b-c; } catch(Exception e) {} { System.out.println("Division by zero"); } y=a/b+c; System.out.println("y="+y); } }
  • 23. Program 12 Program: WAP in java to implement User-defined and pre-defined packages. package package1; public class A { public void display() { System.out.println("This is class A"); } } import package1.A; class Packagetest1 { public static void main(String args[]) { A obj=new A(); obj.display(); } }
  • 25. Program 13 Program: WAP in java to implement applet using Graphics class. import java.awt.*; import java.applet.*; import java.net.*; public class star extends Applet { public void paint(Graphics g) { g.setColor(Color.green); int x[ ]={80,100,150,120,150,80,0,30,0,50}; int y[ ]={10,40,40,70,120,90,120,70,40,40}; g.drawPolygon(x,y,10); g.fillPolygon(x,y,10); } } /*<applet code="star.class"width=500 height=500></applet>*/
  • 27. Program 14 Program: WAP in java to implement the use of I/O Streams. import java.io.*; class First { public static InputStreamReader input=new InputStreamReader(System.in); public static BufferedReader keyboardInput=new BufferedReader(input); static PrintWriter screenOutput=new PrintWriter(System.out,true); public static void main(String[] args)throws IOException { String name; screenOutput.print("What is your name?"); screenOutput.flush(); name=keyboardInput.readLine(); screenOutput.print("nHello"+name); screenOutput.println("java is based on independent platform"); } }
  • 29. Program 15 Program: WAP in java to implement swing program. import javax.swing.*; class program extends JFrame { program() { setTitle("first form"); setSize(300,300); setVisible(true); } } class form { public static void main (String args[ ]) { program p=new program(); } }