You are on page 1of 24

SCANNER CLASS

import java.io.*;

import java.util.Scanner;

class Circle

double ar,pr;

float pi=3.14f;

void area(int r)

ar=pi*r*r;

System.out.println("\n\tArea of the circle:"+ar);

void perimeter(int r)

pr=2*pi*r;

System.out.println("\n\tPerimtere of the circle:"+pr);

class formula

public static void main(String args[])

int r;

Circle c=new Circle();

Scanner s=new Scanner(System.in);

System.out.println("Area and Perimeter of the circle:");

System.out.println("Enter the radius value:");

r=s.nextInt();
c.area(r);

c.perimeter(r);

OUTPUT:
RANDOM CLASS

import java.io.*;
importjava.util.Random;
public class Arrayrandom
{
public static void main(String args[])
{
Random r=new Random();
int arr[]=new int[20];
for(int i=0;i<20;i++)
{
arr[i]=r.nextInt(10)+1;
}
for(int i=0;i<20;i++)
{
System.out.println(" "+arr[i]);
}
}
}
OUTPUT:
STRING MANIPULATION USING STRING CLASS

import java.io.*;
import java.lang.*;
class Astring
{
public static void main(String args[])throws Exception
{
String S1=new String();
String S2=new String();
String S3=new String();
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(in);
System.out.println("\n\t String manipulation");
System.out.println("\n\t +++++++++++++++++++");
System.out.println("\n\t Input");
System.out.println("\n\t +++++++++++++++++++");
System.out.println("\n\t Enter the first string:");
S1=br.readLine();
System.out.println("\n\t Enter the second string:");
S2=br.readLine();
S3=S1.concat(S2);
System.out.println("\n\t output:");
System.out.println("\n\t _______:");
System.out.println("\n\t First string:"+S1);
System.out.println("\n\t Second string:"+S2);
System.out.println("\n\t Concatination of S1 and S2:"+S3);
System.out.println("\n\t Length of string 3:"+S3.length());
System.out.println("\n\t Substring of string:"+S3.substring(4,7));
System.out.println("\n\t replacing the character 'A' with'Z':"+S3.replace('a','z'));
System.out.println("\n\t Finding the character at 7th positionn:"+S3.charAt(8));
System.out.println("\n\t toLoweCase of the first string:"+S3.toLowerCase());
System.out.println("\n\t toUpperCase of the second string:"+S3.toUpperCase());
System.out.println("\n\t substring of string 3 from 4th position:"+S3.substring(4));
System.out.println("\n\t trim the blank space of string 3:"+S3.trim());
}
}

OUTPUT:
DRAWING OVAL,RECTANGLE,ARC AND CIRCLE USING APPLET

importjava.util.*;
importjava.applet.*;
importjava.awt.*;
/*<applet code ="sample1.class"width=500 ,height=500></applet>*/
public class sample1 extends Applet
{
public void init()
{
setBackground(Color.WHITE);
}
public void paint(Graphics g)
{
\\SQUARE
g.setColor(Color.RED);
g.drawString("SQUARE",80,30);
g.fillRect(50,50,100,100);
\\OVAL
g.setColor(Color.ORANGE);
g.drawString("OVAL",220,50);
g.fillOval(200,80,160,40);
\\ARC
g.setColor(Color.CYAN);
g.drawString("ARC",50,300);
g.fillArc(30,185,100,80,80,80);
\\CIRCLE
g.setColor(Color.RED);
g.drawString("CIRCLE",280,190);
g.fillOval(250,200,110,110);
\\ROUNDRECTANGLE
g.setColor(Color.BLUE);
g.drawString("ROUND RECTANGLE",80,270);
g.fillRoundRect(70,280,80,180,115,115);
}
}

OUTPUT:
Complier:
THREAD BASED APPLICATION AND EXPECTION HANDLING

