Sunday, January 6, 2008

Java Example Event Programming

Infterface Program


interface callback
{
void callback(int param);
}
class imp2 implements callback
{
public void callback(int p)
{
System.out.println("callback called with " + p);
}
}
class imp1
{
public static void main(String a[])
{
callback c = new imp2();
c.callback(42);
}
}
class imp3 implements callback
{
public void callback(int t)
{
System.out.println("Interface");
}
public static void main(String a[])
{
imp3 i = new imp3();
i.callback(6);
}
}
class int1 implements inter
{
public void m()
{
}
}
public interface inter
{
public void m();
}
import java.io.*;
class read
{
public static void main(String a[]) throws IOException
{
char c;
InputStreamReader i = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
c = (char) br.read();
System.out.println(c);
c = (char) i.read();
System.out.println(c);
}
}
import java.io.*;
class read1
{
public static void main(String a[]) throws IOException
{
char c;
String s;
InputStreamReader i = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("press chars");
do
{
s = br.readLine();
System.out.println(s);
}while(!s.equals("stop"));
System.out.println("press chars");
do
{
// s = i.readLine();
System.out.println(s);
} while(!s.equals("stop"));
}
}
import java.io.*;
class fileread
{
public static void main(String a[]) throws IOException
{
int i;
FileInputStream fin;
try{
fin = new FileInputStream(a[0]);
}
catch(FileNotFoundException e)
{
System.out.println("File not found");
return ;
}
do
{
i = fin.read();
if(i != -1)
System.out.print((char) i);
}
while(i!= -1);
fin.close();
}
}
import java.io.*;
class files
{
public static void main(String arg[])
{
File f = new File ("c.c");
System.out.println("File Name : " + f.getName());
System.out.println(f.getPath());
System.out.println(f.getAbsolutePath());
String s;
s = (f.canRead()? "is readable" : "is writable");
System.out.println(s);
s = (f.isDirectory()? "dir" : "not dir");
System.out.println(s);
s = (f.isFile()? "file" : "not file");
System.out.println(s);
boolean b = f.delete();
}
}
import java.io.*;
class filewrite
{
public static void main(String a[]) throws IOException,FileNotFoundException
{
FileOutputStream fin = new FileOutputStream(a[0]);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// int i = br.read();
String str = br.readLine();
byte[] b = str.getBytes();
fin.write(b);
System.out.print("Stored in the file");
fin.close();
}
}
import java.io.*;
class filewrite
{
public static void main(String a[]) throws IOException,FileNotFoundException
{
FileOutputStream fin = new FileOutputStream(a[0]);
BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
InputStreamReader br2 = new InputStreamReader(System.in));
// int i = br.read();
byte b = br.read();
byte b1 = br2.read();
String str = br.readLine();
// byte[] b = str.getBytes();
fin.write(b);
System.out.print("Stored in the file");
fin.close();
}
}
import java.io.*;
class in
{
public static void main(String arg[]) throws Exception
{
System.out.println("enter a number");
char c =(char) System.in.read();
System.out.println(c);
}
}
import java.io.*;
class pw
{
public static void main(String a[])
{
PrintWriter pw = new PrintWriter(System.out,true);
pw.print("this is the string");
int i=9;
pw.println(i);
double d=34.34;
pw.println(d);
System.out.write('e');
// System.out.write('lle');
System.out.write('\n');
}
}
import java.io.*;
class read
{
public static void main(String a[]) throws IOException,FileNotFoundException
{
int i;
FileInputStream fin = new FileInputStream(a[0]);
do
{
i = fin.read();
if(i != -1)
System.out.print((char) i);
}
while(i!= -1);
fin.close();
}
}
import java.io.*;
class reader
{
public static void main(String a[]) throws IOException
{
char c;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter characters . q to quit");
do
{
c = (char) br.read();
System.out.println(c);
}while(c!= 'q');
}
}
import java.io.*;
class reader1
{
public static void main(String a[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter 'stop' to quit");
do
{
str = br.readLine();
System.out.println(str);
}while(!str.equals("stop"));
}
}
class str
{
public static void main(String a[])
{
StringBuffer s1 = new StringBuffer();
StringBuffer s2 = new StringBuffer(12);
StringBuffer s3 = new StringBuffer("palani");
System.out.println(s1.length() +" "+ s2.length() +" " + s3.length());
String s4 ="kumar" ;
String s5 = s4;
s2.append("Radiant");
System.out.println(s4.toUpperCase());
System.out.println(s1.length() +" "+ s2.length() +" " + s3.length());
System.out.println("substring " + s3.substring(3,3));
s3.append("kumar");
System.out.println(s3);
System.out.println(s2.reverse());
System.out.println(s2.delete(2,2));
}
}

No comments: