SlideShare a Scribd company logo
OBJECT ORIENTED  PROGRAMMING
INDEX  UNIT 8PPT SLIDES S.NO.   TOPIC    LECTURE NO.  PPTSLIDES Basics of network programming     L1 L1.1TO L1.7  addresses    L2 L2.1 TO L2.2 Ports     L3 L3.1 TO L3.2 4 Sockets     L 4 L4.1 TO L4.3 simple client server program     L 5 L5.1 TO L5.5 Multiple clients   L 6 L6.1 TO L6.5 java .net package      L 7 L7.1 TO L7.2 8 java.util package    L 8 L8.1 TO L8.3
Basics of network programming: Overview   TCP/IP java.net RMI JDBC CORBA Network OS
A Network Is... node any device on the network host a computer on the network address computer-readable name for host host name human-readable name for host
A Network Does... datagram (or “packet”) little bundle of information sent from one node to another protocol roles, vocabulary, rules for communication IP the Internet Protocol
TCP/IP: The Internet Protocol Physical Network Transport Layer (TCP, UDP) Internet Layer (IP) Application Layer (HTTP, FTP, SMTP)
TCP/UDP/IP IP raw packets the “Internet Layer” TCP data stream reliable, ordered the “Transport Layer” UDP user datagrams (packets) unreliable, unordered the “Transport Layer”
The Three ‘I’s internet any IP-based network Internet the big, famous, world-wide IP network intranet a corporate LAN-based IP network extranet accessing corporate data across the Internet
Java and Networking Built into language One of the 11 buzzwords Network ClassLoader java.net API Based on TCP/IP, the Internet Protocol
Addresses Every computer on the Internet has an  address.  An Internet address is a number that uniquely identifies each computer on the Net.  There are 32 bits in an IP address, and often refer to them as a sequence of four numbers between 0 and 255 separated by dots The first few bits define which class of network, lettered A, B, C, D, or E, the address represents.  Most Internet users are on a class C network, since there are over two million networks in class C.
IP Addresses The first byte of a class C network is between 192 and 224, with the last byte actually identifying an individual computer among the 256 allowed on a single class C network.  IP Address: identifies a host DNS: converts host names / domain names into IP addresses.
Ports Port: a meeting place on a host one service per port 1-1023 = well-known services 1024+ = experimental services, temporary
Well-Known Ports 20,21: FTP 23: telnet 25: SMTP 43: whois 80: HTTP 119: NNTP 1099: RMI
Sockets A  network socket  is a lot like an electrical socket. Socket: a two-way connection Internet Protocol (IP)  is a low-level routing protocol that breaks data into small packets and sends them to an address across a network, which does not guarantee to deliver said packets to the destination. Transmission Control Protocol (TCP)  is a higher-level protocol that manages to robustly string together these packets, sorting and retransmitting them as necessary to reliably transmit your data. A third protocol,  User Datagram Protocol (UDP) , sits next to TCP and can be used directly to support fast, connectionless, unreliable transport of packets.
The Socket Class Socket(String host, int port) InputStream getInputStream() OutputStream getOutputStream() void close() Socket s = new Socket(“www.starwave.com”, 90);
Sockets and Ports Client port 13 port 80 Time Service Web Service Socket Server Socket
Client-Server Client - initiates connection retrieves data,  displays data,  responds to user input,  requests more data Examples: Web Browser Chat Program PC accessing files
simple client server program-client /** Client program using TCP */   public class Tclient {   final static  String serverIPname = “starwave.com";// server IP name final static  int serverPort  = 3456; // server port number public static void main(String args[]) { java.net.Socket sock = null; // Socket object for communicating java.io.PrintWriter pw  = null; // socket output to server java.io.BufferedReader br  = null; // socket input from server   try { sock = new java.net.Socket(serverIPname,serverPort);// create socket  and connect pw  = new java.io.PrintWriter(sock.getOutputStream(), true);  // create  reader and writer br  = new java.io.BufferedReader(new    java.io.InputStreamReader(sock.getInputStream())); System.out.println("Connected to Server");
pw.println("Message from the client"); // send msg to the server System.out.println("Sent message to server"); String answer = br.readLine(); // get data from the server System.out.println("Response from the server >" + answer);   pw.close(); // close everything br.close(); sock.close(); } catch (Throwable e) { System.out.println("Error " + e.getMessage()); e.printStackTrace(); } } }
Server program /** Server program using TCP */ public class Tserver {   final static int serverPort  = 3456; // server port number   public static void main(String args[]) { java.net.ServerSocket  sock = null; // original server socket java.net.Socket clientSocket = null; //  //socket created by accept java.io.PrintWriter pw  = null; //  //socket output stream java.io.BufferedReader br  = null; // socket input stream   try { sock = new java.net.ServerSocket(serverPort); // create socket and bind to port System.out.println("waiting for client to connect"); clientSocket = sock.accept();
// wait for client to connect System.out.println("client has connected"); pw  = new java.io.PrintWriter(clientSocket.getOutputStream(),true); br  = new java.io.BufferedReader( new java.io.InputStreamReader(clientSocket.getInputStream()));   String msg = br.readLine(); // read msg from client System.out.println("Message from the client >" + msg); pw.println("Got it!"); // send msg to client   pw.close(); // close everything br.close(); clientSocket.close(); sock.close(); } catch (Throwable e) { System.out.println("Error " + e.getMessage()); e.printStackTrace(); } } }
Multiple Clients Multiple clients can connect to the same port on the server at the same time.  Incoming data is distinguished by the port to which it is addressed and the client host and port from which it came.  The server can tell for which service (like http or ftp) the data is intended by inspecting the port.  It can tell which open socket on that service the data is intended for by looking at the client address and port stored with the data.
Queueing Incoming connections are stored in a queue until the server can accept them.  On most systems the default queue length is between 5 and 50.  Once the queue fills up further incoming connections are refused until space in the queue opens up.
The java.net.ServerSocket Class The java.net.ServerSocket class represents a server socket.  A ServerSocket object is constructed on a particular local port. Then it calls accept() to listen for incoming connections.  accept() blocks until a connection is detected. Then accept() returns a java.net.Socket object that performs the actual communication with the client.
Constructors There are three constructors that specify the port to bind to, the queue length for incoming connections, and the IP address to bind to: public ServerSocket(int port) throws IOException public ServerSocket(int port, int backlog) throws  IOException public ServerSocket(int port, int backlog, InetAddress networkInterface) throws IOException
Constructing Server Sockets specify the port number to listen : try { ServerSocket ss = new ServerSocket(80); } catch (IOException e) { System.err.println(e); }
java.net package The classes in  java.net  package are : JarURLConnection (Java 2)  URLConnection DatagramSocketImpl ServerSocket URLDecoder (Java 2) HttpURLConnection Socket URLEncoder InetAddress SocketImpl URLStreamHandler SocketPermission ContentHandler MulticastSocket URL DatagramPacket NetPermission URLClassLoader (Java 2) DatagramSocket PasswordAuthentication(Java 2) Authenticator (Java 2)
The  java.net  package's interfaces are ContentHandlerFactory SocketImplFactory URLStreamHandlerFactory FileNameMap SocketOptions
java.util package The  java.util package defines the following  classes: AbstractCollection (Java2) EventObject PropertyResourceBundle AbstractList (Java 2) GregorianCalendar Random AbstractMap (Java 2) HashMap(Java 2) ResourceBundle AbstractSequentialList(Java 2) HashSet (Java2) SimpleTimeZone AbstractSet (Java 2) Hashtable Stack
ArrayList (Java 2) LinkedList(Java 2) StringTokenizer Arrays (Java 2) ListResourceBundle TimeZone BitSet Locale TreeMap (Java 2) Calendar Observable TreeSet (Java 2) Collections (Java 2) Properties Vector Date PropertyPermission(Java 2) WeakHashMap (Java 2) Dictionary
java.util  defines the following interfaces.  Collection (Java 2) List (Java 2) Observer Comparator (Java 2) ListIterator(Java 2) Set (Java 2) Enumeration Map (Java 2) SortedMap (Java 2) EventListener Map.Entry(Java 2) SortedSet (Java 2) Iterator (Java 2)
Ad

More Related Content

What's hot (20)

Java OOP Concepts 1st Slide
Java OOP Concepts 1st SlideJava OOP Concepts 1st Slide
Java OOP Concepts 1st Slide
sunny khan
 
Java 8-revealed
Java 8-revealedJava 8-revealed
Java 8-revealed
Hamed Hatami
 
Java - Processing input and output
Java - Processing input and outputJava - Processing input and output
Java - Processing input and output
Riccardo Cardin
 
Python
PythonPython
Python
Aashish Jain
 
Bt0074 oops with java
Bt0074 oops with javaBt0074 oops with java
Bt0074 oops with java
Techglyphs
 
Python ppt
Python pptPython ppt
Python ppt
Mohita Pandey
 
Tutorial c#
Tutorial c#Tutorial c#
Tutorial c#
Mohammad Faizan
 
Qcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharpQcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharp
Michael Stal
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Maloth
Bhavsingh Maloth
 
Java networking
Java networkingJava networking
Java networking
Arati Gadgil
 
C# tutorial
C# tutorialC# tutorial
C# tutorial
sarangowtham_gunnam
 
ANSI C Macros
ANSI C MacrosANSI C Macros
ANSI C Macros
Srikrishnan Suresh
 
Bt0074 oops with java2
Bt0074 oops with java2Bt0074 oops with java2
Bt0074 oops with java2
Techglyphs
 
Java Programming Assignment
Java Programming AssignmentJava Programming Assignment
Java Programming Assignment
Vijayananda Mohire
 
Oop2011 actor presentation_stal
Oop2011 actor presentation_stalOop2011 actor presentation_stal
Oop2011 actor presentation_stal
Michael Stal
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
Michael Stal
 
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
Coen De Roover
 
Socket Programming In Python
Socket Programming In PythonSocket Programming In Python
Socket Programming In Python
didip
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
Srinivas Narasegouda
 
Mixing Python and Java
Mixing Python and JavaMixing Python and Java
Mixing Python and Java
Andreas Schreiber
 
Java OOP Concepts 1st Slide
Java OOP Concepts 1st SlideJava OOP Concepts 1st Slide
Java OOP Concepts 1st Slide
sunny khan
 
Java - Processing input and output
Java - Processing input and outputJava - Processing input and output
Java - Processing input and output
Riccardo Cardin
 
Bt0074 oops with java
Bt0074 oops with javaBt0074 oops with java
Bt0074 oops with java
Techglyphs
 
Qcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharpQcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharp
Michael Stal
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Maloth
Bhavsingh Maloth
 
Bt0074 oops with java2
Bt0074 oops with java2Bt0074 oops with java2
Bt0074 oops with java2
Techglyphs
 
Oop2011 actor presentation_stal
Oop2011 actor presentation_stalOop2011 actor presentation_stal
Oop2011 actor presentation_stal
Michael Stal
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
Michael Stal
 
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
Multi-dimensional exploration of API usage - ICPC13 - 21-05-13
Coen De Roover
 
Socket Programming In Python
Socket Programming In PythonSocket Programming In Python
Socket Programming In Python
didip
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
Srinivas Narasegouda
 

Similar to Unit 8 Java (20)

Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
Tushar B Kute
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
Rakesh Madugula
 
Sockets
SocketsSockets
Sockets
sivindia
 
Java 1
Java 1Java 1
Java 1
VidyaVarshini3
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
Tushar B Kute
 
Networking
NetworkingNetworking
Networking
Tuan Ngo
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
Nitish Nagar
 
Tcp/ip server sockets
Tcp/ip server socketsTcp/ip server sockets
Tcp/ip server sockets
rajshreemuthiah
 
28 networking
28  networking28  networking
28 networking
Ravindra Rathore
 
Networking
NetworkingNetworking
Networking
nik.manjit
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
kamal kotecha
 
Socket Programming it-slideshares.blogspot.com
Socket  Programming it-slideshares.blogspot.comSocket  Programming it-slideshares.blogspot.com
Socket Programming it-slideshares.blogspot.com
phanleson
 
Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programming
elliando dias
 
Os 2
Os 2Os 2
Os 2
university of Gujrat, pakistan
 
Sockets
Sockets Sockets
Sockets
Gopaiah Sanaka
 
Lecture25
Lecture25Lecture25
Lecture25
Debasish Pratihari
 
A.java
A.javaA.java
A.java
JahnaviBhagat
 
Lab manual cn-2012-13
Lab manual cn-2012-13Lab manual cn-2012-13
Lab manual cn-2012-13
Sasi Kala
 
Ad

More from arnold 7490 (20)

Les14
Les14Les14
Les14
arnold 7490
 
Les13
Les13Les13
Les13
arnold 7490
 
Les11
Les11Les11
Les11
arnold 7490
 
Les10
Les10Les10
Les10
arnold 7490
 
Les09
Les09Les09
Les09
arnold 7490
 
Les03
Les03Les03
Les03
arnold 7490
 
Les02
Les02Les02
Les02
arnold 7490
 
Les01
Les01Les01
Les01
arnold 7490
 
Les12
Les12Les12
Les12
arnold 7490
 
Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Java
arnold 7490
 
Unit 5 Java
Unit 5 JavaUnit 5 Java
Unit 5 Java
arnold 7490
 
Unit 4 Java
Unit 4 JavaUnit 4 Java
Unit 4 Java
arnold 7490
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
arnold 7490
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
arnold 7490
 
Unit6 C
Unit6 C Unit6 C
Unit6 C
arnold 7490
 
Unit5 C
Unit5 C Unit5 C
Unit5 C
arnold 7490
 
Ad

Recently uploaded (20)

UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 

Unit 8 Java

  • 1. OBJECT ORIENTED PROGRAMMING
  • 2. INDEX UNIT 8PPT SLIDES S.NO. TOPIC LECTURE NO. PPTSLIDES Basics of network programming L1 L1.1TO L1.7 addresses L2 L2.1 TO L2.2 Ports L3 L3.1 TO L3.2 4 Sockets L 4 L4.1 TO L4.3 simple client server program L 5 L5.1 TO L5.5 Multiple clients L 6 L6.1 TO L6.5 java .net package L 7 L7.1 TO L7.2 8 java.util package L 8 L8.1 TO L8.3
  • 3. Basics of network programming: Overview TCP/IP java.net RMI JDBC CORBA Network OS
  • 4. A Network Is... node any device on the network host a computer on the network address computer-readable name for host host name human-readable name for host
  • 5. A Network Does... datagram (or “packet”) little bundle of information sent from one node to another protocol roles, vocabulary, rules for communication IP the Internet Protocol
  • 6. TCP/IP: The Internet Protocol Physical Network Transport Layer (TCP, UDP) Internet Layer (IP) Application Layer (HTTP, FTP, SMTP)
  • 7. TCP/UDP/IP IP raw packets the “Internet Layer” TCP data stream reliable, ordered the “Transport Layer” UDP user datagrams (packets) unreliable, unordered the “Transport Layer”
  • 8. The Three ‘I’s internet any IP-based network Internet the big, famous, world-wide IP network intranet a corporate LAN-based IP network extranet accessing corporate data across the Internet
  • 9. Java and Networking Built into language One of the 11 buzzwords Network ClassLoader java.net API Based on TCP/IP, the Internet Protocol
  • 10. Addresses Every computer on the Internet has an address. An Internet address is a number that uniquely identifies each computer on the Net. There are 32 bits in an IP address, and often refer to them as a sequence of four numbers between 0 and 255 separated by dots The first few bits define which class of network, lettered A, B, C, D, or E, the address represents. Most Internet users are on a class C network, since there are over two million networks in class C.
  • 11. IP Addresses The first byte of a class C network is between 192 and 224, with the last byte actually identifying an individual computer among the 256 allowed on a single class C network. IP Address: identifies a host DNS: converts host names / domain names into IP addresses.
  • 12. Ports Port: a meeting place on a host one service per port 1-1023 = well-known services 1024+ = experimental services, temporary
  • 13. Well-Known Ports 20,21: FTP 23: telnet 25: SMTP 43: whois 80: HTTP 119: NNTP 1099: RMI
  • 14. Sockets A network socket is a lot like an electrical socket. Socket: a two-way connection Internet Protocol (IP) is a low-level routing protocol that breaks data into small packets and sends them to an address across a network, which does not guarantee to deliver said packets to the destination. Transmission Control Protocol (TCP) is a higher-level protocol that manages to robustly string together these packets, sorting and retransmitting them as necessary to reliably transmit your data. A third protocol, User Datagram Protocol (UDP) , sits next to TCP and can be used directly to support fast, connectionless, unreliable transport of packets.
  • 15. The Socket Class Socket(String host, int port) InputStream getInputStream() OutputStream getOutputStream() void close() Socket s = new Socket(“www.starwave.com”, 90);
  • 16. Sockets and Ports Client port 13 port 80 Time Service Web Service Socket Server Socket
  • 17. Client-Server Client - initiates connection retrieves data, displays data, responds to user input, requests more data Examples: Web Browser Chat Program PC accessing files
  • 18. simple client server program-client /** Client program using TCP */   public class Tclient {   final static String serverIPname = “starwave.com";// server IP name final static int serverPort = 3456; // server port number public static void main(String args[]) { java.net.Socket sock = null; // Socket object for communicating java.io.PrintWriter pw = null; // socket output to server java.io.BufferedReader br = null; // socket input from server   try { sock = new java.net.Socket(serverIPname,serverPort);// create socket and connect pw = new java.io.PrintWriter(sock.getOutputStream(), true); // create reader and writer br = new java.io.BufferedReader(new java.io.InputStreamReader(sock.getInputStream())); System.out.println("Connected to Server");
  • 19. pw.println("Message from the client"); // send msg to the server System.out.println("Sent message to server"); String answer = br.readLine(); // get data from the server System.out.println("Response from the server >" + answer);   pw.close(); // close everything br.close(); sock.close(); } catch (Throwable e) { System.out.println("Error " + e.getMessage()); e.printStackTrace(); } } }
  • 20. Server program /** Server program using TCP */ public class Tserver {   final static int serverPort = 3456; // server port number   public static void main(String args[]) { java.net.ServerSocket sock = null; // original server socket java.net.Socket clientSocket = null; // //socket created by accept java.io.PrintWriter pw = null; // //socket output stream java.io.BufferedReader br = null; // socket input stream   try { sock = new java.net.ServerSocket(serverPort); // create socket and bind to port System.out.println("waiting for client to connect"); clientSocket = sock.accept();
  • 21. // wait for client to connect System.out.println("client has connected"); pw = new java.io.PrintWriter(clientSocket.getOutputStream(),true); br = new java.io.BufferedReader( new java.io.InputStreamReader(clientSocket.getInputStream()));   String msg = br.readLine(); // read msg from client System.out.println("Message from the client >" + msg); pw.println("Got it!"); // send msg to client   pw.close(); // close everything br.close(); clientSocket.close(); sock.close(); } catch (Throwable e) { System.out.println("Error " + e.getMessage()); e.printStackTrace(); } } }
  • 22. Multiple Clients Multiple clients can connect to the same port on the server at the same time. Incoming data is distinguished by the port to which it is addressed and the client host and port from which it came. The server can tell for which service (like http or ftp) the data is intended by inspecting the port. It can tell which open socket on that service the data is intended for by looking at the client address and port stored with the data.
  • 23. Queueing Incoming connections are stored in a queue until the server can accept them. On most systems the default queue length is between 5 and 50. Once the queue fills up further incoming connections are refused until space in the queue opens up.
  • 24. The java.net.ServerSocket Class The java.net.ServerSocket class represents a server socket. A ServerSocket object is constructed on a particular local port. Then it calls accept() to listen for incoming connections. accept() blocks until a connection is detected. Then accept() returns a java.net.Socket object that performs the actual communication with the client.
  • 25. Constructors There are three constructors that specify the port to bind to, the queue length for incoming connections, and the IP address to bind to: public ServerSocket(int port) throws IOException public ServerSocket(int port, int backlog) throws IOException public ServerSocket(int port, int backlog, InetAddress networkInterface) throws IOException
  • 26. Constructing Server Sockets specify the port number to listen : try { ServerSocket ss = new ServerSocket(80); } catch (IOException e) { System.err.println(e); }
  • 27. java.net package The classes in java.net package are : JarURLConnection (Java 2) URLConnection DatagramSocketImpl ServerSocket URLDecoder (Java 2) HttpURLConnection Socket URLEncoder InetAddress SocketImpl URLStreamHandler SocketPermission ContentHandler MulticastSocket URL DatagramPacket NetPermission URLClassLoader (Java 2) DatagramSocket PasswordAuthentication(Java 2) Authenticator (Java 2)
  • 28. The java.net package's interfaces are ContentHandlerFactory SocketImplFactory URLStreamHandlerFactory FileNameMap SocketOptions
  • 29. java.util package The java.util package defines the following classes: AbstractCollection (Java2) EventObject PropertyResourceBundle AbstractList (Java 2) GregorianCalendar Random AbstractMap (Java 2) HashMap(Java 2) ResourceBundle AbstractSequentialList(Java 2) HashSet (Java2) SimpleTimeZone AbstractSet (Java 2) Hashtable Stack
  • 30. ArrayList (Java 2) LinkedList(Java 2) StringTokenizer Arrays (Java 2) ListResourceBundle TimeZone BitSet Locale TreeMap (Java 2) Calendar Observable TreeSet (Java 2) Collections (Java 2) Properties Vector Date PropertyPermission(Java 2) WeakHashMap (Java 2) Dictionary
  • 31. java.util defines the following interfaces. Collection (Java 2) List (Java 2) Observer Comparator (Java 2) ListIterator(Java 2) Set (Java 2) Enumeration Map (Java 2) SortedMap (Java 2) EventListener Map.Entry(Java 2) SortedSet (Java 2) Iterator (Java 2)