You are on page 1of 20

Laxmi Devi Institute of Engineering & Technology, Alwar Rajasthan Technical University, Kota

A JAVA PROGRAM FILE 2009-10 Session

Submitted to -

Submitted by -

Mr.Paranay mishra ( Assistant prof.) LIET Alwar

Name : Tarun Khandelwal Roll No. : 08ELDEE059 Sem : 4th sem

S.NO NAME OF PROGRAM DATE SIGN REMARK .

lang.23607 . Double y. Class squreroot { Public static void main(String args[] ) { Double x=5. } } OUTPUT: y=2.println(“y=”+y).math. System. y = Math.A PROGRAM WITH MULTIPLE STATEMENTS PROGRAM - /* * More Java Statements * This Code Computes Squre root */ Import java.out.sqrt(x).

length*room1.println(“Area=”+area). Void getdata(float a. Room room1=new room(). Area=room1. } OUTPUT: - 140 . } } Class RoomArea { Public static void main (String args[]) { Float area. float b) { Length =a.10). Room1. Breath=b.getdata(14.breath. Float breath.out.A PROGRAM WITH MULTIPLE CLASSES PROGRAM - Class room { Float length. System.

A PROGRAM USING COMMANDLINE ARGUMENT PROGRAM - /* * This Program Uses Command Line * Arguments As Input.out. String string. System. i=i+1. System.println(“Number of arguments=”+count).println(i+ “:”+ “java is” + string+ “:”). } } } OUTPUT:- Number of arguments+5 1: Java is simple! 2: Java is object oriented! 3: Java is distributed! 4: Java is robust! 5: Java is portable! .out. i=0. While (i<count) { String=args[i]. */ Class ComlineTest { Public static void main(String arga[]) { Int count. Count=args.length.

num1 = integer.o*.out. num2 = integer. int num3 = num1+num2.println(“sum”+num3). System.in).parseInt(snum). Int num1.i. } Catch(Exception eobj) { System. System. num2. snum = input.println(“Error”).out. } } OUTPUT:Enter first number 10 Enter second number 20 Sum 30 .out. input = new DataInputStream (system.println(“Enter first number”).readline( ).parseInt(snum). Try { DataInputStream input.println(“enter second number”). System.readline( ).PROGRAM – Import java. Class jps { Public static void main (string args []) { String snum. snum = input.out.

max. max1 = a>b? a:b. } Catch(Exception eobj) { System.out.out.readline( )). try { DataInputStream input.parseInt(input.o*.readline( )). system. Class JSP { Public static void main (string agrs[]) { String snum.println(“Enter third number”). system. max1>c?max1:c.out.out.println(“Enter second number”). a = Integer.out. int a.readline( )). c = Integer. system. system. b = Integer.out. b.print(“Error”). input = new DataInputStream(system. system.parseInt(input.i.max1.println(“Enter first number”). } } } OUTPUT: Enter first number 12 Enter second number 40 Enter third number 25 a = 12 b = 40 c = 25 Maximum = 40 .parseInt(input. system.println(“c=” +c).println(“b=” +b).c.out. system.in).out.mport java.println(“Maximum=” +max).println(“a=” +a).

hra = (bs*15)/100. if (bs<=5000) { da = (bs*45)/100.println(“Basic salary is ”+bs).0 DA is 6600. } } } OUTPUT: Enter your basic salary 12000 Basic salary is 12000.out.out.0 .out. system.out.0 Gross salary is 20400.* Class JPS { Public static void main(string args[]) { Float bs. System.out. try { DataInputStream input = new DataInputStream(system.println(“HRA is”+hra). } gs = bs + da + hra .io.floatvalue( ).A PROGRAM WITH GROSS SALARY OF THE PERSON PROGRAM Import java.println(“Enter your basic salary”).0 HRA is 1800.out.da.in). system. hra = (bs*15)/100. bs = float.readline( )). } else { da = (bs*55)/100.gs.hra.println(“Gross salary is ”+gs). system.println(“DA is”+da). } Catch(Exception eobj) { System. system.valueof(input.println(“Error”).

number[i] = number[j]. j++) { if (number[i] < number[j]) { int temp = number[i]. 80.i-).print(“Give list :”). } } OUTPUT: Given List : 55 40 80 65 71 Sorted List: 80 71 65 55 40 . for (int i = 0.out.out.print(“ ” + number. 65.out. number[j] = temp.A PROGRAM WITH SORTIG A LIST OF NUMBERS PROGRAM - Class NumberSorting { Public static void main (string args []) { int number [] = { 55. i++) { for (int j = i+1.out. int n = number. System. i < n. i < n. i++) { System. for (int i = 0.print( “Sorted list :” ). for (int i= 0. } System. 40.out.println(“/n”). j < n. } } } System. { System.out. 71}.println( “ ” ). i++).print(“ ” + number*i+). i < n.length. } System.

} } } OUTPUT: Enter any number a it is a vowel. try { DataInputStream input.A PROGRAM WITH CHECK A CHARACTER FOR VOWEL PROGRAM Import java.println(“It is vowel”).*. input = new DataInputStream(system. } } Catch(Exception eobj) { System. Break.in).out.println(“Enter any character”). ch = (char)inpu.out. Case ‘a’: Case ‘e’: Case ‘i’: Case ‘o’: Case ‘u’: System. switch(ch) { Default: Break. . Class Temp { Public static void main(string args[]) { Char ch.read( ).out. system.println(“Error”).io.

} } Class Circle implements Area { Public float compute (float x. Circle cir = new Circle ( ).println (“Area of Circle =” + area. } } Class Interface Test { Public static void main (String args []) { Rectangle rect = new Rectangle ( ).out.14f. float compute (float x. float y) { return (pi * x *x). } } OUTPUT:Area of rectangle = 200 Area of circle = 314 . System. float y) { return (x * y). compute (10. area = rect.println (“Area of Rectangle =” + area. System. Area area.out. 0)). } Class Rectangle implements Area { Public float compute (float x. 20)). area = cir. float y).compute (10.A PROGRAM WITH IMPLEMENTING INTERFACE PROGRAM Interface Area { final static float pi = 3.

10).volume( ). BedRoom (int x. int z) { Super (x. } int area( ) { return (length * breath).out. System. } } OUTPUT:Area1 = 168 Volume = 1680 .area( ). int area1 = room1. int y) { length=x. int volume1 = room1.println(“volume=” +volume). } int volume( ) { return (length * breadth * height).A PROGAM WITH SINGLE INHERITANCE PROGRAM Class Room { int length. } Classs InherTest { Public static void main ( String args[] ) { BadRoom room1 = new Badroom(14.out. breath=y. int y. int breadth.println(“Area1=” +area1 ).12. } } Class Bedroom extends Room { int height. Room (int x. System. y) height = z.

MONTH).PROGRAM - import java.get (calendar.DAY_OF_MONTH).get (calendar.HOUR).getInstance ( ). int day = cal.YEAR).get (calendar. System. int h = cal. Class temp { Public satic void main(string args []) { Calendar cal = calendar. int s = cal.out.SECOND).get (calendar.calender. } } OUTPUT: Time is 10:40:43 Date is 15/04/2008 .get (calendar.MINUTE).out. int m = cal. int yr = cal.println(“Date is” + day + “/” + mon + “/” + yr). System. int mon = cal.get (calendar.println(“Time is” +h “:”+m “:” +s). mon++.util.

add(but). but.applet. String disp = “ “.PROGRAM Import java.100).*. } Public void actionperformed(ActionEvent.80. Import java.*. } Public void paint (Graphics g) { g.awt. repaint ( ). Public class button extends applet Implements Actionlistioner { Button but. Import java. Public void init ( ) { but = new Button (“click me”). AE) { disp = “you clicked me”.awt. } } // html file <html> <applet code= “button” width = 200*height = 150> </applet> </html> OUTPUT: Applet viewer : button[][] Applet: Click me You clicked me Applet started .event.*.addActionlistener(this).drawstring(disp.

} } Public void paint(Graphics g) { g. import java.getsource( )= but1) { Text = “hello” + tf.blue). } } //html file <html> <applet code = “button3” width=300 height = 150> .drawstring(text.setcolor(color.getText( ). add(tf). Import java.applet.w.event. int h. but1 = new Button (“click Me Now”).awt.pink).*. Llabel l. } Public void actionPerformed (ActionEvent AE) { if(AE. tf = new TextField (30).*.A PROGRAM OF APPLET SHARING TEXTFIELD PROGRAM Import java.120. add(but1). but1. public class button1 extends Applet implements Actionlistner { Button butt. L = new Label (“Please enter your name”). String text = “ ”. Public void init( ) { SetBackground(color. Repaint( ). add(L).awt.addActionListener(this).125). g. Boolean in = false. Textfield tf.*.

</applet> </html> OUTPUT: Applet viewer button3 Applet Please enter your name LIETANS Click Me Now Hello LIETANS Applet Started .

... change current directory man (command) ........ shows who is logged into the local system ..UNIX COMMANDS ls . search the Archie database for a file on a FTP site irc ...... connects to a FTP site archie (filename) ............................ easy to use text editor to edit files pine ... recieve a file (to the unix system) using zmodem telnet (host) .......... pages user for chat .............................. change your password chfn .. connect to another Internet site ftp (host) ... make a directory rmdir ...... shows help on a specific command talk (user) .... connect to Internet Relay Chat lynx .. trn ............ change your "Real Name" as seen on finger chsh ... views a file........... send a file (to you) using zmodem rz ............................................................ remove directory (rm -r to delete folders with files) rm .......... write a user on the local system (control-c to end) pico (filename) ..... a Gopher database browser tin..................... pausing every screenful sz ................... search for a string in a file tail . read Usenet newsgroups passwd .......... a textual World Wide Web browser gopher .... show the last few lines of a file who ............. in alphabetical order logout . easy to use mailer more (file) ...... show directory.(user) is a email address write (user) .......... change the shell you log into grep . logs off system mkdir ................ remove files cd ............................

..... shows who is logged on and what they're doing finger (emailaddr)..w ............ shows more information about a user df .......... shows disk space available on the system du .c) ........... compiles C source into a file named 'a...............out' ... compiles source code gcc (file................................. shows how much disk space is being used up by folders chmod ............. changes permissions on a file bc... a simple calculato make ..