import java.io.*;
class thread1 extends thread
{
public void run()
{
for(int i=1;i<=10;i=i+2)
{
System.out.println("n\tOdd:"+i);
try
{
thread.sleep(1000);
}
catch(Exception e){}
}
}
}
class thread2 extends thread
{
public void run()
{
for(intj=2;j<=10;j=j+2)
{
System.out.println("\n\tEven:"+j);
try
{
threads.sleep(1000);
}
catch(Excpetion e){}
}
}
}
classte
{
public static void main(String args[])
{
System.out.println("\n\t\tThread&Eception Handling");
System.out.println("\n\t\t**************************");
thread1 t1=new thread1();
thread2 t2=new thread2();
t1.start();
t2.start();
}
}
OUTPUT:
IMPLEMENTING SYCHRONIZATION THREAD CLASS

import java.io.*;
importjava.util.*;
importjava.lang.*;
classcallme
{
synchronized void call(String msg)
{
for(int i=1;i<=3;i++)
{
System.out.println("\n\t\t"+msg+""+i);
}
try
{
Thread.sleep(1000);
}
catch(Exception e)
{
}
}
}
class caller implements Runnable
{
String msg;
callme target;
caller(callmet,String s)
{
target=t;
msg=s;
Thread t1=new Thread(this);
t1.start();
}
public void run()
{
target.call(msg);
}
}
classsyn
{
public static void main(String args[])
{
System.out.println("\n\tApplication using Synchronized");
System.out.println("\n\t**********************************");
callme target=new callme();
caller c1=new caller(target,"HELLO");
caller c2=new caller(target,"SYNCHRONIZED");
caller c3=new caller(target,"WORLD");
}
}
OUTPUT:
SWING COMPONENTS

importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
public class jbd extends JApplet implements ActionListener
{
JLabel label1;
JButton b1,b2;
JTextFieldtf;
public void init()
{
Container c=getContentPane();
c.setLayout(new FlowLayout());
label1=new JLabel("Hello Welcome To Swing",JLabel.CENTER);
add(label1);
b1=new JButton("Internet Expolrer");
b1.setActionCommand("Microsoft Internet Explorer");
b1.setBounds(20,20,150,50);
c.add(b1);
b2=new JButton("NN");
b2.setActionCommand("Netscape\navigator");
b2.setBounds(20,20,150,50);
c.add(b2);
}
public void actionPerformed(ActionEventae)
{
tf.setText(ae.getActionCommand());
}
}
/*<applet code="jbd.class"width=200 height=200></applet>*/

OUTPUT:
LAYOUT MANAGERS AND MENUS

importjava.awt.*;
importjava.applet.*;
/*<applet code="Menus.class"height =300 width=500></applet>*/
public class Menus extends Applet
{
Label l1=new Label("NAME");
TextField tf1=new TextField(10);
Label l2=new Label("QULAFICATION");
TextField tf2=new TextField(10);
Label l3=new Label("POST NAME");
TextField tf3=new TextField(10);
public void init()
{
FlowLayout flow=new FlowLayout();
setLayout(flow);
add(l1);
add(tf1);
add(l2);
add(tf2);
add(l3);
add(tf3);
}
}
OUTPUT:
FILE STREAM (SEQUENTIAL)

import java.io.*;
importjava.lang.*;
class Sequential
{
public static void main(String args[])throws IOException
{
String s="welcome to java";
FileWriter f1=new FileWriter("f.txt");
for(int i=0;i<s.length();i++)
{
f1.write(s.charAt(i));
}
System.out.println("content is uploaded to f.txt");
f1.close();
}
}
OUTPUT:
APPLICATION USING FILE STREAM (RANDOM FILE)

import java.io.*;
classRandomfile
{
public static void main(String args[])
{
RandomAccessFile file=null;
try
{
System.out.println("Random File Handling");
System.out.println("____________________");
file=new RandomAccessFile("rand.dat","rw");
file.writeChar('A');
file.writeInt(111);
file.writeDouble(3.142);
file.seek(0);
System.out.println(file.readChar());
System.out.println(file.readInt());
System.out.println(file.readDouble());
file.seek(2);
System.out.println(file.readInt());
file.writeBoolean(true);
file.seek(4);
System.out.println(file.readBoolean());
file.close();
}
catch(IOException e)
{
System.out.println(e);
}
}
}

OUTPUT:

You might also like