DOWNLOAD

Get our toolbar!

Saturday, 30 April 2011

// write a program of JDBC ODBC connectivity through ms access which prints the record one by one.

CODEimport java.sql.*;class Database{public static void main(String args[])throwsException{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection con=DriverManager.getConnection("jdbc:odbc:nitin");Statement st=con.createStatement();ResultSet res=st.executeQuery("select * from Student");while(res.next()){System.out.println(res.getInt(1)+" "+res.getString(2)+" "+res.getString(3)+" "+res.getString(4));}}}OUTPUT DISPLAY...

// write a program in java which concatenate two string.

CODEimport java.io.*;public class CombinString{public static void main(String[] args) throws IOException{BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));System.out.println("Enter First String:");String str1 = bf.readLine();System.out.println("Enter Second String:");String str2 = bf.readLine();System.out.println("CONCATINATE TWO STRING!");String com = str1.concat(str2);System.out.println("CONCATINATE STRING: " + com);}}OUTPUT...

// write a program in java which finds the index of a particular character the string.

CODEimport java.io.*;import java.awt.*;public class StringIndex{public static void main(String args[]){String s = "Welcome to BCA";System.out.println(s);System.out.println("INDEX OF 'B' IN THE STRING IS=" + s.indexOf("BCA"));}OUTPUT DISP...

// write a program which counts the length of the string.

CODEimport java.lang.*; import java.io.*;public class StringLength{public static void main(String[] args) throws IOException{System.out.println("String lenght example!");BufferedReader bf = new BufferedReader(newInputStreamReader(System.in));System.out.println("Please enter string:");String str = bf.readLine();int len = str.length();System.out.println("String lenght : " + len);}}OUTPUT DISP...

// write a program in java which initialize the object of class through parameterized constructor.

CODEclass a{a( ){System.out.println("In a\'s Contructor...");}}class b extends a{b(String s){System.out.println("In b\'s constructor...");System.out.println(s);}}public class par{public static void main(String [ ]args){b obj=new b("Hello from java!");}}OUTPUT DISP...

// write a program in java which converts a lower case to upper case string.

CODE import java.io.*;import java.lang.*;class UpperCase{public static void main(String args[ ]) throws IOException{BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));System.out.print("Enter the lowercase character : ");String s = buff.readLine();System.out.println("Upper case of "+s +" is "+s.toUpperCase());}}OUTPUT DISP...

// write a program in java to compare two strings whether equal or not.

CODEimport java.lang.*;import java.io.*;public class CompString{public static void main(String[] args) throws IOException{System.out.println("String equals or not example!");BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));System.out.println("Please enter first string:");String str1 = bf.readLine();System.out.println("Please enter second string:");String str2 = bf.readLine();if (str1.equals(str2)){System.out.println("The given...

// write a program to handle divide by zero exception.

CODEclass Dividebyzero{public static void main(String s[]){int a =10;int b =5;int c =5;int x;try{x =a/(b-c);}catch(ArithmeticException e){System.out.println("divisle by zero"+e);}}}OUTPUT DISP...

// write a program in java using buffer reader to read the name entered through keyboard by the user.

CODEimport java.io.*;public class Hi{public static void main(String[] args) throws IOException{InputStreamReader reader = new InputStreamReader(System.in);BufferedReader input = new BufferedReader(reader);System.out.print("Enter your name: ");String name = input.readLine();System.out.println("Hi," + name + "!");}}OUTPUT DISP...

// program in java using awt control label and button to select a value of label.

CODEimport java.applet.*;import java.awt.*;import java.awt.event.*;public class value extends Applet implements ActionListener{Label l1;Button b1;public void init( ){l1= new Label("Hello");add(l1);b1= new Button("Show");add(b1);b1.addActionListener (this);}public void actionPerformed(ActionEvent e){if(e.getSource()==b1){String s=l1.getText();System.out.println(s);}}}HTML CODE<HTML><BODY><APPLET ALIGN="CENTER" CODE="AppletSum.class"...

// write a program in java using buffer reader to read the name entered through keyboard by the user.

CODEimport java.io.*;public class Hi{public static void main(String[] args) throws IOException{InputStreamReader reader = new InputStreamReader(System.in);BufferedReader input = new BufferedReader(reader);System.out.print("Enter your name: ");String name = input.readLine();System.out.println("Hi," + name + "!");}}OUTPUT DISP...

// write a program in java using awt control label and button to select a value of label.

CODEimport java.applet.*;import java.awt.*;import java.awt.event.*;public class value extends Applet implements ActionListener{Label l1;Button b1;public void init( ){l1= new Label("Hello");add(l1);b1= new Button("Show");add(b1);b1.addActionListener (this);}public void actionPerformed(ActionEvent e){if(e.getSource()==b1){String s=l1.getText();System.out.println(s);}}}HTML CODE<HTML><BODY><APPLET ALIGN="CENTER" CODE="AppletSum.class"...

// program in java using awt control label and text field in which user inputs the value to the text field.

CODEimport java.applet.Applet;import java.awt.Button;import java.awt.TextField;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class AnonymouseButton extends Applet {TextField txtSource;Button btnToLOwer;public void init(){txtSource=new TextField(20);btnToLOwer=new Button("Lower Case");btnToLOwer.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {String tmp=txtSource.getText();tmp=tmp.toLowerCase();txtSource.setText(tmp);}});add(txtSource);add(btnToLOwer);}}HTML...

// Write a program in java in which derived class uses attributes of base class.

CODEclass Overload{public void test(int a) {System.out.println("a: " + a);}void test(int a, int b) {System.out.println("a and b: " + a + "," + b);}double test(double a) {System.out.println("double a: " + a);return a*a; }}class Over extends Overload {void test(int a, int b) {System.out.println("a and b: " + a + "," + b); }}class MethodOverloading {public static void main(String args[]) {Over overload = new Over();double result;overload.test(10);overload.test(10,...

// write a program in java in which two threads are prioritized.

CODEclass MyThread1 extends Thread{MyThread1(String s){super(s);start();}public void run(){for(int i=0;i<3;i++){Thread cur=Thread.currentThread();cur.setPriority(Thread.MIN_PRIORITY);int p=cur.getPriority();System.out.println("Thread Name  :"+Thread.currentThread().getName());System.out.println("Thread Priority  :"+cur);}}}class MyThread2 extends Thread{MyThread2(String s){super(s);start();}public void run(){for(int i=0;i<3;i++){Thread...

Twitter Delicious Facebook Digg Stumbleupon Favorites More