class logik{
public static void main(String[] args) {
boolean Benar = true;
boolean Salah = false;
System.out.println("Hubungan OR (||)");
System.out.println("Benar || Benar : " +(Benar||Benar));
System.out.println("Benar || Salah : " +(Benar||Salah));
System.out.println("Salah || Benar : " +(Salah||Benar));
System.out.println("Salah || Salah : " +(Salah||Salah));
System.out.println("Hubungan AND (&&)");
System.out.println("Benar && Benar : " +(Benar&&Benar));
System.out.println("Benar && Salah : " +(Benar&&Salah));
System.out.println("Salah && Benar : " +(Salah&&Benar));
System.out.println("Salah && Salah : " +(Salah&&Salah));
System.out.println("Hubungan NOT (!)");
System.out.println("Kebalikan (NOT) dari Benar adalah: " +!Benar);
System.out.println("Kebalikan (NOT) dari Salah adalah: " +!Salah);
}
}/*
- This is a random number generation Program where it compares the number you entered and the number the program generats. If it matches, you WIN..
*/
import java.io.*;
import java.util.*;
class lottery
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter your lucky number: ");
int n = input.nextInt();
//Random Generator
Random lotteryNumber = new Random();
int ln;
do
{
ln = lotteryNumber.nextInt();
}
while(lotteryNumber.nextInt() <= 100 && lotteryNumber.nextInt() > 0);
if(ln == n)
{
System.out.println("********************* YOU WIN *********************");
}
else
{
System.out.println("Your number did not match " + ln);
System.out.println("Try Again");
System.exit(1);
}
}
}import java.io.*;
interface weightage
{
int sports = 5;
}
class student
{
int rollno;
}
class test extends student
{
int sub1;
int sub2;
}
class result extends test implements weightage
{
int total;
void gd()throws IOException
{
DataInputStream in = new DataInputStream(System.in);
rollno = Integer.parseInt(in.readLine());
sub1 = Integer.parseInt(in.readLine());
sub2 = Integer.parseInt(in.readLine());
}
void display()
{
total=sub1+sub2+sports;
System.out.println("rollno"+rollno+"sub1"+sub1+"sub2"+sub2);
System.out.println("total"+total);
}
}
class mainresult
{
public static void main(String args[])throws IOException
{
result res=new result();
res.gd();
res.display();
}
}
//import java.lang.Thread.*;
class MainThreadDemo
{
public static void main(String arg[])
{
try
{
Thread th= Thread.currentThread();
System.out.println("Thread="+th);
th.sleep(1000);
System.out.println("Thread name="+th.getName());
th.sleep(1000);
System.out.println("Thread priority="+th.getPriority());
th.setName("MyMainThread");
th.setPriority(th.MAX_PRIORITY);
Thread th1=Thread.currentThread();
System.out.println("Thread="+th1);
System.out.println("Active count Thread="+th1.activeCount());
System.out.println("Alive Thread="+th1.isAlive());
}catch(InterruptedException ie)
{
System.out.println("Error is"+ie);
}
}
}import java.io.*;
class area
{
int x,y;
double z;
void cal(double a,int b)
{
z = a*b*b;
System.out.println("circle area :"+z);
}
void cal(int a)
{
x = a*a;
System.out.println("squre :"+x);
}
void cal(int a,int b)
{
y = a*b;
System.out.println("rectangle :"+y);
}
}
class marea
{
public static void main(String args[])throws IOException
{
System.out.println("1.circle 2.rectangle 3.squre");
DataInputStream in = new DataInputStream(System.in);
int a = Integer.parseInt(in.readLine());
area A = new area();
if(a == 1)
{
System.out.println("enter the radius");
int b = Integer.parseInt(in.readLine());
A.cal(3.14,b);
}
else if(a == 2)
{
System.out.println("enter the length and breath");
int c = Integer.parseInt(in.readLine());
int d = Integer.parseInt(in.readLine());
A.cal(c,d);
}
else
{
System.out.println("enter the squre");
int e = Integer.parseInt(in.readLine());
A.cal(e);
}
}
}
class MathDemo
{
public static void main(String arg[])
{
System.out.println("Square of 2 ="+Math.sqrt(2));
System.out.println("Round value for 1.49 ="+Math.round(1.49));
System.out.println("ceiling value for 1.0001 ="+Math.ceil(1.0001));
System.out.println("Floor value for 1.9999 ="+Math.floor(1.9999));
System.out.println("Max value for 10,20 ="+Math.max(10,20));
System.out.println("Min value for 10,20 ="+Math.min(10,20));
System.out.println("A random num ="+Math.random());
System.out.println("Absolute value of -15 ="+Math.abs(-15));
System.out.println("IEEE value of 1.5,3.0 ="+Math.IEEEremainder(1.5,3.0));
}
}import java.io.*;
class matmul
{
public static void main(String[] args) throws IOException
{
int mat1[][]={{1,2,3},{4,5,6},{7,8,9}};
int mat2[][]={{1,2,3},{4,5,6},{7,8,9}};
int mat3[][],i,j,k;
mat3=new int[3][3];
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
for(k=0;k<=2;k++)
{
mat3[i][j]+=mat1[i][k]*mat2[k][j];
}
}
}
System.out.println("After Matrix Multiplicatin......");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
System.out.print(mat3[i][j]+"\t");
}
System.out.print("\n");
}
}
}
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class MenuDemo extends JFrame implements ActionListener
{
JTextArea t;
JMenuBar mb;
JMenu mf,me;
JMenuItem in,io,is,isa,ie,iu,ip,ic,icu,isal;
JFileChooser jfc;
JScrollPane jsp;
public MenuDemo()
{
jfc=new JFileChooser();
mb=new JMenuBar();
setJMenuBar(mb);
mf=new JMenu("File");
me=new JMenu("Edit");
mb.add(mf);
mb.add(me);
in=new JMenuItem(" New ");
io=new JMenuItem(" Open ");
io.addActionListener(this);
is=new JMenuItem(" Save ");
isa=new JMenuItem(" SaveAs ");
ie=new JMenuItem(" Exit ");
Container ct=getContentPane();
mf.add(in);
mf.add(io);
mf.add(is);
mf.add(isa);
mf.addSeparator();
mf.add(ie);
in.addActionListener(this);
is.addActionListener(this);
isa.addActionListener(this);
ie.addActionListener(this);
iu=new JMenuItem(" Undo ");
ip=new JMenuItem(" Paste ");
ic=new JMenuItem(" Copy ");
icu=new JMenuItem(" Cut ");
isal=new JMenuItem("SelectAll ");
isal.addActionListener(this);
me.add(iu);
me.add(ic);
me.add(ip);
me.add(isal);
me.add(icu);
t=new JTextArea();
jsp=new JScrollPane(t);
ct.add(jsp);
setTitle("Menu");
setSize(300,300);
setVisible(true);
setExtendedState(JFrame.MAXIMIZED_BOTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ae )
{
if(ae.getSource()==ic)
{
t.copy();
}
if(ae.getSource()==ic)
{
t.paste();
}
try{
if(ae.getSource()==in)
{
t.setText("");
}
if(ae.getSource()==ie)
{
System.exit(0);
}
if(ae.getSource()==isal)
{
t.selectAll();
}
if(ae.getSource()==io)
{
jfc.showOpenDialog(this);
try{
FileReader fr=new FileReader(jfc.getSelectedFile());
BufferedReader br=new BufferedReader(fr);
t.setText("");
String data="";
while((data=br.readLine())!=null)
{
t.append(data+"\n");
}
fr.close();
}
catch(Exception e)
{
System.out.println("error in reading "+e);
}
}
if(ae.getSource()==is)
{
jfc.showSaveDialog(this);
try{
FileWriter fw=new FileWriter(jfc.getSelectedFile());
String data=t.getText();
fw.write(data);
fw.close();
}
catch(Exception e)
{
System.out.println("error in writting"+e);
}
}
} catch(Exception e)
{
System.out.println("error is "+e);
}
}
public static void main(String arg[])
{
new MenuDemo();
}
}import java.io.*;
class MenulisFile {
public static void main(String[] args){
if(args.length==0) {
System.out.println("Anda harus memasukkan nama file sebagai parameternya.");
return;
}
String data;
FileWriter fout=null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try{
fout = new FileWriter(args[0]);
System.out.println("Ketik data yang ingin Anda tulis ke file.");
System.out.println("Ketik BERHENTI jika Anda ingin berhenti.");
data = br.readLine();
while(!data.equals("BERHENTI")){
// \r\n digunakan untuk pindah baris
fout.write(data + "\r\n");
data = br.readLine();
}
}catch(FileNotFoundException e) {
System.out.println("File : " + args[0] + " tidak dapat dibuka atau dibuat.");
}catch(IOException e) {
System.out.println("Eksepsi tidak diketahui : " + e);
}finally {
//tutup file
if(fout!=null) {
try{
fout.close();
}catch(IOException err) {
System.out.println("Eksepsi tidak diketahui : " + err);
}
}
}
}
}import java.io.*;
import java.util.*;
class MKDirDemo
{
public static void main(String s[])
{
File f1=new File("d:/Rahul/yyt");
File f2=new File("d:/xty/yyy");
if(f1.mkdir())
{
System.out.println("Directory created");
}
else
{
System.out.println("Parent is not found");
}
if(f2.mkdirs())
{
System.out.println("Nested Directory created");
}
else
{
System.out.println("Drive is not found");
}
}
}import java.io.*;
import java.lang.*;
import java.util.*;
import java.util.Vector;
import java.util.Hashtable;
import java.util.Enumeration;
import com.ibm.aglet.*;
import java.security.Permission.*;
import java.security.AllPermission.*;
import java.net.*;
import com.ibm.aglet.event.*;
public class Monitor extends Aglet
{
static String remote1="atp://veera:8001/";
static String remote="atp://veera:7001/";
static int away = 0;
String token=" ";
String pid[] = new String[100];
String sb;
URL destn;
File f;
int flag=0;
FileInputStream fis;
InputStreamReader is;
BufferedReader br;
FilePermission fp;
AgletContext ac ;
AgletProxy ap;
AgletProxy ap1;
LinkedList address;
public void onCreation(Object init)
{
setText("This is the Monitoring Agent");
try{
// address = new LinkedList();
address = (LinkedList)init;
fp=new FilePermission("D:\\aglets\\public","read");
}
catch(Exception e)
{
System.out.println("Exception");
// while(true)
}
}
public void run()
{
int l=0;
String temp;
System.out.println("In Run");
int count=address.size();
for(int i=0;i
System.out.println(address.get(i));
}
addMobilityListener(new MobilityAdapter(){
public void onArrival(MobilityEvent e)
{
System.out.println("In On Arrival");
away=1;
}
public void onReverting(MobilityEvent e)
{
//System.out.println("Bye");
}
}
);
//if (away==1)
try{
f = new File("D:\\aglets\\public\\dataset.txt");
fis = new FileInputStream(f);
is = new InputStreamReader(fis);
br = new BufferedReader(is);
sb = br.readLine();
do
{
StringTokenizer st = new StringTokenizer(sb,",");
token = st.nextToken();
temp=token;
while(st.hasMoreTokens()){
token = st.nextToken();
}
if(token.equals("normal"))
{
System.out.println("No Problem");
}
else
{
System.out.println("problem");
pid[l++] = temp;
//id=temp;
flag = 1;
}
sb = br.readLine();
}while(sb!= null);
System.out.println(flag);
if(flag==0)
{
System.out.println("In corrective Method");
ac = getAgletContext();
URL destn=ac.getHostingURL();
ap=ac.createAglet(null,"Information",(Object)"Information");
ap.dispatch(destn);
/*String msg=(String)ap1.sendMessage(new Message("No Intrusion"));*/
}
else
{
System.out.println("Error occured so dispatched another aglet");
System.out.println("Veera");
ac = getAgletContext();
URL destn=ac.getHostingURL();
ap=ac.createAglet(null,"Corrective",(Object)pid);
ap.dispatch(destn);
//String msg = (String)ap.sendMessage(new Message(pid));
Thread.sleep(1000000);
//ap = ac.retractAglet(destn,ap.getAgletID());
//ap.dispose();
}
setText("Completed");
away = 0;
}
catch(FileNotFoundException e1)
{
System.out.println("2");
System.out.println("File Error Occured");
}
catch(IOException e1)
{
System.out.println("3");
System.out.println("Error Occured");
}
catch(Exception e1)
{
System.out.println("4");
}
}
}
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/* */
public class MouseAdp extends Applet
{
public void init()
{
addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent me)
{
showStatus("Mouse is clicked at"+me.getX()+","+me.getY());
}
}
);
}
public void paint(Graphics g)
{
g.drawString("This is a demo of Adapter class",50,50);
}
}import java.awt.*;
import java.awt.event.*;
public class MouseAdp1 extends Frame
{
public WindowAdp1()
{
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent me)
{
System.exit(0);
}
}
);
System.out.println("This is demo of Adapter class in frame");
setSize(600,600);
setTitle("Adapter");
setVisible(true);
}
public static void main(String args[])
{
new WindowAdp1();
}
}import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
*/
class MouseLstn implements MouseMotionListener
{
public void mouseDragged(MouseEvent evt)
{
}
public void mouseMoved(MouseEvent evt)
{
int x,y;
x=evt.getX();
y=evt.getY();
mouseapplt.t1.setText(String.valueOf(x)+" , "+String.valueOf(y));
}
}
public class mouseapplt extends Applet
{
static TextField t1=new TextField("......");
public void init()
{
Panel p=new Panel();
p.add(t1);
add(p);
setVisible(true);
setSize(300,400);
addMouseMotionListener(new MouseLstn());
}
}
import java.applet.Applet;
import java.awt.TextField;
import java.awt.Graphics;
import java.awt.Panel;
import java.awt.event.*;
class mmlstn implements MouseMotionListener
{
public void mouseDragged(MouseEvent m)
{
}
public void mouseMoved(MouseEvent m)
{
int x,y;
x=m.getX();
y=m.getY();
mousecoord.t.setText(String.valueOf(x)+" , "+String.valueOf(y));
}
}
public class mousecoord extends Applet
{
static TextField t;
public void init()
{
t=new TextField("RNEC.....");
Panel p=new Panel(); // to manage the components
p.add(t);
add(p);
setSize(300,400);
setVisible(true);
addMouseMotionListener(new mmlstn());
}
public void paint(Graphics g)
{
g.drawRect(20,70,120,150);
}
}
/*
*/
import java.io.*;
import java.awt.*;
import java.awt.event.*;
class mouselstn extends MouseAdapter implements ActionListener
{
Frame f;
Label l1,l2;
static TextField t1,t2;
Button b1,b2;
Panel p;
public void actionPerformed(ActionEvent e)
{
String txt;
Button bt;
bt=(Button)e.getSource();
txt=bt.getLabel();
if(txt.equals("Submit"))
{
mouselstn.t1.setText(" ");
mouselstn.t2.setText(" ");
System.out.println("Your page cannot redirect? then press HELP");
}
else if(txt.equals("HELP"))
{
System.out.println("You Don'y have any Help...Because you are not Naveen������");
}
}
public void mouseClicked(MouseEvent m)
{
System.out.println("no of times mouse clicked.."+m.getClickCount());
}
public mouselstn()
{
p=new Panel();
Label l1=new Label("User Name�");
Label l2=new Label("Password�");
TextField t1=new TextField("000000");
TextField t2=new TextField("000000");
Button b1=new Button("Submit");
Button b2=new Button("HELP");
f=new Frame("My Frame");
b1.addActionListener(this);
b2.addActionListener(this);
f.addMouseListener(this);
p.setLayout(new GridLayout(3,3));
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(b1);
p.add(b2);
f.add(p);
f.setSize(300,400);
f.setVisible(true);
}
public static void main(String args[])
{
new mouselstn();
}
}
import java.io.*;
import java.awt.*;
import java.awt.event.*;
/*
observe the code ( when submit clicks it deletes the textfields data
, help clicked shows the count in out put....
compiled by rvs@cse RNEC
*/
class mouselstn extends MouseAdapter implements ActionListener
{
Frame f;
Label l1,l2;
static TextField t1,t2;
Button b1,b2;
static int clicks;
Panel p;
public void actionPerformed(ActionEvent e)
{
String txt;
Button bt;
bt=(Button)e.getSource();
txt=bt.getLabel();
if(txt.equals("Submit"))
{
mouselstn.t1.setText(" ");
mouselstn.t2.setText(" ");
System.out.println("Your page cannot redirect? then press HELP");
}
else if(txt.equals("HELP"))
{
System.out.println("You Don'y have any Help...Because you are not Naveen������");
}
}
public void mouseClicked(MouseEvent m)
{
System.out.println("no of times mouse clicked........."+clicks++);
}
public mouselstn()
{
p=new Panel();
Label l1=new Label("User Name�");
Label l2=new Label("Password�");
t1=new TextField("000000");
t2=new TextField("000000");
b1=new Button("Submit");
b2=new Button("HELP");
f=new Frame("My Frame");
b1.addActionListener(this);
b2.addActionListener(this);
b2.addMouseListener(this);
p.setLayout(new GridLayout(3,3));
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(b1);
p.add(b2);
f.add(p);
f.setSize(300,400);
f.setVisible(true);
}
public static void main(String args[])
{
new mouselstn();
}
}
/*Dynamic Dispacthing Of Method*/
class Test11
{
void Demo()
{
System.out.println("This in method of Test11 class");
}
}
class Mov extends Test11
{
void Demo()
{
System.out.println("This in method of Mov Subclass");
}
public static void main(String arg[])
{
Test11 t=new Test11();
Mov m=new Mov();
Test11 obj=t;
obj.Demo();
obj=m;
obj.Demo();
}
}
class Test11
{
final int x=10;
void Demo()
{
System.out.println("This in method of Test11 class");
}
}
class Mov1 extends Test11
{
final void Demo()
{
System.out.println("This in method of Mov Subclass="+x);
}
public static void main(String arg[])
{
Test11 t=new Test11();
t.Demo();
Mov1 m=new Mov1();
m.Demo();
Test11 obj=t;
obj.Demo();
obj=m;
obj.Demo();
}
}
//Program 3
//Program to animate a ball
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
/*
*/
public class MovingBall extends Applet implements Runnable,ActionListener
{
Thread t;
boolean flag;
int x=0,y=0,dia=40;
int deltaX=1,deltaY=2;
int xbound,ybound;
Button start, stop;
public void init()
{
start = new Button("Start");
stop = new Button("Stop");
add(start);
add(stop);
start.addActionListener(this);
stop.addActionListener(this);
setBackground(Color.gray);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource() == start)
{
t=new Thread(this);
flag=true;
t.start();
}
else if(ae.getSource() == stop)
{
flag=false;
}
}
public void run()
{
int width = getSize().width;
int height = getSize().height;
xbound=width-dia;
ybound=height-dia;
while(flag)
{
try
{
x+=deltaX ;
y+=deltaY;
repaint();
Thread.sleep(5);
if(x > xbound || x < 0)
deltaX = - deltaX;
if(y > ybound || y < 0)
deltaY= -deltaY;
}
catch(InterruptedException ie)
{
System.out.println("Error:"+ie);
}
}
}
public void paint(Graphics g)
{
g.setColor(Color.RED);
g.fillOval(x,y,dia,dia);
}
}
import java.io.*;
import stud.*;
class result extends student
{
int total;
void get()throws IOException
{
DataInputStream in = new DataInputStream(System.in);
System.out.print("enter the details\t:");
rollno = Integer.parseInt(in.readLine());
sub1 = Integer.parseInt(in.readLine());
sub2 = Integer.parseInt(in.readLine());
}
void display()
{
total = sub1+sub2;
System.out.println("total = :"+total);
}
}
class mres
{
public static void main(String args[])throws IOException
{
result R = new result();
R.get();
R.display();
}
}import java.io.*;
interface display1
{
String maker[] = {"bata","canas","paragoan"};
String ph[] = {"9943982390","9578437743","99527787843"};
}
class sh implements display1
{
void gd(int x)
{
System.out.println(maker[x]);
System.out.println(ph[x]);
}
}
class issue extends sh
{
void pd(int y)
{
gd(y);
}
}
class msh
{
public static void main(String args[])throws IOException
{
DataInputStream in =new DataInputStream(System.in);
issue I = new issue();
int x = Integer.parseInt(in.readLine());
I.pd(x);
}
}import java.lang.Thread;
class threada extends Thread
{
public threada(String msg)
{
super(msg);
}
public void run()
{
int i;
try
{
System.out.println(getName()+" Started....");
for(i=1;i<=10;i++)
{
System.out.println(" i = "+i);
//sleep(100);
}
System.out.println(getName()+" Exited....");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
class threadb extends Thread
{
public threadb(String msg)
{
super(msg);
}
public void run()
{
int j;
try
{
System.out.println(getName()+" Started....");
for(j=1;j<=10;j++)
{
System.out.println(" j = "+j);
}
System.out.println(getName()+" Exited....");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
class threadc extends Thread
{
public threadc(String msg)
{
super(msg);
}
public void run()
{
int k;
try
{
System.out.println(getName()+" Started....");
for(k=1;k<=10;k++)
{
System.out.println(" k = "+k);
//sleep(200);
}
System.out.println(getName()+" Exited....");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
class multhread
{
public static void main(String arg[])
{
//creating new threads
threada t1=new threada("Thread A");
threadb t2=new threadb("Thread B");
threadc t3=new threadc("Thread C");
//setting priority
//t2.setPriority(Thread.MAX_PRIORITY);
///t1.setPriority(Thread.MAX_PRIORITY);
//t3.setPriority(Thread.MIN_PRIORITY);
//starting new threads
t1.start();
t2.start();
t3.start();
}
}
import java.lang.Thread;
/*
Java program that creates three threads first thread to display
"GOOD MORNING" every 1 sec , second thread to display HELLO for every 2 sec and
third thread to display WELCOME for every 3 sec
*/
class threada extends Thread
{
public void run()
{
try
{
for(;;)
{
System.out.println("GOOD MORNING");
sleep(1000);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
class threadb extends Thread
{
public void run()
{
try
{
for(;;)
{
System.out.println("HELLO");
sleep(2000);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
class threadc extends Thread
{
public void run()
{
try
{
for(;;)
{
System.out.println("WELCOME");
sleep(3000);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
class multhreads
{
public static void main(String arg[])
{
//creating new threads
threada t1=new threada();
threadb t2=new threadb();
threadc t3=new threadc();
//starting new threads
t1.start();
t2.start();
t3.start();
}
}
class Test1
{
int x,y;
void getData(int x1,int y1)
{
x=x1;
y=y1;
}
void add()
{
int z=x+y;
System.out.println("Addtion of "+x+"and"+y+"is="+z);
}
}
class SingleInherit extends Test1
{
void sub()
{
int z=x-y;
System.out.println("Substraction of "+x+"and"+y+"is="+z);
}
}
class Multi extends SingleInherit
{
void div()
{
float z=x/y;
System.out.println("Division of "+x+"and"+y+"is="+z);
}
public static void main(String arg[])
{
Multi s=new Multi();
s.getData(5,10);
s.add();
s.sub();
s.div();
}
}
class Test2
{
int x,y;
void getData(int x1,int y1)
{
x=x1;
y=y1;
}
}
class SingleInherit1 extends Test1
{
void add()
{
int z=x+y;
System.out.println("Addtion of "+x+"and"+y+"is="+z);
}
}
class SingleInherit extends Test1
{
void sub()
{
int z=x-y;
System.out.println("Substraction of "+x+"and"+y+"is="+z);
}
}
class Multi1
{
public static void main(String arg[])
{
SingleInherit1 s1 =new SingleInherit1 ();
SingleInherit s2 =new SingleInherit ();
s1.getData(20,10);
s2.getData(20,10);
s1.add();
s2.sub();
}
}
class MultiCatch
{
public static void main(String s[])
{
Demo d=new Demo();
d.Sq(-5);
/* try
{
int arr[]=new int[4];
System.out.println("Array elements at 4th pointer="+arr[4]);
}
catch(ArithmeticException e)
{
System.out.println("NullPointer Exception "+e);
e.printStackTrace();
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Array inde out of bound"+e);
}
finally
{
System.out.println("Hello Deepak");
}*/
try
{
int a=10;
int b=0;
System.out.println("a="+a+"\n b="+b);
int c=a/b;
System.out.println("result is "+c);
}
catch(ArithmeticException e)
{
System.out.println("NullPointer Exception "+e);
e.printStackTrace();
}
catch(Exception e)
{
System.out.println("Exception is "+e);
}
finally
{
System.out.println("Hello Rahul");
}
System.out.println("hello ");
}
}
class Demo
{
void Sq(int n)
{
/*try
{*/
if(n<0 p=""> {
throw new ArithmeticException();
}
else
{
int s=n*n;
System.out.println("Square of "+n+" is "+s);
}
/*}
catch(ArithmeticException e)
{
System.out.println("Caught inside method itself "+e);
}*/
}
}class ThreadBaru extends Thread {
public ThreadBaru(String id) {
super(id);
start(); //Mulai eksekusi thread baru
}
public void run() {
for(int i=0;i<5 i="" p=""> try{
Thread.sleep(100);
}catch(InterruptedException e) {}
}
}
}
class DemoThread {
public static void main(String[] args)throws Exception {
ThreadBaru thread1 = new ThreadBaru("Thread1");
ThreadBaru thread2 = new ThreadBaru("Thread2");
ThreadBaru thread3 = new ThreadBaru("Thread3");
System.out.println("Thread1 masih dieksekusi : " + thread1.isAlive());
System.out.println("Thread2 masih dieksekusi : " + thread2.isAlive());
System.out.println("Thread3 masih dieksekusi : " + thread3.isAlive());
//tunggu hingga semua child thread selesai dieksekusi
try{
thread1.join();
System.out.println("Thread1 selesai dieksekusi");
thread2.join();
System.out.println("Thread2 selesai dieksekusi");
thread3.join();
System.out.println("Thread3 selesai dieksekusi");
}catch(InterruptedException e) {
System.out.println("Thread utama diinterupsi " + e);
}
System.out.println("Thread utama selesai dieksekusi");
}
}import java.awt.*;
import java.applet.*;
public class myapp extends Applet
{
public void paint(Graphics g)
{
g.drawString("Welcome to Applet",100,50);
}
}
/*
5>0>
*/
import java.applet.*;
import java.awt.*;
public class myapplet extends Applet{
String str;
public void init(){
str = "This is my first applet";
}
public void paint(Graphics g){
g.drawString(str, 50,50);
}
}import java.awt.*;
import java.awt.event.*;
public class MyBorder extends Frame implements WindowListener,ActionListener
{
Button b1,b2,b3,b4;
TextField t1;
public MyBorder()
{
b1=new Button("NORTH");
b1.addActionListener(this);
b2=new Button("SOUTH");
b2.addActionListener(this);
b3=new Button("EAST");
b3.addActionListener(this);
b4=new Button("WEST");
b4.addActionListener(this);
t1=new TextField(20);
addWindowListener(this);
add(b1,BorderLayout.NORTH);
add(b2,BorderLayout.SOUTH);
add(b3,BorderLayout.EAST);
add(b4,BorderLayout.WEST);
add(t1,BorderLayout.CENTER);
setTitle("Border Layout demo");
setSize(600,600);
setVisible(true);
setResizable(false);
}
public void windowActivated(WindowEvent e)
{
}
public void windowClosed(WindowEvent e)
{
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowDeactivated(WindowEvent e)
{
}
public void windowDeiconified(WindowEvent e)
{
}
public void windowIconified(WindowEvent e)
{
}
public void windowOpened(WindowEvent e)
{
}
public void actionPerformed(ActionEvent ae)
{
try
{
if(ae.getSource()==b1)
{
t1.setText(b1.getLabel());
}
if(ae.getSource()==b2)
{
t1.setText(b2.getLabel());
}
if(ae.getSource()==b3)
{
t1.setText(b3.getLabel());
}
if(ae.getSource()==b4)
{
t1.setText(b4.getLabel());
}
}
catch(Exception e)
{
System.out.println("Error is"+e);
}
}
public static void main(String args[])
{
new MyBorder();
}
}
import java.awt.*;
class mycanvas
{
public static void main(String[] args)
{
Frame f=new Frame("My Frame");
Canvas c1=new Canvas();
Label l1=new Label("Enter Ur name?");
c1.setBackground(Color.red);
c1.setSize(100,100);
Canvas c2=new Canvas();
Label l2=new Label("Enter Age?");
c2.setBackground(Color.green);
c2.setSize(100,100);
Canvas c3=new Canvas();
Label l3=new Label("Enter Age?");
c3.setBackground(Color.blue);
c3.setSize(100,100);
f.add(l1);
f.add(c1);
f.add(l2);
f.add(c2);
f.add(l3);
f.add(c3);
f.setLayout(new GridLayout(3,2));
f.setSize(300,400);
f.setVisible(true);
}
}
import java.rmi.*;
public class MyClient
{
public static void main(String arg[])
{
try
{
MyRemote obj=(MyRemote)Naming.lookup("rmi://localhost:1099/OBJ1");
System.out.println("Calling remote methods");
int a=20,b=5,c=0;
c=obj.add(a,b);
System.out.println("Addition of"+a+" and "+b+" is "+c);
c=obj.sub(a,b);
System.out.println("Substraction of"+a+" and "+b+" is "+c);
c=obj.multi(a,b);
System.out.println("Multiplication of"+a+" and "+b+" is "+c);
c=obj.div(a,b);
System.out.println("division of"+a+" and "+b+" is "+c);
}catch(Exception e)
{
System.out.println("Error in lookup"+e);
}
}
}class MyException extends Exception
{
int n;
MyException()
{
n=0;
System.out.println("Default Contructor");
}
MyException(int n)
{
this.n=n;
System.out.println("Parametarized Contructor");
}
public String toString()
{
return "Cube is not allowed for negative no. :"+n;
}
}
import java.awt.*;
import java.awt.event.*;
public class MyForm extends Frame implements ItemListener
{
Label l1,l2,l3,l4;
TextField t1,t2;
Checkbox c1,c2,c3,c4,c5,c6,c7,c8,c9,c10;
Panel p1,p2,p3,p4,p5,mainp;
public MyForm()
{
l1=new Label(" Hobbies");
l2=new Label(" Your hobbies are:");
l3=new Label(" Color");
l4=new Label(" Your favourite color is:");
t1=new TextField(20);
t2=new TextField(20);
c1=new Checkbox(" Reading");
c1.addItemListener(this);
c2=new Checkbox(" Singing");
c2.addItemListener(this);
c3=new Checkbox(" Dancing");
c3.addItemListener(this);
c4=new Checkbox(" Travelling");
c4.addItemListener(this);
c5=new Checkbox(" Watching TV");
c5.addItemListener(this);
c6=new Checkbox(" Chatting");
c6.addItemListener(this);
CheckboxGroup cg=new CheckboxGroup();
c7=new Checkbox("Red",false,cg);
c7.addItemListener(this);
c8=new Checkbox("Green",false,cg);
c8.addItemListener(this);
c9=new Checkbox("Blue",false,cg);
c9.addItemListener(this);
c10=new Checkbox("Yellow",false,cg);
c10.addItemListener(this);
p1=new Panel(new GridLayout(1,1));
p1.add(l1);
p2=new Panel(new GridLayout(2,3));
p2.add(c1);
p2.add(c2);
p2.add(c3);
p2.add(c4);
p2.add(c5);
p2.add(c6);
p3=new Panel(new GridLayout(3,1));
p3.add(l2);
p3.add(t1);
p3.add(l3);
p4=new Panel(new GridLayout(1,4));
p4.add(c7);
p4.add(c8);
p4.add(c9);
p4.add(c10);
p5=new Panel(new GridLayout(2,1));
p5.add(l4);
p5.add(t2);
mainp=new Panel(new GridLayout(5,1));
mainp.add(p1);
mainp.add(p2);
mainp.add(p3);
mainp.add(p4);
mainp.add(p5);
add(mainp);
setTitle(" My Form ");
setSize(300,300);
setVisible(true);
}
public void itemStateChanged(ItemEvent ie)
{
try
{
if(ie.getItemSelectable()==c1 || ie.getItemSelectable()==c2 || ie.getItemSelectable()==c3 || ie.getItemSelectable()==c4 || ie.getItemSelectable()==c5 || ie.getItemSelectable()==c6)
{
t1.setText(" ");
if(c1.getState()==true)
{
t1.setText(t1.getText()+c1.getLabel()+" , ");
}
if(c2.getState()==true)
{
t1.setText(t1.getText()+c2.getLabel()+" , ");
}
if(c3.getState()==true)
{
t1.setText(t1.getText()+c3.getLabel());
}
if(c4.getState()==true)
{
t1.setText(t1.getText()+c4.getLabel());
}
if(c5.getState()==true)
{
t1.setText(t1.getText()+c5.getLabel());
}
if(c6.getState()==true)
{
t1.setText(t1.getText()+c6.getLabel());
}
}
if(c7.getState())
{
t2.setText(c7.getLabel());
t2.setBackground(Color.red);
}
if(c8.getState())
{
t2.setText(c8.getLabel());
t2.setBackground(Color.green);
}
if(c9.getState())
{
t2.setText(c9.getLabel());
t2.setBackground(Color.blue);
}
if(c10.getState())
{
t2.setText(c10.getLabel());
t2.setBackground(Color.yellow);
}
}
catch(Exception e)
{
}
}
public static void main(String args[])
{
new MyForm();
}
}
import java.awt.*;
import java.awt.event.*;
public class MyForm1 extends Frame implements ItemListener,ActionListener
{
Label l1,l2,l3,l4;
Choice c1;
List l;
TextField t1,t2;
Button b1;
Panel p1,p2,p3,p4,p5,p6,p7,p8,p9,wp,ep,mp;
public MyForm1()
{
l1=new Label("Product name");
l2=new Label("Quantity");
l3=new Label("Total Amount");
l4=new Label("Price");
c1=new Choice();
c1.add("CPU");
c1.add("RAM");
c1.add("Monitor");
c1.add("ROM");
c1.add("Keyboard");
c1.add("Mouse");
c1.addItemListener(this);
l=new List();
l.add("7000");
l.add("1500");
l.add("6000");
l.add("5000");
l.add("600");
l.add("5400");
t1=new TextField(20);
t2=new TextField(20);
b1=new Button("Calculate");
b1.addActionListener(this);
p1=new Panel();
p1.add(l1);
p2=new Panel();
p2.add(c1);
p3=new Panel();
p3.add(l2);
p4=new Panel();
p4.add(t1);
p5=new Panel();
p5.add(l3);
p6=new Panel();
p6.add(t2);
p7=new Panel();
p7.add(l4);
p8=new Panel();
p8.add(l);
p9=new Panel();
p9.add(b1);
wp=new Panel(new GridLayout(6,1));
wp.add(p1);wp.add(p2);wp.add(p3);wp.add(p4);wp.add(p5);wp.add(p6);
ep=new Panel();
ep.add(p7);ep.add(p8);ep.add(p9);
mp=new Panel(new GridLayout(1,2));
mp.add(wp);mp.add(ep);
add(mp);
setTitle(" My Form ");
setSize(300,300);
setVisible(true);
}
public void itemStateChanged(ItemEvent ie)
{
//if(e.getSelectedItem()=="keyboard")
l.select(c1.getSelectedIndex());
}
public void actionPerformed(ActionEvent ae)
{
try
{
int p=Integer.parseInt(l.getSelectedItem());
int q=Integer.parseInt(t1.getText());
int t=p*q;
t2.setText(""+t);
t2.setEditable(false);
}
catch(Exception e)
{
}
}
public static void main(String args[])
{
new MyForm1();
}
}import java.awt.*;
public class MyFrame extends Frame
{
MyFrame()
{
}
public static void main(String args[])
{
new MyFrame();
}
}import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MyFrame1 extends JFrame implements ActionListener
{
JLabel l1,l2,l3,l4;
JButton b1,b2,b3,b4;
JTextArea a1;
JTextField t1,t2,t3;
JPanel p1,p2,p3,mp;
MyFrame1()
{
l1=new JLabel("NUM1");
l2=new JLabel("NUM2");
l3=new JLabel("RESULT");
l4=new JLabel("ALL OPERATION");
b1=new JButton(" + ");
b1.addActionListener(this);
b2=new JButton(" - ");
b2.addActionListener(this);
b3=new JButton(" / ");
b3.addActionListener(this);
b4=new JButton(" * ");
b4.addActionListener(this);
t1=new JTextField();
t2=new JTextField();
t3=new JTextField();
a1=new JTextArea(4,4);
p1=new JPanel(new GridLayout(3,2));
p2=new JPanel();
p3=new JPanel(new GridLayout(2,1));
mp=new JPanel(new GridLayout(3,1));
p1.add(l1);
p1.add(t1);
p1.add(l2);
p1.add(t2);
p1.add(l3);
p1.add(t3);
p2.add(b1);
p2.add(b2);
p2.add(b3);
p2.add(b4);
p3.add(l4);
p3.add(a1);
mp.add(p1);
mp.add(p2);
mp.add(p3);
Container ct=getContentPane();
ct.setLayout(new FlowLayout());
ct.add(mp);
setTitle("Demo");
setVisible(true);
setSize(400,400);
}
public void actionPerformed(ActionEvent ae)
{
try
{
if(ae.getSource()==b1)
{
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int c=a+b;
t3.setText(""+c);
a1.append("\n"+t1.getText()+" + "+t2.getText()+" = "+t3.getText());
}
if(ae.getSource()==b2)
{
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int c=a-b;
t3.setText(""+c);
a1.append("\n"+t1.getText()+" - "+t2.getText()+" = "+t3.getText());
}
if(ae.getSource()==b3)
{
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int c=a/b;
t3.setText(""+c);
a1.append("\n"+t1.getText()+" / "+t2.getText()+" = "+t3.getText());
}
if(ae.getSource()==b4)
{
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int c=a*b;
t3.setText(""+c);
a1.append("\n"+t1.getText()+" * "+t2.getText()+" = "+t3.getText());
}
}catch(Exception e)
{
System.out.println("Error is"+e);
}
}
public static void main(String arg[])
{
new MyFrame1();
}
}
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.awt.event.*;
public class MyFrame11 extends JFrame implements ActionListener
{
JLabel l1,l2,l3,l4;
JTextField t1,t2;
JPanel p1,p2,mp;
JComboBox cb;
JList lt;
JButton b1;
Vector v;
JScrollPane s;
MyFrame11()
{
cb=new JComboBox();
cb.addItem("CPU");
cb.add
cb.addItem("Mouse");
cb.addItem("KeyBoard");
cb.addItem("RAM");
cb.addItem("HD");
cb.addItem("Monitor");
cb.addItem("CPU11");
cb.addItem("Mouse11");
cb.addItem("KeyBoard11");
cb.addItem("RAM11");
cb.addItem("HD11");
cb.addItem("Monitor11");
v=new Vector();
v.add("2500");
v.add("1500");
v.add("500");
v.add("200");
v.add("3500");
v.add("100");
v.add("2500");
v.add("01500");
v.add("0500");
v.add("0200");
v.add("03500");
v.add("0100");
lt=new JList(v);
l1=new JLabel("Product");
l2=new JLabel("Qty");
l3=new JLabel("Total");
l4=new JLabel("Price");
t1=new JTextField();
t2=new JTextField();
b1=new JButton("Calculate");
s=new JScrollPane(lt);
p1=new JPanel(new GridLayout(15,1));
p1.add(l1);
p1.add(cb);
p1.add(l2);
p1.add(t1);
p1.add(l3);
p1.add(t2);
p1.add(b1);
p2=new JPanel(new GridLayout(5,1));
p2.add(l4);
p2.add(s);
mp=new JPanel(new GridLayout(1,2));
mp.add(p1);
mp.add(p2);
Container ct=getContentPane();
ct.setLayout(new FlowLayout());
ct.add(mp);
setTitle("Demo");
setVisible(true);
setSize(400,400);
}
public static void main(String arg[])
{
new MyFrame11();
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MyFrame2 extends JFrame implements ItemListener
{
JLabel l1,l2,l3,l4;
JCheckBox b1,b2,b3,b4,b5;
JRadioButton r1,r2,r3,r4,r5;
JTextField t1,t2;
JPanel p1,p2,p3,p4,p5,mp;
ButtonGroup bg;
MyFrame2()
{
l1=new JLabel("Different OS are");
l2=new JLabel("Your favourite OS's are");
l3=new JLabel("Different countries are");
l4=new JLabel("Your favourite country are");
b1=new JCheckBox("Dos");
b1.addItemListener(this);
b2=new JCheckBox("Win 98");
b2.addItemListener(this);
b3=new JCheckBox("Win NT");
b3.addItemListener(this);
b4=new JCheckBox("WinXP");
b4.addItemListener(this);
b5=new JCheckBox("Win2000");
b5.addItemListener(this);
r1=new JRadioButton("India");
r1.addItemListener(this);
r2=new JRadioButton("USA");
r2.addItemListener(this);
r3=new JRadioButton("UK");
r3.addItemListener(this);
r4=new JRadioButton("Japan");
r4.addItemListener(this);
r5=new JRadioButton("Russia");
r5.addItemListener(this);
t1=new JTextField();
t2=new JTextField();
p1=new JPanel();
p2=new JPanel();
p3=new JPanel(new GridLayout(3,1));
p4=new JPanel();
p5=new JPanel(new GridLayout(2,1));
mp=new JPanel(new GridLayout(5,1));
bg=new ButtonGroup();
bg.add(r1);
bg.add(r2);
bg.add(r3);
bg.add(r4);
bg.add(r5);
p1.add(l1);
p2.add(b1);
p2.add(b2);
p2.add(b3);
p2.add(b4);
p2.add(b5);
p3.add(l2);
p3.add(t1);
p3.add(l3);
p4.add(r1);
p4.add(r2);
p4.add(r3);
p4.add(r4);
p4.add(r5);
p5.add(l4);
p5.add(t2);
mp.add(p1);
mp.add(p2);
mp.add(p3);
mp.add(p4);
mp.add(p5);
Container ct=getContentPane();
ct.setLayout(new FlowLayout());
ct.add(mp);
setTitle("Demo");
setVisible(true);
setSize(400,400);
}
public void itemStateChanged(ItemEvent ae)
{
if(ae.getItemSelectable()==b1 || ae.getItemSelectable()==b2 || ae.getItemSelectable()==b3 || ae.getItemSelectable()==b4 || ae.getItemSelectable()==b5 )
{
t1.setText("");
if(b1.isSelected())
t1.setText(t1.getText()+b1.getText());
if(b2.isSelected())
t1.setText(t1.getText()+b2.getText());
if(b3.isSelected())
t1.setText(t1.getText()+b3.getText());
if(b4.isSelected())
t1.setText(t1.getText()+b4.getText());
if(b5.isSelected())
t1.setText(t1.getText()+b5.getText());
}
if(r1.isSelected())
t2.setText("India");
if(r2.isSelected())
t2.setText("USA");
if(r3.isSelected())
t2.setText("UK");
if(r4.isSelected())
t2.setText("Japan");
if(r5.isSelected())
t2.setText("Russia");
}
public static void main(String arg[])
{
new MyFrame2();
}
}
import java.awt.*;
import java.awt.event.*;
public class Labeltextdemo extends Frame
{
Label l1,l2;
TextField t1,t2; // declaration
public Labeltextdemo()
{
l1=new Label("Num");
l2=new Label("Square"); // construction
t1=new TextField(20);
t2=new TextField(20);
add(l1);
add(t1); // adding component
add(l2);
add(t2);
setTitle("Text Label demo");
setSize(600,600);
setVisible(true);
}
public static void main(String args[])
{
new Labeltextdemo();
}
}package mypackage;
public class Demo11
{
public static void demo()
{
System.out.println("this is static mrthod of demo1 class");
}
}
import java.rmi.*;
public interface MyRemote extends Remote
{
public int add(int a,int b)throws RemoteException;
public int sub(int a,int b)throws RemoteException;
public int multi(int a,int b)throws RemoteException;
public int div(int a,int b)throws RemoteException;
}import java.rmi.*;
public interface MyRemote1 extends Remote
{
public void deposit(int amt)throws RemoteException;
public void withdraw(int amt)throws RemoteException;
public int getbalance()throws RemoteException;
}import java.rmi.*;
import java.rmi.server.*;
public class MyServer extends UnicastRemoteObject implements MyRemote
{
public MyServer(String nm)throws RemoteException
{
try{
Naming.bind(nm,this);
System.out.println("Object binded here.......");
}catch(Exception e)
{
System.out.println("Error in binding"+e);
}
}
public int add(int a,int b) throws RemoteException
{
return (a+b);
}
public int sub(int a,int b) throws RemoteException
{
return (a-b);
}
public int multi(int a,int b) throws RemoteException
{
return (a*b);
}
public int div(int a,int b) throws RemoteException
{
return (a/b);
}
public static void main(String arg[])throws RemoteException
{
new MyServer("OBJ1");
System.out.println("Server started here");
}
}import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class MyTabbed extends JFrame
{
JTabbedPane jtab;
public MyTabbed()
{
jtab=new JTabbedPane();
jtab.addTab("SquarePanel", new SquarePanel());
jtab.addTab("CubePanel", new CubePanel());
Container ct=getContentPane();
ct.add(jtab);
setTitle("Tabbed Demo");
setSize(500,500);
setVisible(true);
}
public static void main(String arg[])
{
new MyTabbed();
}
}
class SquarePanel extends JPanel implements ActionListener
{
JLabel l1,l2;
JTextField t1,t2;
JButton b1;
JPanel mp,p1,p2;
SquarePanel()
{
l1=new JLabel("Num1");
l2=new JLabel("Square");
t1=new JTextField(20);
t2=new JTextField(20);
b1=new JButton("Square");
b1.addActionListener(this);
p1=new JPanel(new GridLayout(2,2));
p1.add(l1); p1.add(t1); p1.add(l2); p1.add(t2);
p2=new JPanel();
p2.add(b1);
mp=new JPanel(new GridLayout(2,1));
mp.add(p1); mp.add(p2);
add(mp);
}
public void actionPerformed(ActionEvent ae)
{
int x=Integer.parseInt(t1.getText());
int a=x*x;
t2.setText(""+a);
}
}
class CubePanel extends JPanel implements ActionListener
{
JLabel l1,l2;
JTextField t1,t2;
JButton b1;
JPanel mp,p1,p2;
CubePanel()
{
l1=new JLabel("Num1");
l2=new JLabel("Cube");
t1=new JTextField(20);
t2=new JTextField(20);
b1=new JButton("Cube");
b1.addActionListener(this);
p1=new JPanel(new GridLayout(2,2));
p1.add(l1); p1.add(t1); p1.add(l2); p1.add(t2);
p2=new JPanel();
p2.add(b1);
mp=new JPanel(new GridLayout(2,1));
mp.add(p1); mp.add(p2);
add(mp);
}
public void actionPerformed(ActionEvent ae)
{
int x=Integer.parseInt(t1.getText());
int a=x*x*x;
t2.setText(""+a);
}
}class MyThread implements Runnable
{
Thread th;
MyThread(String nm,int p)
{
th=new Thread(this,nm);
th.start();
System.out.println(th.getName()+"Thread Started Here");
th.setPriority(p);
}
public void run()
{
for(int i=0;i<4 i="" p=""> {
System.out.println("Inside"+th.getName()+"i="+i);
try{
th.sleep(1000);
}catch(InterruptedException e)
{
System.out.println("Child Thread Interruptde");
}
}
System.out.println(th.getName()+" Thread Over Here");
}
public static void main(String arg[])
{
System.out.println("Main Thread Started Here");
MyThread obj1=new MyThread(" One",3);
MyThread obj2=new MyThread(" Two",5);
MyThread obj3=new MyThread(" Three",7);
//MyThread rd=new MyThread();
for(int i=0;i<4 i="" p=""> {
System.out.println("Inside Main Thread i="+i);
try{
Thread.sleep(1000);
}catch(InterruptedException e)
{
System.out.println("Main Thread Interruptde");
}
}
// System.out.println("Main Thread Over Here");
}
}
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class Notepad extends JFrame implements ActionListener
{
JTextArea t;
JMenuBar mb;
JMenu mf,me,ce;
JMenuItem in,io,is,isa,ie,iu,ip,ic,icu,isal,cd;
JFileChooser jfc;
JColorChooser jcc;
JScrollPane jsp;
public Notepad()
{
mb=new JMenuBar();
setJMenuBar(mb);
mf=new JMenu("File");
me=new JMenu("Edit");
ce=new JMenu("Color");
mb.add(mf);
mb.add(me);
mb.add(ce);
in=new JMenuItem("New");
io=new JMenuItem("Open");
is=new JMenuItem("Save");
isa=new JMenuItem("SaveAs");
ie=new JMenuItem("Exit");
in.setMnemonic('N');
jfc=new JFileChooser();
jcc=new JColorChooser();
Container ct=getContentPane();
mf.add(in);
mf.add(io);
mf.add(is);
mf.add(isa);
mf.addSeparator();
mf.add(ie);
iu=new JMenuItem("Undo");
ip=new JMenuItem("Paste");
ic=new JMenuItem("Copy");
icu=new JMenuItem("Cut");
isal=new JMenuItem("SelectAll");
cd=new JMenuItem("ColorDialog");
ce.add(cd);
in.addActionListener(this);
io.addActionListener(this);
is.addActionListener(this);
isa.addActionListener(this);
ie.addActionListener(this);
iu.addActionListener(this);
ip.addActionListener(this);
ic.addActionListener(this);
icu.addActionListener(this);
isal.addActionListener(this);
cd.addActionListener(this);
me.add(iu);
me.add(ic);
me.add(ip);
me.add(icu);
me.add(isal);
t=new JTextArea();
jsp=new JScrollPane(t);
ct.add(jsp);
setTitle("Menu");
setSize(300,300);
setVisible(true);
setExtendedState(JFrame.MAXIMIZED_BOTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ae )
{
try{
if(ae.getSource()==in)
{
t.setText("");
}
if(ae.getSource()==ie)
{
System.exit(0);
}
if(ae.getSource()==isal)
{
t.selectAll();
}
if(ae.getSource()==io)
{
jfc.showOpenDialog(this);
try{
FileReader fr=new FileReader(jfc.getSelectedFile());
BufferedReader br=new BufferedReader(fr);
t.setText("");
String data="";
while((data=br.readLine())!=null)
{
t.append(data+"\n");
}
fr.close();
}
catch(Exception e)
{
System.out.println("error in reading "+e);
}
}
if(ae.getSource()==is)
{
jfc.showSaveDialog(this);
try{
FileWriter fw=new FileWriter(jfc.getSelectedFile(),true);
String data=t.getText();
fw.write(data);
fw.close();
}
catch(Exception e)
{
System.out.println("error in writting"+e);
}
}
if(ae.getSource()==ic)
{
t.copy();
}
if(ae.getSource()==icu)
{
t.cut();
}
if(ae.getSource()==ip)
{
t.paste();
}
if(ae.getSource()==cd)
{
Color c=jcc.showDialog(this,"ColorDailog",Color.red);
t.setForeground(c);
}
} catch(Exception e)
{
System.out.println("error is "+e);
}
}
public static void main(String arg[])
{
new Notepad();
}
}class ObjArg
{
int x;
ObjArg(int x1)
{
x=x1;
}
void increase(ObjArg o)
{
System.out.println("original Value of x="+o.x);
x=o.x+10;
System.out.println("Udate Value="+x);
}
public static void main(String arg[])
{
ObjArg Obj1=new ObjArg(7);
Obj1.increase(Obj1);
}
}
/*CLASS CAN BE USED AS ARRGUMENT'S & RETURN TYPE*/
class ObjReturn
{
int x;
ObjReturn(int x1)
{
x=x1;
}
ObjReturn increase() //RETURN TYPE
{
ObjReturn ob=new ObjReturn(x+10);
return ob;
}
public static void main(String arg[])
{
ObjReturn Obj1=new ObjReturn(6); //PARAMETERISED CONSTRUCTOR
System.out.println("original Value of x="+Obj1.x);
ObjReturn Obj2=Obj1.increase(); //REFERNCE VARIABLE
System.out.println("New Value of x="+Obj2.x);
Obj2=Obj2.increase(); //VARIABLE INSTALIZATION
System.out.println("Again Value of x="+Obj2.x);
}
}
package helloclass;
public class one {
public int a;
}import java.io.*;
class OutputStream {
public static void main(String[] args) throws IOException {
byte[] data = {'a','b','c','d','e','f','g'};
System.out.write(data,3,4);
//pindah baris
System.out.write('\n');
//tulis semua isi array data
System.out.write(data);
}
}import java.awt.*;
import java.applet.*;
public class oval extends Applet
{
public void paint(Graphics g)
{
g.drawOval(10,5,120,40);
g.fillOval(80,90,120,40);
}
}
/*
4>4>
*/
import java.io.*;
class Overload
{
int print(int a,int b,int c)
{
System.out.println("Method with 3 arguments");
return(a+b+c);
}
int print(int a,int b)
{
System.out.println("Method with 2 arguments from Overload class");
return(a+b);
}
}
class Override extends Overload
{
int print(int a,int b,int c)
{
System.out.println("Method with 3 arguments from Override class");
return(a+b+c);
}
public static void main(String arg[])
{
Override ob=new Override();
ob.print(2,3,4);
ob.print(6,7);
Overload ob1=new Overload();
ob1.print(7,8,9);
}
}
import mypackage.*;
import mypackage.subpackage.*;
class PackageImpl
{
public static void main(String str[])
{
Demo11.demo();
Demo2 d=new Demo2();
d.square(7);
}
}import mypackage.*;
import mypackage.subpackage.*;
class PackageImpl
{
public static void main(String args[])
{
Test.demo();
TestSub ts=new TestSub();
ts.cube(5);
}
}
import java.io.*;
class pal
{
public static void main(String arg[]) throws IOException
{
int i,j,len;
String s;
DataInputStream in=new DataInputStream(System.in);
System.out.print("Enter a string ?");
s=in.readLine();
len=s.length();
for(i=0,j=len-1;i
if(s.charAt(i)!=s.charAt(j))
break;
}
if(i==j)
System.out.println("Pal string");
else
System.out.println("Not a Pal string");
}
}
//to create a panel
import java.awt.*;
public class panel
{
public static void main(String [] s)
{
Frame f=new Frame("FRAME WITH PANEL");
Panel p1=new Panel();
Panel p2=new Panel();
/*
f.setBounds(0,0,300,300);
p1.setBounds(12,81,50,50);
p2.setBounds(162,81,50,50);
*/
f.resize(400,400);
f.setBackground(Color.red);
p1.resize(50,50);
p1.setBackground(new Color(255,255,255));
p2.resize(50,50);
p2.setBackground(new Color(5,5,5));
f.add(p1);
f.add(p2);
f.show();
}
}
import java.awt.*;
public class PanelDemo extends Frame
{
Label l1,l2;
TextField t1,t2; // declaration
Panel p1,p2,mainpanel;
public PanelDemo()
{
l1=new Label("Num");
l2=new Label("Square"); // construction
t1=new TextField(20);
t2=new TextField(20);
p1=new Panel();
p1.add(l1);
p1.add(t1);
p2=new Panel();
p2.add(l2);
p2.add(t2);
mainpanel=new Panel(new GridLayout(5,1));
mainpanel.add(p1);
mainpanel.add(p2);
add(mainpanel); // adding component
setTitle("Text Label demo");
setSize(200,200);
setVisible(true);
}
public static void main(String args[])
{
new PanelDemo();
}
} import java.io.*;
import java.lang.Math;
class pfixevl
{
int top,j,i;
String str;
char t,postfix[];
int s[];
DataInputStream in;
public pfixevl()
{
top=-1;i=0;
postfix=new char[30];
s=new int[30];
in=new DataInputStream(System.in);
}
public void push(int val)
{
top++;
s[top]=val;
}
public int pop()
{
int val;
val=s[top];
top--;
return val;
}
public void evaluate(String str) throws IOException
{
int op1,op2,value=0;
while(i
t=str.charAt(i);
if( (t>='a' && t<='z') || (t>='A' && t<='Z'))
{
System.out.print("Enter value for '"+t+"' ?");
value=Integer.parseInt(in.readLine());
push(value);
}
else
{
switch(t)
{
case '+':
op2=pop();
op1=pop();
value=op1+op2;
push(value);
break;
case '-':
op2=pop();
op1=pop();
value=op1-op2;
push(value);
break;
case '*':
op2=pop();
op1=pop();
value=op1*op2;
push(value);
break;
case '/':
op2=pop();
op1=pop();
value=op1*op2;
push(value);
break;
case '^':
op2=pop();
op1=pop();
value=(int)Math.pow((float)op1,(float)op2);
push(value);
break;
}
}
i++;
}
System.out.println("postfix evaluated val = "+value);
}
public static void main(String args[]) throws IOException
{
String str;
DataInputStream in=new DataInputStream(System.in);
System.out.print("Enter a string?");
str=in.readLine();
(new pfixevl()).evaluate(str);
}
}
abstract class Bentuk {
protected int panjang;
protected int lebar;
public String getBentuk() {
return "Bentuk Dasar";
}
public abstract int hitungLuas();
}
class BujurSangkar extends Bentuk {
public BujurSangkar(int panjang1, int lebar1) {
this.panjang = panjang1;
this.lebar = lebar1;
}
public String getBentuk() {
return "Bentuk Bujur Sangkar";
}
public int hitungLuas() {
return panjang*lebar;
}
}
class SegiTiga extends Bentuk {
public SegiTiga(int panjang2, int lebar2) {
this.panjang = panjang2;
this.lebar = lebar2;
}
//public String getBentuk() {
//return "Bentuk Segi Tiga";
//return "";
//}
public int hitungLuas() {
return this.panjang*this.lebar/2;
}
}
class Polimorfisme {
public static void cetakLuasBentuk(Bentuk btk) {
System.out.println(btk.getBentuk() + " dengan luas " + btk.hitungLuas());
}
public static void main(String[] args) {
BujurSangkar bs = new BujurSangkar(10,20);
BujurSangkar bs1 = new BujurSangkar(10,20);
SegiTiga st = new SegiTiga(5,10);
SegiTiga st1 = new SegiTiga(50,100);
cetakLuasBentuk(bs);
cetakLuasBentuk(bs1);
cetakLuasBentuk(st);
cetakLuasBentuk(st1);
}
}import java.io.*;
import java.io.*;
class prime
{
public static void main(String[] args) throws IOException
{
String s;
int no,i,j;
DataInputStream in=new DataInputStream(System.in);
System.out.print("Enter a value?");
s=in.readLine();
no=Integer.parseInt(s);
for(i=no;i>=1;i--)
{
for(j=2;j {
if(i%j==0)
break;
}
if(i==j)
System.out.println(i+" is a prime no..");
}
}
}
import java.io.*;
class PrintWriterDemo
{
public static void main(String s[])
{
PrintWriter pw=new PrintWriter(System.out);
pw.println("Hello");
pw.println("Deepak");
}
}
import java.io.*;
class PrintWriterDemo1
{
public static void main(String s[])
{
try
{
FileWriter fw=new FileWriter("d:/Rahul/priyam.txt",true);
PrintWriter pw=new PrintWriter(fw);
pw.println("Hello");
pw.println("Deepak");
System.out.println("Writing is over");
pw.flush();
}
catch(Exception e)
{
}
}
}
import java.io.*;
class Consumer extends Thread
{
private CubbyHole cubbyhole;
private int number;
public Consumer(CubbyHole c,int number)
{
cubbyhole=c;
this.number=number;
}
public void run()
{
int value=0;
for(int i=0;i<10 i="" p=""> {
value=cubbyhole.get();
System.out.println("Consumer #" + this.number +"Got:" +value);
}
}
}
class Producer extends Thread
{
private CubbyHole cubbyhole;
private int number;
public Producer(CubbyHole c, int number)
{
cubbyhole=c;
this.number=number;
}
public void run()
{
for(int i=10;i<20 i="" p=""> {
cubbyhole.put(i);
try
{
sleep(100);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
System.out.println("Consumer #"+this.number+"put:" +i);
}
}
}
class CubbyHole
{
private int contents;
private boolean available=false;
public synchronized int get()
{
while(available==false)
{
try
{
wait();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
available=false;
notifyAll();
return contents;
}
public synchronized void put(int value)
{
while(available==true)
{
try
{
wait();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
available=true;
contents=value;
notifyAll();
}
}
public class ProducerConsumer
{
public static void main(String arg[])
{
CubbyHole c=new CubbyHole();
Producer p1= new Producer(c,2);
Consumer c1=new Consumer(c,1);
p1.start();
c1.start();
}
}
import java.io.*;
class Pwsdemo
{
public static void main(String args[])
{
PrintWriter p=new PrintWriter(System.out);
int i=10;
p.println("Hello!"+ i);
p.print(i);
p.print(i);
p.println(i);
p.println(i);
p.flush();
}
}//importing io classes
import java.io.*;
//importing Math class
import java.lang.Math;
class qd_eq
{
public static void main(String[] args) throws IOException
static
{
String s;
int a,b,c,d;
double r1,r2;
DataInputStream in=new DataInputStream(System.in);
System.out.print("Enter a value?");
s=in.readLine();
a=Integer.parseInt(s);
System.out.print("Enter b value?");
s=in.readLine();
b=Integer.parseInt(s);
System.out.print("Enter c value?");
s=in.readLine();
c=Integer.parseInt(s);
d=((b*b)-(4*a*c));
if(d<0 p=""> {
System.err.println("No real solution...");
}
else
{
r1=((-b)+Math.sqrt(d))/(2*a);
r2=((-b)-Math.sqrt(d))/(2*a);
System.out.println("Root 1 = "+r1);
System.out.println("Root 2 = "+r2);
}
//System.exit(0);
}
}
//reading file data line by line...
import java.io.*;
class readfile
{
public static void main(String args[])
{
char ch;
StringBuffer s=new StringBuffer();
String fname=null;
int ctr=1;
try
{
System.out.println("Enter a filoe name?");
while((ch=(char)System.in.read())!='\n')
{
s.append(ch);
}
fname=s.toString().trim();
//opening Random Access file
RandomAccessFile r=new RandomAccessFile("readfile.java","rw");
while(r.getFilePointer()
System.out.print(ctr+"\t");
System.out.println(r.readLine());
}
r.close();
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
import java.awt.*;
import java.applet.*;
public class rect extends Applet
{
public void paint(Graphics g)
{
g.drawRect(10,5,120,40);
g.fillRect(80,90,120,40);
}
}
/*
*/
class Relasi{
public static void main(String[] args) {
int x,y,z;
x = 100;
y = 99;
z = 99;
System.out.println("Nilai x = "+x);
System.out.println("Nilai y = "+y);
System.out.println("Nilai z = "+z);
// operator sama dengan
if(y == z ){
System.out.println("y sama dengan z");
}else {
System.out.println("y tidak sama dengan z");
}
// operator tidak sama dengan
if(x != y ){
System.out.println("x tidak sama dengan y");
}else {
System.out.println("x sama dengan y");
}
// operator lebih besar dari
if(x > y ){
System.out.println("x lebih besar dari y");
}else {
System.out.println("x lebih kecil dari y");
}
// operator lebih kecil dari
if(y < x ){
System.out.println("y lebih kecil dari x");
}else {
System.out.println("y lebih besar dari x");
}
// operator lebih besar dari atau sama dengan
if(x >= y ){
System.out.println("x lebih besar dari atau sama dengan y");
}else {
System.out.println("x lebih kecil dari atau sama dengany");
}
// operator lebih kecil dari atau sama dengan
if(y <= x ){
System.out.println("y lebih kecil dari atau sama dengan x");
}else {
System.out.println("y lebih besar dari atau sama dengan x");
}
}
}/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package filters;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.Timestamp;
import java.util.Enumeration;
import java.util.Locale;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
/**
* Example filter that dumps interesting state information about a request
* to the associated servlet context log file, before allowing the servlet
* to process the request in the usual way. This can be installed as needed
* to assist in debugging problems.
*
* @author Craig McClanahan
* @version $Revision$ $Date$
*/
public final class RequestDumperFilter implements Filter {
// ----------------------------------------------------- Instance Variables
/**
* The filter configuration object we are associated with. If this value
* is null, this filter instance is not currently configured.
*/
private FilterConfig filterConfig = null;
// --------------------------------------------------------- Public Methods
/**
* Take this filter out of service.
*/
public void destroy() {
this.filterConfig = null;
}
/**
* Time the processing that is performed by all subsequent filters in the
* current filter stack, including the ultimately invoked servlet.
*
* @param request The servlet request we are processing
* @param result The servlet response we are creating
* @param chain The filter chain we are processing
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
if (filterConfig == null)
return;
// Render the generic servlet request properties
StringWriter sw = new StringWriter();
PrintWriter writer = new PrintWriter(sw);
writer.println("Request Received at " +
(new Timestamp(System.currentTimeMillis())));
writer.println(" characterEncoding=" + request.getCharacterEncoding());
writer.println(" contentLength=" + request.getContentLength());
writer.println(" contentType=" + request.getContentType());
writer.println(" locale=" + request.getLocale());
writer.print(" locales=");
Enumeration locales = request.getLocales();
boolean first = true;
while (locales.hasMoreElements()) {
Locale locale = (Locale) locales.nextElement();
if (first)
first = false;
else
writer.print(", ");
writer.print(locale.toString());
}
writer.println();
Enumeration names = request.getParameterNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
writer.print(" parameter=" + name + "=");
String values[] = request.getParameterValues(name);
for (int i = 0; i < values.length; i++) {
if (i > 0)
writer.print(", ");
writer.print(values[i]);
}
writer.println();
}
writer.println(" protocol=" + request.getProtocol());
writer.println(" remoteAddr=" + request.getRemoteAddr());
writer.println(" remoteHost=" + request.getRemoteHost());
writer.println(" scheme=" + request.getScheme());
writer.println(" serverName=" + request.getServerName());
writer.println(" serverPort=" + request.getServerPort());
writer.println(" isSecure=" + request.isSecure());
// Render the HTTP servlet request properties
if (request instanceof HttpServletRequest) {
writer.println("---------------------------------------------");
HttpServletRequest hrequest = (HttpServletRequest) request;
writer.println(" contextPath=" + hrequest.getContextPath());
Cookie cookies[] = hrequest.getCookies();
if (cookies == null)
cookies = new Cookie[0];
for (int i = 0; i < cookies.length; i++) {
writer.println(" cookie=" + cookies[i].getName() +
"=" + cookies[i].getValue());
}
names = hrequest.getHeaderNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
String value = hrequest.getHeader(name);
writer.println(" header=" + name + "=" + value);
}
writer.println(" method=" + hrequest.getMethod());
writer.println(" pathInfo=" + hrequest.getPathInfo());
writer.println(" queryString=" + hrequest.getQueryString());
writer.println(" remoteUser=" + hrequest.getRemoteUser());
writer.println("requestedSessionId=" +
hrequest.getRequestedSessionId());
writer.println(" requestURI=" + hrequest.getRequestURI());
writer.println(" servletPath=" + hrequest.getServletPath());
}
writer.println("=============================================");
// Log the resulting string
writer.flush();
filterConfig.getServletContext().log(sw.getBuffer().toString());
// Pass control on to the next filter
chain.doFilter(request, response);
}
/**
* Place this filter into service.
*
* @param filterConfig The filter configuration object
*/
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
}
/**
* Return a String representation of this object.
*/
public String toString() {
if (filterConfig == null)
return ("RequestDumperFilter()");
StringBuffer sb = new StringBuffer("RequestDumperFilter(");
sb.append(filterConfig);
sb.append(")");
return (sb.toString());
}
}
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* $Id$
*
*/
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import util.HTMLFilter;
/**
* Example servlet showing request headers
*
* @author James Duncan Davidson
*/
public class RequestHeaderExample extends HttpServlet {
ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("");
out.println("");
String title = rb.getString("requestheader.title");
out.println("
out.println("
"); out.println("");
// all links relative
// XXX
// making these absolute till we work out the
// addition of a PathInfo issue
out.println("");
out.println(" "width=24 align=right border=0 alt=\"view code\">
"); out.println("");
out.println(" "width=24 align=right border=0 alt=\"return\">
");
out.println("
" + title + "
");out.println("
Enumeration e = request.getHeaderNames();
while (e.hasMoreElements()) {
String headerName = (String)e.nextElement();
String headerValue = request.getHeader(headerName);
out.println("
out.println(HTMLFilter.filter(headerName));
out.println("
out.println("
"); }
out.println("
"); }
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
}
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* $Id$
*
*/
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import util.HTMLFilter;
/**
* Example servlet showing request information.
*
* @author James Duncan Davidson
*/
public class RequestInfoExample extends HttpServlet {
ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("");
out.println("");
String title = rb.getString("requestinfo.title");
out.println("
out.println("
"); out.println("");
// img stuff not req'd for source code html showing
// all links relative!
// XXX
// making these absolute till we work out the
// addition of a PathInfo issue
out.println("");
out.println(" "width=24 align=right border=0 alt=\"view code\">
"); out.println("");
out.println(" "width=24 align=right border=0 alt=\"return\">
");
out.println("
" + title + "
");out.println("
"); |
out.println(rb.getString("requestinfo.label.method"));
out.println("
out.println("
out.println("
out.println("
out.println("
out.println("
out.println("
out.println("
String cipherSuite=
(String)request.getAttribute("javax.servlet.request.cipher_suite");
out.println("
out.println("
");
if(cipherSuite!=null){
out.println("
out.println("
"); out.println("
out.println(request.getAttribute("javax.servlet.request.cipher_suite"));
out.println("
"); }
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
}
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* $Id$
*
*/
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import util.HTMLFilter;
/**
* Example servlet showing request headers
*
* @author James Duncan Davidson
*/
public class RequestParamExample extends HttpServlet {
ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("");
out.println("");
String title = rb.getString("requestparams.title");
out.println("
out.println("
"); out.println("");
// img stuff not req'd for source code html showing
// all links relative
// XXX
// making these absolute till we work out the
// addition of a PathInfo issue
out.println("");
out.println(" "width=24 align=right border=0 alt=\"view code\">
"); out.println("");
out.println(" "width=24 align=right border=0 alt=\"return\">
");
out.println("
" + title + "
");String firstName = request.getParameter("firstname");
String lastName = request.getParameter("lastname");
out.println(rb.getString("requestparams.params-in-req") + "
");
if (firstName != null || lastName != null) {
out.println(rb.getString("requestparams.firstname"));
out.println(" = " + HTMLFilter.filter(firstName) + "
");
out.println(rb.getString("requestparams.lastname"));
out.println(" = " + HTMLFilter.filter(lastName));
} else {
out.println(rb.getString("requestparams.no-params"));
}
out.println("");
out.print("");
out.println("
"); out.println("
"); }
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
}
class RunnableDemo implements Runnable
{
Thread th;
RunnableDemo()
{
th=new Thread(this,"ChildThread");
th=new Thread(this,nm);
th.start();
th.setPriority(p);
System.out.println("Child Thread Started Here");
}
public void run()
{
for(int i=0;i<4 i="" p=""> {
System.out.println("Inside Child Thread i="+i);
try{
th.sleep(1000);
}catch(InterruptedException e)
{
System.out.println("Child Thread Interruptde");
}
}
System.out.println(th.getName()+" Thread Over Here");
}
public static void main(String arg[])
{
System.out.println("Main Thread Started Here");
MyThread obj1=new MyThread(" One",3);
MyThread obj2=new MyThread(" Two",5);
MyThread obj3=new MyThread(" Yhree",3);
RunnableDemo rd=new RunnableDemo();
for(int i=0;i<4 i="" p=""> {
System.out.println("Inside Main Thread i="+i);
try{
Thread.sleep(1000);
}catch(InterruptedException e)
{
System.out.println("Main Thread Interruptde");
}
}
System.out.println("Main Thread Over Here");
}
}
class RunnableDemo1 extends Thread
{
Thread th;
RunnableDemo1()
{
super("Child Thread");
start();
System.out.println("Child Thread Started Here");
}
public void run()
{
for(int i=0;i<4 i="" p=""> {
System.out.println("Inside Child Thread i="+i);
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
System.out.println("Child Thread Interruptde");
}
}
System.out.println("Child Thread Over Here");
}
public static void main(String arg[])
{
System.out.println("Main Thread Started Here");
RunnableDemo1 rd=new RunnableDemo1();
for(int i=0;i<4 i="" p=""> {
System.out.println("Inside Main Thread i="+i);
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
System.out.println("Main Thread Interruptde");
}
}
System.out.println("Main Thread Over Here");
}
}
class RunnableDemo2 extends Thread
{
Thread th;
RunnableDemo2(String nm,int p)
{
super(nm);
start();
System.out.println(getName()+"Thread Started Here");
setPriority(p);
}
public void run()
{
for(int i=0;i<4 i="" p=""> {
System.out.println("Inside"+getName()+" i="+i);
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
System.out.println("Child Thread Interrupted");
}
}
System.out.println(getName()+"Thread Over Here");
}
public static void main(String arg[])
{
System.out.println("Main Thread Started Here");
RunnableDemo2 obj1=new RunnableDemo2("One",3);
RunnableDemo2 obj2=new RunnableDemo2("Two",5);
RunnableDemo2 obj3=new RunnableDemo2("Three",7);
//RunnableDemo2 rd=new RunnableDemo2();
for(int i=0;i<4 i="" p=""> {
System.out.println("Inside Main Thread i="+i);
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
System.out.println("Main Thread Interruptde");
}
}
System.out.println("Main Thread Over Here");
}
}
import java.sql.*;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.event.*;
import java.util.*;
public class SalsClient extends JFrame implements ActionListener
{
static SalsRemote obj;
Connection con;
ResultSet rs;
Statement st;
ResultSetMetaData rsmd;
JLabel l1,l2;
JTable jtab;
JScrollPane jsp;
JTextField t1;
JButton b_execute;
JPanel p1,p2,mp;
Vector head,row,data;
public SalsClient()
{
l1=new JLabel("SQL");
l2=new JLabel("Details are");
t1=new JTextField(20);
b_execute=new JButton("Execute");
b_execute.addActionListener(this);
p1=new JPanel();
jtab=new JTable();
int vsp=ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
int hsp=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
jsp=new JScrollPane(jtab,vsp,hsp);
p1.add(l1);
p1.add(t1);
p1.add(b_execute);
p2=new JPanel();
p2.add(l2);
p2.add(jsp);
mp=new JPanel();
Container ct=getContentPane();
ct.add(p1,BorderLayout.NORTH);
ct.add(p2,BorderLayout.CENTER);
setTitle("Demo");
setSize(550,400);
setVisible(true);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:abc","scott","tiger");
JOptionPane.showMessageDialog(this,"Database Connected");
}catch(Exception e)
{
JOptionPane.showMessageDialog(this,"Error in connection"+e);
}
}
public Vector displayData(String query)
{
try{
st=con.createStatement();
rs=st.executeQuery(query);
rsmd=rs.getMetaData();
int cols=rsmd.getColumnCount();
head=new Vector();
for(int i=1;i<=cols;i++)
{
head.add(rsmd.getColumnName(i));
}
data=new Vector();
data.add(head);
while(rs.next())
{
row=new Vector();
for(int i=1;i<=cols;i++)
{
row.add(rs.getString(i));
}
data.add(row);
}
No comments:
Post a Comment