Java
[Link] Babu
Basic Java
Exception
Thread
Serialization
AWT
Applet
Swing
Collection
Advance Java
RMI
CORBA
Java Media Framework
JMS
Java Introduction
Class
Object
Java Virtual Machine
Constructor
OOP Concepts
Eclipse IDE
Exception
Introduction
Try Catch
Multiple Try Catch
Try Catch Finally
throws
throw - User Defined Exceptions
Exception
Introduction
Try Catch
Multiple Try Catch
Try Catch Finally
throws
throw - User Defined Exceptions
Exception Try - Catch
public class ExceptionSample {
public static void main(String args[])
{
try {
} catch (Exception e) {
// Handle Exception
}finally
{
[Link]("Final Block");
}
}
}
Exception User Defined
class MyException extends Exception
{
String name;
public MyException(String str)
{
name= str;
}
public String toString()
{
return "My Exception Demo";
}
}
Exception throws
public class ExceptionSample {
public static void main(String args[]) throws Exception
{
}
}
Thread
Introduction
Multithreading
Implementing Runnable Interface
Extending Thread Class
Suspend Resume
wait notify - notifyAll
Thread Life Cycle
Thread Runnable Interface
public class RunnableSample implements Runnable
{
Thread t;
public RunnableSample() {
t= new Thread(this,"Example Thread");
[Link]();
[Link]("Child thread");
}
public void run() {
try {
for (int j = 0; j < 10; j++) {
[Link](j);
[Link](100);
}
} catch (Exception e) {
[Link]("error"+e);
}
}
}
Thread extending Thread
public class ThreadSample extends Thread
{
Thread t;
public RunnableSample() {
t= new Thread("Example Thread");
start();
[Link]("Child thread");
}
public void run() {
try {
for (int j = 0; j < 10; j++) {
[Link](j);
[Link](100);
}
} catch (Exception e) {
[Link]("error"+e);
}
}
}
Thread Control
Suspend
Resume
Wait
Notify
Notify All
Serialization
Introduction
Object Serialization
Demo
Serialization - Program
class MyClass implements Serializable {
String s;
int i;
double d;
public MyClass(String s, int i, double d) {
this.s = s;
this.i = i;
this.d = d;
}
public String toString() {
return "s=" + s + "; i=" + i + "; d=" + d;
}
}
AWT
Introduction
GUI concepts
Containers
Layout Managers
Controls
Events
AWT
Frame
Flowlayout,BorderLayout,GridLayout
TextField
Button
CheckBox
Choice
List
TextArea
Label
Listeners ActionListener, WindowListener
etc
Applet
Introduction
LifeCycle
Init,start,stop,paint,destroy
Running Applet Programs
Appletviewer
Applet - Program
import
import
[Link].*;
[Link].*;
public class RectangleApplet extends Applet {
public void paint(Graphics g) {
[Link](0, 0, 100, 100);
}
}
Swing
Introduction
Difference Between AWT & Applet
Heavy Weight Light Weight
Content Pane
UIManager
Swing Components
Java Collection
Introduction
Lists
store objects in a specific order
Sets
Reject duplicates of any objects already in the collection
Maps
store objects in association with a key, which is later used to
look up and retrieve the object (note that if an item with a
duplicate key is put into a map, the new item will replace the
old item)
Java Collection Tree
Collection
MAP
SORTED MAP
LIST
ArrayList,
Vector
SET
Hash Set,
TreeSet
TreeMap,Hash
Map,HashTable
Java Collection Examples
import [Link].*;
public class ArrayListSample {
public static void main(String args[]) {
List list = new ArrayList();
[Link]("one");
[Link]("two");
[Link]("three");
[Link]("four");
[Link]("five");
[Link](list);
}
}
Java Collection Examples
import [Link];
import [Link];
public class SetExample {
public static void main(String args[]) {
}
}
Set set = new HashSet();
[Link]("One");
[Link]("Two");
[Link]("Three");
[Link]("Four");
[Link]("Five");
[Link](set);
Set sortedSet = new TreeSet(set);
[Link](sortedSet);
Java Collection <k,v>
Hashtable ht = new Hashtable();
[Link]("1","one");
[Link]("2","two");
[Link]("3","three");
[Link]("4","four");
[Link]([Link]("4"));
Advance Java
RMI
CORBA
Java Media Framework
JMS
Remote Method Invocation
Introduction
Server Program
Client Program
Interface
Rmic compiler
rmiregistry
executing RMI Programs
RMI Server Program
import
import
import
[Link];
[Link];
[Link];
publicclass AddServer extends UnicastRemoteObject implements AddServerInterface
{
public AddServer()throws RemoteException
{}
public double add(double d1,double d2)throws RemoteException
{
return(d1+d2);
}
public static void main(String ar[])
{
try
{
AddServer addser = new AddServer();
[Link]("AddServer",addser);
}
catch(Exception e)
{
[Link]("Exce caught"+e);
}
}
}
RMI Client Program
import [Link];
public class AddClient
{
public static void main(String ar[])
{
try
{
String url="rmi://localhost/AddServer";
AddServerInterface ob=(AddServerInterface)[Link](url);
[Link]("RMI started working..");
[Link]("Sum of two numbers"+[Link](12,90));
}
catch(Exception e)
{ [Link]("This is "+e); }
}
}
RMI Interface
import [Link];
import [Link];
interface AddServerInterface extends Remote
{
double add(double d1,double d2)throws
RemoteException;
}
CORBA
Introduction
Architecture
CORBA - Demo
CORBA - IDL Program
module HelloApp
{
interface Hello
{
string sayHello();
oneway void shutdown();
};
};
CORBA Server Program
class HelloImpl extends HelloPOA
{
private ORB orb;
public void setORB(ORB orb_val) { orb=orb_val; }
public String sayHello() { return "\nHello world!!\n"; }
public void shutdown()
{ [Link](false); }
}
public class HelloServer {
public static void main(String args[]) {
try {
ORB orb=[Link](args,null);
POA rootpoa=[Link](orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
HelloImpl helloImpl=new HelloImpl();
[Link](orb);
[Link] ref=rootpoa. servant_to_reference(helloImpl);
Hello href=[Link](ref);
[Link] objRef=orb.resolve_initial_references("NameService");
NamingContextExt ncRef=[Link](objRef);
String name="hello";
NameComponent path[]=ncRef.to_name(name);
[Link](path,href);
[Link]("server ready and waiting");
[Link]();
}
catch(Exception e) { [Link]("ERRROR:"+e); [Link](System. out); }
[Link]("server exiting");
}}
CORBA Client Program
public class HelloClient
{
static Hello helloImpl;
public static void main(String args[]) {
try
{
ORB orb=[Link](args,null);
[Link]
objRef=orb.resolve_initial_references("NameService");
NamingContextExt ncRef=[Link](objRef);
String name="hello";
helloImpl=[Link](ncRef.resolve_str(name));
[Link]("Obtained a handle on server
object:"+helloImpl);
[Link]([Link]());
[Link]();
}catch(Exception e)
{
[Link]("ERROR:"+e);
[Link]([Link]);
}
}
Java Media Framework
Introduction
Demo
JMF - Program
public class MediaPanel extends JPanel
{
public MediaPanel( URL mediaURL )
{
setLayout( new BorderLayout() ); // use a BorderLayout
// Use lightweight components for Swing compatibility
[Link]
[Link](( Manager.LIGHTWEIGHT_RENDERER
Manager.LIGHTWEIGHT_RENDERER,, true );
try
{
// create a player to play the media specified in the URL
Player mediaPlayer = [Link]
[Link](( mediaURL );
// get the components for the video and the playback controls
Component video = [Link]();
Component controls = [Link]();
if ( video != null )
add( video, [Link]
[Link] ); // add video component
if ( controls != null )
add( controls, [Link]
[Link] ); // add controls
[Link](); // start playing the media clip
} // end try
catch ( NoPlayerException noPlayerException )
{
[Link]
.println( "No media player found" );
[Link](
} // end catch
catch ( CannotRealizeException cannotRealizeException )
[Link]
.println( "Could not realize media player" );
[Link](
} // end catch
catch ( IOException iOException )
[Link]
.println( "Error reading from the source" );
[Link](
} // end catch
} // end MediaPanel constructor
} // end class MediaPanel
JMF - Program
public class MediaTest
{
// launch the application
public static void main( String args[] )
{
// create a file chooser
JFileChooser fileChooser = new JFileChooser();
// show open file dialog
int result = [Link]( null );
if ( result == JFileChooser.APPROVE_OPTION
JFileChooser.APPROVE_OPTION ) // user chose a file
{
URL mediaURL = null;
null;
try
{
// get the file as URL
mediaURL = [Link]().toURL()
;
[Link]().toURL();
} // end try
catch ( MalformedURLException malformedURLException )
{
[Link]
.println( "Could not create URL for the file" );
[Link](
} // end catch
if ( mediaURL != null ) // only display if there is a valid URL
{
JFrame mediaTest = new JFrame( "Media Tester" );
[Link]( JFrame.EXIT_ON_CLOSE
JFrame.EXIT_ON_CLOSE );
MediaPanel mediaPanel = new MediaPanel( mediaURL );
[Link]( mediaPanel );
[Link]( 300, 300 );
[Link]( true );
} // end inner if
} // end outer if
} // end main
} // end class MediaTest
Java Messaging Service
Introduction
point to-point JMS
Queue JMS
Thank You