You are on page 1of 20

PROGRAM 1

PROGRAM TO PRINT HELLO & WELCOME TO JAVA.


class himanshu1 { public static void main (String args[]) {System.out.println("hello ..its me himanshu........"); System.out.println("HEY WELCOME TO JAVA"); }

OUTPUT

PROGRAM 2
PROGRAM TO IMPLEMENT BUFFER READER.

import java.io.*; class himanshu3 { public static void main(String args[]) { InputStreamReader a=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(a); String name; System.out.println("Enter your name"); try { name=br.readLine();

System.out.println("YOUR NAME IS"); System.out.println(name); } catch(IOException e) { System.out.println("error"); } }}

OUTPUT

PROGRAM 3
PROGRAM TO IMPLEMENT COMMAND LINE.

class command_line { public static void main(String args[]) { String a,b,s; a=args[0]; b=args[1]; System.out.println(a+" "+b); } }

OUTPUT

PROGRAM 4

PROGRAM TO IMPLEMENT DATA INPUT STREAM.

import java.io.*;

class dis { public static void main(String args[]) throws IOException { DataInputStream d=new DataInputStream(System.in); String s; int a,b,c; System.out.print(" Enter 1st no.- "); s=d.readLine(); a=Integer.parseInt(s); System.out.print(" Enter 2nd no.- "); s=d.readLine(); b=Integer.parseInt(s);

c=a+b;

System.out.print(" addition is= "+c); } }

OUTPUT

PROGRAM 5
PROGRAM TO IMPLEMENT DATA INPUT STREAM.

package p1; public class root { int a,b,c; float r1,r2; root() { a=1;b=3;c=2; } public void cal() { int d; d=b*b-4*a*c; r1=(float)((-b)+Math.sqrt(d))/(2*a); r2=(float)((-b)-Math.sqrt(d))/(2*a);

System.out.println("the roots of equation are:"+r1 +"and" +r2); } } package p2; public class area { float b,h; area() { b=2;h=3;

} public void cal1() { float area; area=(float)(0.5)*b*h;

System.out.println("the area of triangle is:"+area); } }

//MAIN import p1.*; import p2.*; class sumit { public static void main(String args[]) { area a= new area(); root b=new root(); a.cal1(); b.cal(); } }

OUTPUT

PROGRAM 6
PROGRAM TO IMPLEMENT THREADS.

class A extends Thread { public void run() { for(int i=1;i<11;i++) System.out.println("table of 2 is" +2*i); } } class B extends Thread { public void run() { for(int j=1;j<11;j++)

System.out.println("table of 5 is" +5*j); } } class C extends Thread { public void run() { for(int k=1;k<11;k++) System.out.println("table of 10 is" +10*k); } } //MAIN class thread { public static void main(String args[]) { A threadA=new A(); B threadB=new B(); C threadC=new C(); threadA.start(); System.out.println("START A"); threadB.start(); System.out.println("START B"); threadC.start(); System.out.println("START C"); } }

OUTPUT

PROGRAM 7

PROGRAM TO IMPLEMENT LIBRARY MANAGEMENT BY MAKING OBJECTS.


Package pkg; import java.io.*; public class libr { DataInputStream k= new DataInputStream(System.in); public void issue() { try{System.out.println("book name??"); String book =k.readLine(); System.out.println("library id??"); int lid=Integer.parseInt(k.readLine()); System.out.print(book); System.out.println(" has been issued to idno. "+lid+" for 15 days"); } catch(Exception e) {System.out.println("error"); } } public void retn() { try{ System.out.println("book id"); int id; id = Integer.parseInt(k.readLine()); System.out.println("Enter no. of day after due"); int days; days=Integer.parseInt(k.readLine()); int fine= days*2; System.out.println("FINE Rs."+fine); } catch(Exception e) {System.out.println("error");} } } //MAIN import pkg.*; import java.io.*; class library { public static void main(String args[]) { DataInputStream k= new DataInputStream(System.in);

try{ System.out.println("\t\t\t WELCOME TO A.S.E.T. LIBRARY"); System.out.println("\n\n\tENTER YOUR NAME"); String book =k.readLine(); int select; intbookcount=500; DataInputStream a= new DataInputStream(System.in); int lid; do{ System.out.println("\t\t\t**ENTER YOUR CHOICE**\n\t\t1.ISSUE BOOK \n\t\t2.RETURN BOOK\n\t\t3.GET TOTAL NUMBER OF BOOKS"); select=Integer.parseInt(a.readLine()); libr l = new libr(); switch(select) { case 1: l.issue(); bookcount--; System.out.println("BOOKS LEFT\t\t"+bookcount); break; case 2: l.retn(); bookcount++; System.out.println("BOOKS LEFT\t"+bookcount); break; case 3: System.out.println("TOTAL NUMBER OF BOOKS IS\t\t"+bookcount); break; default: System.out.println("\nWRONG CHOICE"); } System.out.println("\nTO GET THE OPTIONS AGAIN PRESS 5"); System.out.println("\n\nTO EXIT FROM PROGRAM TYPE EXIT"); lid=Integer.parseInt(a.readLine()); }

while(lid==5);} catch(Exception e) { System.out.println("\nTHANK YOU FOR VISITING"); } } }

OUTPUT

PROGRAM 8

PROGRAM TO IMPLEMENT TWO INTERFACES IN A CLASS.


import java.io.*; interface i { void u(String nme); void v(int marks); } interface j { void w(int age); } class a implements i { public void u(String nm) { System.out.println("the name of the owner is "+nm); } public void v(int marks) { System.out.println("the marks in linux are "+marks+" out of 100"); } public void w(int age) { System.out.println("the age of the student is "+ age); } } class himanshu8 { public static void main(String args[]) { String name; BufferedReader br,br1,br2; br = new BufferedReader( new InputStreamReader( System.in ) ); br1=new BufferedReader( new InputStreamReader( System.in ) ); br1=new BufferedReader( new InputStreamReader( System.in ) ); System.out.println("enter the following "); System.out.println("1) name of the student"); System.out.println("2) marks in linux out of 100 "); System.out.println("3) age of the student"); try{

name= br.readLine(); String input = br1.readLine(); Integer number = Integer.parseInt(input); String in = br1.readLine(); Integer num= Integer.parseInt(in); a o1=new a(); o1.u(name); o1.v(number); o1.w(num); } catch(IOException e) {System.out.println("error");} } }

OUTPUT

PROGRAM 9
PROGRAM TO DRAW HUMAN FACE.

import import import import

java.applet.*; java.awt.*; java.util.*; java.awt.event.*;

//<applet code=humanface width=300 height=300></applet> public class humanface extends Applet { public void init() { setBackground(Color.yellow); } public void paint(Graphics g) { Font f=new Font("Arial",Font.BOLD,30); g.setFont(f); g.drawOval(40,40,120,150); //head g.drawOval(57,75,30,20); //left eye g.drawOval(110,75,30,20);//right eye g.fillOval(68, 81,10,10); // pupil left g.fillOval(121, 81,10,10); // pupil right g.drawOval(85, 100,30,30); // nose g.drawOval(25, 92,15,30); // left ear g.drawOval(160,90,15,30); // right ear g.setColor(Color.red); g.fillArc(60,125,80,40,180,180); g.setColor(Color.blue); g.drawString("Human Face",30,20); g.drawString(" welcome to graphics programming " ,20,250); }

OUTPUT

You might also like