Posts

Showing posts from February, 2022

12.CLIENT/SERVER SOCKET COMMUNICATION

  //ServerPrg.Java import java.net.*; import java.io.*; public class ServerPrg { private static Socket socket; public static void main(String[] args) { try { int port = 25000; ServerSocket serverSocket = new ServerSocket(port); System.out.println("Server Started and listening to the port 25000"); //Server is running always. This is done using this while(true) loop while(true) { //Reading the message from the client socket = serverSocket.accept(); InputStream is = socket.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String number = br.readLine(); System.out.println("Message received from client is "+number); //Multiplying the number by 2 and forming the return message String returnMessage; try { int n = Integer.parseInt(number); int result = n*2; returnMessage = String.valueOf(result) + "\n"; } catch(NumberFormatException e) { //Input was not a number. Sending proper message back to client....

11.REMOTE METHOD INVOCATION

Image
  //Define the remote interface import java.rmi.Remote; import java.rmi.RemoteException; public interface Hello extends Remote { void printMsg() throws RemoteException; } //Develop the implementation class (remote object) // Implementing the remote interface public class ImplExample implements Hello { public void printMsg() { System.out.println("This is an example RMI program"); } } //Develop the server program import java.rmi.registry.Registry; import java.rmi.registry.LocateRegistry; import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; public class Server extends ImplExample { public Server() {} public static void main(String args[]) { try { ImplExample obj = new ImplExample(); Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0); Registry registry = LocateRegistry.getRegistry(); registry.bind("Hello", stub); System.err.println("Server ready"); } catch (Exception e) { System.err.println("Server exception: " + e....

10.SERVLETS /JSP IN JAVA

  package JSP;  import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest import javax.servlet.http.HttpServletResponse; public class Login extends HttpServlet { protected void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException PrintWriter pw=res.getWriter(); res.setContentType("text/html"); String user=req.getParameter("userName"); String pass=req.getParameter("userPassword"); pw.println("Login Success...!") if(user.equals("veera") && pass.equals("@123")) pw.println("Login Success...!"); else pw.println("Login Failed...!"); pw.close(); } }  OUTPUT: username:veera userPassword:@123 LOGIN SUCCESS

9.JDBC CONNECTIVITY

  import java.sql.*; public class database { public static void main(String args[]) { try { Class.forName("oracle.jdbc.driver.OracleDriver"); System.out.println("Oracle Database Connectivity"); System.out.println("############################\n\n"); Connection con=DriverManager.getConnection ("jdbc:oracle:thin:@192.168.23.237:1521:orcl", "scott","tiger"); Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery("SELECT * FROM Login"); System.out.println("Username\tPassword"); System.out.println("********\t********"); while(rs.next()) System.out.println(rs.getString(1)+"\t\t"+rs.getString(2)); con.close(); } catch(Exception e) { System.out.println(e); } } } Output: Oracle Database Connectivity ############################ Username Password ******** ******** Anitha 123 James 456 George 789

