Interface Member InnerClass(Inner class type) 'final' modifier User Defined Packages Creating exception class
public interface public class OuterClass{ class BaseClass { package myPackage; public class InvalidAgeException extends
MyInterface { private int OuterField; final voud finalMethod() { public class Sum{ Exception {
void myMethod(); public class InnerClass{ //Method Content public int add(int x,int y) public InvalidAgeException(String str)
} public void InnerMethod() { }} { { super(str); } }
public class MyClass [Link]("Accessing outer class SubClass extends return(x+y); } } It is used as
implements MyInterface{ field from inner class" + OuterField); BaseClass { public class TestCustomException {
@Override }}} //This class can't override Using this in a program static void validate(int age) throws
public void myMethod() { Static Nested Class(Inner class type) finalMethod } import [Link]; InvalidAgeException{
[Link]("Imple public class OuterClass{ 'static' modifier class addoperation if(age<18) {throw new
menting myMethod"); private static int OuterField; Class A { { InvalidAgeException("Age isnt valid to
} public static class StaticNestedClass { Static void staticMethod() psvm(String[] args) { vote"); } else { S.o.p("Welcome"); } }
} public void NestedMethod() { { Sum s = new Sum(); public static void main(String[] args) {
S.o.p("Accessing outer static field //Method content } S.o.p("Sum:"+[Link](3,2)); try{ validate(15); }
from SNC"+ OuterField); } } } } [Link](); }} catch(InvalidAgeException ex){
S.o.p("Exception occured"+ex); } } }
Multithreaded Programs Thread Synchronization Thread Priorities Applets
Extending thread class class PrintTable{ continue from thread synchronization
class TestThread extends Thread public synchronized void printTable(int n){ example import [Link];
{ S.o.p("Table of"+n); import [Link];
public void run() { for(int i=1;i<10;i++){ S.o.p(n*i); public class Main { public class HelloWorldApplet extends
S.o.p("Thread running"); } try{ [Link](500);} public static void main(String[] args) { Applet {
psvm(String[] args) { catch(Exception e){S.o.p(e);}}} PrintTable table = new PrintTable(); public void paint(Graphics g) {
TestThread t1= new class Thread1 extends Thread { Thread1 t1 = new Thread1(table); [Link]("Hello,World!",20,20);
TestThread(); [Link](); } } PrintTable pt; Thread2 t2 = new Thread2(table); }
Implement runable Interface Thread1(PrintTable pt) { }
class TestThread implements [Link]=pt; } [Link](Thread.MIN_PRIORITY); This applet can be used in HTML as:
Runnable { public void run() { [Link](Thread.MAX_PRIORITY); <body>
public void run() { [Link](2); }} [Link](); <applet code ="[Link]"
S.o.p("Thread running");} class Thread2 extends Thread { [Link](); width="40" height="25"> </applet>
psvm(String[] args) { PrintTable pt; } </body>
TestThread t1= new Thread2(PrintTable pt){
TestThread(); [Link]=pt; }
Thread m1 = new Thread(t1); public void run() { [Link](5); } }
[Link](); } }
NO Layout Managers Flow Layout
Grid Layout
GridBag Layout Group Layout Dialog Boxes
import [Link].*;
import [Link].*;
public class GridBagLayoutEx {
GridBagLayoutEx()
{
JFrame f = new JFrame();
JPanel p = new Jpanel(new GridBagLayout());
GridBagConstraints g=new GridBagConstraints
addButton(p,"Button1",gbc,0,0);
addButton(p,"Button2",gbc,1,0);
[Link](panel);
[Link](true);
}
public static void addButton(Jpanel p, String
label, GridBagConstraints g, int x, int y)
{
JButton button = new JButton(label);
[Link]=x; [Link]=y;
[Link](button,g);
}
} psvm (.....)
List Trees Table
Mnemonics Color Chooser Sum of two numbers, action event, mouse events
JMenu menu = new JMenu("My Menu"); JColorChooser cc = new JColorChooser(); public class example implements ActionListener {
[Link]('M'); JPanel p = new JPanel(); ------
Color c = [Link](this,"select [Link](this);
Accelerators color",[Link]); }
JMenuItem i1=new JMenuItem("Item 1"); [Link](c); public void actionPerformed(ActionEvent e)
[Link]([Link](keyEvent.VK_C,key [Link](p); {
Event.SHIFT_MASK)); if([Link] ==b1){
[Link](i1); int n1= [Link]([Link]());
Internal Frames (iframes) [Link]([Link](sum));
ToolBar with BorderLayout JDesktopPane dp = nee JDesktopPane();
JToolbar t1 = new JToolbar(); JInternalFrame jif= new JInternalFrame(); For Mouse events
[Link](true); JTextField tf = new JTextField(10); public class example implements MouseListener
[Link](button1); JLabel lb = new JLabel("Name:"); public void mousePressed(MouseEvent e)
[Link](jcombobox1); [Link](jif); public void mouseReleased(MouseEvent e)
Container c1=[Link](); [Link](dp);
[Link](t1,[Link]);
JDBC Database all operations //Select or retrive data from tabe using DML Prepared Statement
import [Link].*; String s2 = SELECT * FROM users"; (esma query pahila lekhni ani balla statement)
public class Example { ResultSet rs = [Link](s2); //Insert data in Table (same example)
public static void main(String[] args) { while([Link]()) {
try { int id =[Link]("id"); String s1 = "INSERT INTO users VALUES(?,?)";
[Link]("[Link]"); String name = [Link]("name"); PreparedStatement pstmt = [Link](s1);
String url="jdbc:mysql://localhost:3306/test"; String email = [Link]("email"); [Link](1, "A");
String username="root"; [Link]("Id="+id+"Name="+name); [Link](2, "xyz@[Link]");
String password=""; [Link]();
//Update table using DML [Link](1, "B");
Connection conn String s3="UPDATE users SET name ='x' [Link](2, "abc@[Link]");
=[Link](url,username, password); WHERE id=1"; [Link]();
Statement stmt = [Link](); [Link](s3);
//Select Data from Table
//Create a new table using DDL //Delete data from table using DML String s2="SELECT * FROM users WHERE id=?";
String s1 = "CREATE TABLE users(id INT PRIMARY String s4="DELETE FROM users WHERE id=1"; PreparedStatement pstmt = [Link](s2);
KEY, name VARCHAR(255), email VARCHAR(255))"; [Link](s4); [Link](1, 1);
[Link](s1); [Link](1,2);
[Link](); [Link]; } catch(SQLException e) ResultSet rs= [Link]();......... rest are same
{ S.o.p([Link]()); } } }
Scrollable and updatable resultsets SQL ESCAPES
Statement st i) Like wildcard literals{escape 'escapecharacter'}
=[Link](ResultSet.TYPE_SCROLL_S SELECT a FROM tabA WHERE a LIKE '$%%'
ENSITIVE, ResultSet.CONCUR_READ_ONLY {escape '$;}
Transactions ii) Function Handling
try { SELECT {fn UCASE(Name) } FROM Employee
[Link](false);
//execute Statement #1
//execute Statement #2
//execute Statement #3
[Link]();
}
catch(exception e) { [Link](); }
finally { [Link](trye);
}
Socket Programming using TCP For Server Socket Programming using UDP For Client
For Client For Server public class UDPClient {
import [Link].*; import [Link].*; import [Link].*; public static void main(String[] args) {
import [Link].*; import [Link].*; import [Link].*;
String serverAddress = "localhost";
public class TCPClient { public class TCPServer{ public class UDPServer { int serverPort = 9876;
public static void main(String[] args]) { public static void main(String[] args]) { public static void main(String[] args) { try {
try { try { int port = 9876; try { DatagramSocket clientSocket = new
Socket c1= new Socket("localhost",4241); ServerSocket s1= new Socket(4241); DatagramSocket serverSocket = new DatagramSocket();
Socket c1 = [Link](); DatagramSocket(port); InetAddress serverIPAddress =
Scanner in = new byte[] receiveData = new byte[1024]; [Link](serverAddress);
Scanner([Link]()); Scanner in = new [Link]("UDP Server is running on port " BufferedReader userInput = new
Scanner([Link]()); + port); BufferedReader(new
PrintWriter out = new while (true) { InputStreamReader([Link]));
PrintWriter([Link](),true); PrintWriter out = new DatagramPacket receivePacket = new while (true) {
PrintWriter([Link](),true); DatagramPacket(receiveData, [Link] ("Enter message: ");
[Link]("Hello Server"); [Link]); String message = [Link]();
String servermsg = [Link](); String clientmsg = [Link](); [Link](receivePacket); byte[] sendData = [Link]();
[Link]("Message :"+ servermsg); [Link]("Message :"+ servermsg); String receivedMessage = new DatagramPacket sendPacket = new
[Link]("Hello Client"); String([Link](), 0, DatagramPacket(sendData,
[Link](); [Link](); [Link](); } [Link]()); [Link], serverIPAddress,
catch(IOException e) { [Link](); [Link](); [Link](); [Link] ("Received message from client: " serverPort);
[Link]([Link]()); } } [Link](); } + receivedMessage); }} [Link](sendPacket); } }
catch(IOException e) { catch(IOException e) { catch(IOException e) {
[Link]([Link]()); } } [Link]([Link]()); } } [Link]([Link]()); } }
JAVA Mail API JAVAFX UI CONTROLS RMI to find sum of two numbers 3) Create Client
Sending email 1)Define remote interface import [Link].*;
import [Link].*; import [Link]; import [Link].*; import [Link].*;
import [Link].*; import [Link].*; public interface RemoteInterface public class Client {
import [Link]; import [Link].*; extends Remote { public static void main(String[] args){
public class SendEmail { import [Link].*; public int add(int x, int y) throws String ip = "rmi://[Link]/SERVICE";
public static void main(String[] args) { import [Link].*; RemoteException; } RemoteInterface ri =
String from = "test@[Link]"; (RemoteInterface)[Link](ip);
String to = "test1@[Link]"; public class JavaFxExample extends 2) Implement remote interface [Link]("Sum is"+ [Link](1,3));
Properties props = new Properties(); Application { import [Link].*; }
[Link]("[Link]", public static void main(String[] args) import [Link];
"[Link]"); { public class RemoteInterfaceImplement
[Link]("[Link]", "25"); launch(args); extends UnicastRemoteObject Simple CORBA Example
Session session = @Override implements RemoteInterface {
[Link](props); public void start(Stage primaryStage){ public RemoteInterfaceImplement() module HelloApp
try { RadioButton b1=new RadioButton("A"); throws RemoteException {
MimeMessage message = new RadioButton b2=new RadioButton("B"); { super(); } interface Hello{
MimeMessage(session); ToggleGroup tg = new ToggleGroup(); public int add(intx, inty) { return string SayHello();
[Link](new [Link](tg); (x+y);} } };
InternetAddress(from)); [Link](tg); };
[Link]([Link] 3) Create Server
[Link], new InternetAddress(to)); VBox vb = new Vbox(); import [Link].*; We run IDL Compiler to generate Java
[Link]("Test Email"); [Link]().addAll(b1,b2); import [Link].*; Files as:
[Link]("This is a test email sent Scene scene = new Scene(vb, 300,50); public class Server { idlj-fall [Link]
from Java without authentication."); [Link](scene); public static void main(String[] args){ This generates the necessary Java Files,
[Link](message); [Link](); RemoteInterfaceImplement rii = new including the stubs and skeletons.
[Link]("Email sent } RemoteInterfaceImplement();
successfully!"); } catch [Link](1099);
(MessagingException e) { [Link]("SERVICE",rii);
throw new RuntimeException(e); [Link]("Server Started");
} }} }
Servlet program that reads and displays data from JSP program that reads and displays data from HTML form
HTML Form
<form action="FormServlet" method ="POST"> HTML Form
Username:<input type="text" name= "user"> <form action="[Link]" method ="POST">
Password:<input type="password" name="pass"> Firstname:<input type="text" name= "fname">
<input type="submit"> </form> Lastname:<input type="text" name="lname">
<input type="submit"> </form>
Servlet
import [Link].*; JSP
import [Link].*; <% @ page language="java" contentType="text/html" %>
import [Link].*; <html>
public class FormServlet extends HttpServlet{ <head> <title>JSP</title>
public void doPost(HttpServletRequest request, HttpServletResponse <body><h2>Your full name</h2>
response) throws IOException, ServletException { <%
String firstname=[Link]("fname");
[Link]("text/html"); String lastname=[Link]("lname");
PrintWriter out = [Link](); [Link](firstname +" "+lastname);
%>
String username=[Link]("user") </body>
String password=[Link]("pass") </html?
[Link]("<p>Username:"+username+"</p>");
[Link]("<p>Password:"+password+"</p>");
}}