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.


CODE

import java.sql.*;
class Database
{
public static void main(String args[])throws
Exception
{
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.


CODE

import 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 DISPLAY






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


CODE

import 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 DISPLAY







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

CODE



import 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(new
InputStreamReader(System.in));
System.out.println("Please enter string:");
String str = bf.readLine();
int len = str.length();
System.out.println("String lenght : " + len);
}
}


OUTPUT DISPLAY



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

CODE


class 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 DISPLAY



// 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 DISPLAY


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

CODE



import 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 string is equals");
}
else
{
System.out.println("The given string is not equals");
}
}
}

OUT[UT DISPLAY


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


CODE

class 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 DISPLAY


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


CODE
import 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 DISPLAY





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


CODE

import 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" width = "700" height = "400"></APPLET>
</BODY>
</HTML>

OUTPUT DISPLAY



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

CODE



import 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 DISPLAY


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

CODE

import 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" width = "700" height = "400"></APPLET>
</BODY>
</HTML>

OUTPUT DISPLAY


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


CODE

import 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 CODE

<HTML>
<BODY>
<APPLET ALIGN="CENTER" CODE=" AnonymouseButton.java" width = "700" height = "400"></APPLET>
</BODY>
</HTML>

OUTPUT DISPLAY




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


CODE

class 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, 20);
result = overload.test(5.5);
System.out.println("Result : " + result);
}
}

OUTPUT DISPLAY


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


CODE

class 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 cur=Thread.currentThread();
cur.setPriority(Thread.MAX_PRIORITY);
int p=cur.getPriority();
System.out.println("Thread Name  :"+Thread.currentThread().getName());
System.out.println("Thread Priority  :"+cur);
}
}
}
public class ThreadPriority{
public static void main(String args[]){
MyThread1 m1=new MyThread1("My Thread 1");
MyThread2 m2=new MyThread2("My Thread 2");
}
}

OUTPUT DISPLAY







Twitter Delicious Facebook Digg Stumbleupon Favorites More