8.NETWORK PROGRAMMING IN JAVA

 import java.net.InetAddress; import java.net.MalformedURLException; import java.net.URL; import java.net.UnknownHostException; public class Networking { public static void main(String[] args) throws MalformedURLException { InetAddress ip; String hostname; try { ip = InetAddress.getLocalHost(); hostname = ip.getHostName(); System.out.println("Your current IP address : " + ip); System.out.println("Your current Hostname : " + hostname); URL url=new URL("https://mail.google.com/mail/u/0/#"); System.out.println("Protocol: "+url.getProtocol()); System.out.println("Host Name: "+url.getHost()); System.out.println("Port Number: "+url.getPort()); System.out.println("Default Port Number: "+url.getDefaultPort()); System.out.println("Query String: "+url.getQuery()); System.out.println("Path: "+url.getPath()); System.out.println("File: "+url.getFile()); } catch (UnknownHostException e) { e.printStack...

7.SWING AND EVENT HANDLING IN JAVA

Image
  import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SwingDemo { private JFrame mainFrame; private JLabel headerLabel; private JLabel statusLabel; private JPanel controlPanel; public SwingDemo() { prepareGUI(); } public static void main(String[] args) { SwingDemo swingControlDemo = new SwingDemo(); swingControlDemo.showEventDemo(); }  private void prepareGUI() { mainFrame = new JFrame("Java SWING Examples"); mainFrame.setSize(400,400); mainFrame.setLayout(new GridLayout(3, 1)); headerLabel = new JLabel("",JLabel.CENTER ); statusLabel = new JLabel("",JLabel.CENTER); statusLabel.setSize(350,100); mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent windowEvent) { System.exit(0); } }); controlPanel = new JPanel(); controlPanel.setLayout(new FlowLayout()); mainFrame.add(headerLabel); mainFrame.add(controlPanel); mainFrame.add(statusLabel); mainFrame.setVisible(true); } private void showEventDemo() ...

6.AWT COMPONENTS

Image
  Source Code:  import java.awt.*; import javax.swing.*; public class AWTDemo { AWTDemo() { Frame f= new Frame("AWT Components"); MenuBar mb=new MenuBar(); Menu menu=new Menu("File"); Menu New=new Menu("New"); MenuItem i1=new MenuItem("Save"); MenuItem i2=new MenuItem("Close"); MenuItem i3=new MenuItem("Project"); MenuItem i4=new MenuItem("Class"); New.add(i3); New.add(i4); menu.add(New); menu.add(i1); menu.add(i2); mb.add(menu); JButton b1=new JButton("NORTH"); JButton b2=new JButton("SOUTH"); JButton b3=new JButton("EAST"); JButton b4=new JButton("WEST"); JButton b5=new JButton("CENTER"); f.add(b1,BorderLayout.NORTH); f.add(b2,BorderLayout.SOUTH); f.add(b3,BorderLayout.EAST); f.add(b4,BorderLayout.WEST); f.add(b5,BorderLayout.CENTER); f.setMenuBar(mb); f.setSize(400,400); f.setVisible(true); } public static void main(String args[]) { new AWTDemo(); } } Output:

5.IMPLEMENTING I/O STREAMS IN JAVA

  5.IMPLEMENTING I/O STREAMS IN JAVA Source Code:  import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class FileStream { public static void main(String[] args) { FileInputStream in = null; FileOutputStream out = null; int words=0,chars=0,lines=0; try { in = new FileInputStream("Input.txt"); out = new FileOutputStream("Output.txt"); int c; while((c=in.read())!=-1) { out.write(c); if(c==' ') { ++words; } else if(c=='\n') { ++lines; ++words; } ++chars; } } catch (IOException e) { e.printStackTrace(); } finally { try { in.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } } System.out.println("File Copied..."); System.out.println("Number of Words:" +(++words)); System.out.println("Number of Characters:" +chars); System.out.println("Number of Lines:" +(++lines)); } } Output: File Copied... Number of Words:4 Number of Characters:30 Number of Lines:4

4.EXCEPTION HANDLING IN JAVA

  4.EXCEPTION HANDLING IN JAVA Source Code:  import java.io.*; class Predefined{ void ArithmeticExcp(){ try{ int a=20,b=0,c; c=a/b; System.out.println("Result:"+c); } catch(ArithmeticException e){ System.out.println("Arithmetic Exception:Division by zero"); } } void StrindOutofBoundExcp(){ try{ String s="Java Programming"; char c=s.charAt(25); System.out.println(c); } catch(StringIndexOutOfBoundsException e) { System.out.println("String out of Bound Exception:character Index out of Range"); } } void ArrayOutofBoundExcp(){ try{ int a[]=new int[5]; a[8]=9; } catch(ArrayIndexOutOfBoundsException e) { System.out.println("Array out of Bound Exception: Index out of Range"); } } void FileNotFoundExcp() throws FileNotFoundException{ try{ File file=new File("D://sample.txt"); FileReader fr=new FileReader(file); } catch(FileNotFoundException e) { System.out.println("File Not Found Exception: File does not exist"); } } } public...

3.MULTITHREADING IN JAVA

  3.MULTITHREADING IN JAVA Source Code:  class SquareThread extends Thread { public void run(){ try { for(int i=1;i<=5;i++) { System.out.println("Square of " +i +" is" +(i*i)); Thread.sleep(1000); } } catch(Exception e) { System.out.println(e); } } } class CubeThread extends Thread{ public void run(){ try { for(int i=1;i<=5;i++) { System.out.println("Cube of " +i +" is" +(i*i*i)); } } catch(Exception e) { System.out.println(e); } } } class SquareRootThread extends Thread{ public void run(){ try { for(int i=1;i<=5;i++) { System.out.println("Square Root of " +i +" is" +(i*0.5)); Thread.sleep(10); } } catch(Exception e) { System.out.println(e); } } } class EmptyThread extends Thread{ public void run(){ for(int i=1;i<=5;i++) { System.out.println("Hello Thread"); } } } public class ThreadExample { public static void main(String[] args) { System.out.println("Multithreading in Java"); System.out.printl...

2)implementation of pakage

 2.Implementation of package Source Code  package pack1;  public class myclass { public void display() { System.out.println("Implementation of package"); } } package pack1; public class myclass1 { public static void main(String[] args) { myclass m=new myclass(); m.display(); } } Output: Implementation of package

1Single Inheritance and multilevel inheritance

 class dog { String name; public void rv1() { System.out.println("Bow Bow"); } } class cat extends dog { public void rv2() { System.out.println("Meow Meow"); } } public class prg1 { public static void main(String[] args) { cat c=new cat(); c.rv2(); c.rv1(); } } Output: Meow Meow Bow Bow 2)b)Multilevel inheritance  Source Code:  class colour { public void red() { System.out.println("Apple -red color"); } } class fruit extends colour { public void orange() { System.out.println("orange – orange color"); } } class name extends fruit { public void yellow() { System.out.println("lemon – yellow color"); } } public class prg11 { public static void main(String[] args) { name a=new name(); a.red(); a.orange(); a.yellow(); } } Output: Apple - red color Orange – orange color Lemon – yellow colo c)Hierarchical inheritance Source Code:  class cs { public void HOD() { System.out.println("Head of Department"); } } class first extends cs { pub...

java last program

https://drive.google.com/file/d/1I6ihCTMeSedeiFzbad9ze1Dqv9Er-fQt/view?usp=sharing

total source pdf

https://drive.google.com/file/d/1OrIJn5Mb3AdLcr0ioR3O-7SOvaBCj2Rg/view?usp=sharing