SlideShare une entreprise Scribd logo
1  sur  28
Télécharger pour lire hors ligne
Advanced Java Programming
Topic: Networking

By
Ravi Kant Sahu
Asst. Professor, LPU
Contents







Network Basics
Client-Server Architecture
Sockets
Networking classes and Interfaces
Network Protocols
Java Mail API

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Basics of NetworkiNg

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Network basics


Transmission Control Protocol (TCP)
- Connection-Oriented
- Reliable
TCP is a connection-based protocol that provides a reliable flow of data
between two computers.



User Datagram Protocol (UDP)
- Connectionless
- Unreliable
UDP is a protocol that sends independent packets of data, called datagrams,
from one computer to another with no guarantees about arrival.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Network basics


Internet Protocol (IP)
IP is a low level protocol for delivering data from one computer
to another across the internet in packets.



IP address
uniquely identifies the computer on Internet.



DNS (Domain Name Server)
translates the host name into IP address.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Understanding Ports


Data transmitted over the Internet is accompanied by addressing
information that identifies the computer and the port for which it is
destined.



The computer is identified by its 32-bit IP address, which IP uses to
deliver data to the right computer on the network.



Ports are identified by a 16-bit number, which TCP and UDP use to
deliver the data to the right application.



Port number ranges from 0 to 65536 but 0 to 1024 are reserved.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Client-Server Architecture

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Client-Server Architecture


Network Programming involves a Server and one or more
Clients.



Client attempts to establish a connection with the Server.



The server can accept or deny the connection.



Once the connection is established, Client sends requests to the
server and server responds.



The communication takes place through Sockets.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Sockets


Sockets are the endpoints of logical connection between
two hosts and used to send and receive data.



Used to implement reliable, bidirectional, persistent, pointto-point, stream-based connections between hosts on the
Internet.



There are two kinds of TCP sockets in Java.
- Socket
- ServerSocket

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
ServerSocket


ServerSocket is for servers.



To establish a server, we need to create a ServerSocket.



ServerSocket is attached to a port where the Server listens
for the connection.



accept() method is defined in ServerSocket class which is a
blocking call that will wait for a client to initiate.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
ServerSocket Constructors

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Socket


The Socket class is for clients.



It is designed to connect to server sockets and initiate
protocol exchanges.
Socket(String hostName, int port)throws
UnknownHostException, IOException
Socket(InetAddress ipAddress, int port) throws
IOException

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Socket Methods

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Socket Methods


connect( ) allows us to specify a new connection



isConnected( ) returns true if the socket is connected to a
server



isClosed( ) returns true if the socket is closed.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
InetAddress Class


InetAddress class is used to find the client’s host name and IP
address.

Example:
Socket s = new Socket(“172.19.2.250”, 8000);
Socket s = new Socket(“lpu.co.in”, 8000);
InetAddress ia = s.getInetAddress();
InetAddress ia = InetAddress.getByName(“lpu.co.in”);
Methods:
ia.getHostName();

ia.getHostAddress();

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Serving Multiple ClientS

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Multiple Clients


Multiple clients can be connected to a server.



A server can serve multiple clients simultaneously.



The connection to each client is handled by one thread.
while (true)
{
Socket socket = serverSocket.accept();
Thread thread = new ThreadClass(socket);
thread.start();
}
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Applet Clients

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Applet Clients


The client can be an applet that connects to the server running
on the host from which the applet is loaded.



HTML file must be located on the machine on which the server
is running.



Server’s host name can be obtained by invoking
getCodeBase().getHost() on an applet.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Sending and Receiving Objects


Similar to the data of primitive types, we can send and receive
the Objects.



ObjectOutputStream and ObjectInputStream is used for
sending and receiving the objects on socket streams.



We can pass only serializable objects.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Java Mail API


JavaMail is an API that is used to compose, write and read
electronic messages.



The JavaMail API provides platform independent framework
for sending and receiving mails.



The javax.mail and javax.mail.activation packages contains the
core classes of JavaMail API.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Steps to send email using JavaMail API




Get the session object.
Compose the message
Send the message

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Steps to send email using JavaMail API
1. Get the session object
 The javax.mail.Session class provides two methods to get the
object of session
public static Session getDefaultInstance( Properties props)
public static Session getDefaultInstance( Properties props,
Authentication auth)
public static Session getInstance( Properties props)
public static Session getInstance( Properties props, Authentication
auth)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Steps to send email using JavaMail API
2. Compose the message
 The javax.mail.Message class provides methods to compose the
message.
 But it is an abstract class so its subclass
javax.mail.internet.MimeMessage class is mostly used.
public MimeMessage (Session s)
public void setFrom(Address address)
public void addRecipients(Message.RecipientType type,
String addresses)
public void setSubject( String sub)
public void setText( String msg)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Steps to send email using JavaMail API
3. Send the message


The javax.mail.Transport class provides method to send the
message.
public static void send(Message message)
public static void send(Message message, Address [] address)

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Networking

Contenu connexe

Tendances

Tendances (18)

Basics of Java
Basics of JavaBasics of Java
Basics of Java
 
Basic java part_ii
Basic java part_iiBasic java part_ii
Basic java part_ii
 
Core Java
Core JavaCore Java
Core Java
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1
 
Spring boot
Spring bootSpring boot
Spring boot
 
Hibernate introduction
Hibernate introductionHibernate introduction
Hibernate introduction
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java 101 Intro to Java Programming
Java 101 Intro to Java ProgrammingJava 101 Intro to Java Programming
Java 101 Intro to Java Programming
 
Unit1 introduction to Java
Unit1 introduction to JavaUnit1 introduction to Java
Unit1 introduction to Java
 
Java basic
Java basicJava basic
Java basic
 
Introduction to JAVA
Introduction to JAVAIntroduction to JAVA
Introduction to JAVA
 
Core java
Core javaCore java
Core java
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
 
Presentation on java
Presentation  on  javaPresentation  on  java
Presentation on java
 
Taking User Input in Java
Taking User Input in JavaTaking User Input in Java
Taking User Input in Java
 
Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview Questions
 
JAVA BASICS
JAVA BASICSJAVA BASICS
JAVA BASICS
 
Core java lessons
Core java lessonsCore java lessons
Core java lessons
 

En vedette (12)

List classes
List classesList classes
List classes
 
Jun 2012(1)
Jun 2012(1)Jun 2012(1)
Jun 2012(1)
 
Sms several papers
Sms several papersSms several papers
Sms several papers
 
Internationalization
InternationalizationInternationalization
Internationalization
 
Basic IO
Basic IOBasic IO
Basic IO
 
Event handling
Event handlingEvent handling
Event handling
 
Jdbc
JdbcJdbc
Jdbc
 
Questions for Class I & II
Questions for Class I & IIQuestions for Class I & II
Questions for Class I & II
 
Servlets
ServletsServlets
Servlets
 
Collection framework
Collection frameworkCollection framework
Collection framework
 
Classes and Nested Classes in Java
Classes and Nested Classes in JavaClasses and Nested Classes in Java
Classes and Nested Classes in Java
 
Generics
GenericsGenerics
Generics
 

Similaire à Networking

Similaire à Networking (20)

Basic Networking in Java
Basic Networking in JavaBasic Networking in Java
Basic Networking in Java
 
Servlet
ServletServlet
Servlet
 
Java networking programs - theory
Java networking programs - theoryJava networking programs - theory
Java networking programs - theory
 
Java seminar.pptx
Java seminar.pptxJava seminar.pptx
Java seminar.pptx
 
Networking in java
Networking in javaNetworking in java
Networking in java
 
Socket
SocketSocket
Socket
 
Java 1
Java 1Java 1
Java 1
 
Java RMI
Java RMIJava RMI
Java RMI
 
Module 1 networking basics-2
Module 1   networking basics-2Module 1   networking basics-2
Module 1 networking basics-2
 
Java
JavaJava
Java
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
WebSockets - Realtime em Mundo Conectado
WebSockets - Realtime em Mundo ConectadoWebSockets - Realtime em Mundo Conectado
WebSockets - Realtime em Mundo Conectado
 
Web Dev 21-01-2024.pptx
Web Dev 21-01-2024.pptxWeb Dev 21-01-2024.pptx
Web Dev 21-01-2024.pptx
 
OpenStack Identity - Keystone (liberty) by Lorenzo Carnevale and Silvio Tavilla
OpenStack Identity - Keystone (liberty) by Lorenzo Carnevale and Silvio TavillaOpenStack Identity - Keystone (liberty) by Lorenzo Carnevale and Silvio Tavilla
OpenStack Identity - Keystone (liberty) by Lorenzo Carnevale and Silvio Tavilla
 
Servlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIServlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, API
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
Java networking
Java networkingJava networking
Java networking
 
RESTing with JAX-RS
RESTing with JAX-RSRESTing with JAX-RS
RESTing with JAX-RS
 
Java EE 7 in practise - OTN Hyderabad 2014
Java EE 7 in practise - OTN Hyderabad 2014Java EE 7 in practise - OTN Hyderabad 2014
Java EE 7 in practise - OTN Hyderabad 2014
 
PPT for Seminar.pptx
PPT for Seminar.pptxPPT for Seminar.pptx
PPT for Seminar.pptx
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Dernier (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Networking

  • 1. Advanced Java Programming Topic: Networking By Ravi Kant Sahu Asst. Professor, LPU
  • 2. Contents       Network Basics Client-Server Architecture Sockets Networking classes and Interfaces Network Protocols Java Mail API Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 3. Basics of NetworkiNg Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 4. Network basics  Transmission Control Protocol (TCP) - Connection-Oriented - Reliable TCP is a connection-based protocol that provides a reliable flow of data between two computers.  User Datagram Protocol (UDP) - Connectionless - Unreliable UDP is a protocol that sends independent packets of data, called datagrams, from one computer to another with no guarantees about arrival. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 5. Network basics  Internet Protocol (IP) IP is a low level protocol for delivering data from one computer to another across the internet in packets.  IP address uniquely identifies the computer on Internet.  DNS (Domain Name Server) translates the host name into IP address. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 6. Understanding Ports  Data transmitted over the Internet is accompanied by addressing information that identifies the computer and the port for which it is destined.  The computer is identified by its 32-bit IP address, which IP uses to deliver data to the right computer on the network.  Ports are identified by a 16-bit number, which TCP and UDP use to deliver the data to the right application.  Port number ranges from 0 to 65536 but 0 to 1024 are reserved. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 7. Client-Server Architecture Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 8. Client-Server Architecture  Network Programming involves a Server and one or more Clients.  Client attempts to establish a connection with the Server.  The server can accept or deny the connection.  Once the connection is established, Client sends requests to the server and server responds.  The communication takes place through Sockets. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 9. Sockets  Sockets are the endpoints of logical connection between two hosts and used to send and receive data.  Used to implement reliable, bidirectional, persistent, pointto-point, stream-based connections between hosts on the Internet.  There are two kinds of TCP sockets in Java. - Socket - ServerSocket Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 10. ServerSocket  ServerSocket is for servers.  To establish a server, we need to create a ServerSocket.  ServerSocket is attached to a port where the Server listens for the connection.  accept() method is defined in ServerSocket class which is a blocking call that will wait for a client to initiate. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 11. ServerSocket Constructors Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 12. Socket  The Socket class is for clients.  It is designed to connect to server sockets and initiate protocol exchanges. Socket(String hostName, int port)throws UnknownHostException, IOException Socket(InetAddress ipAddress, int port) throws IOException Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 13. Socket Methods Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 14. Socket Methods  connect( ) allows us to specify a new connection  isConnected( ) returns true if the socket is connected to a server  isClosed( ) returns true if the socket is closed. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 15. InetAddress Class  InetAddress class is used to find the client’s host name and IP address. Example: Socket s = new Socket(“172.19.2.250”, 8000); Socket s = new Socket(“lpu.co.in”, 8000); InetAddress ia = s.getInetAddress(); InetAddress ia = InetAddress.getByName(“lpu.co.in”); Methods: ia.getHostName(); ia.getHostAddress(); Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 16. Serving Multiple ClientS Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 17. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 18. Multiple Clients  Multiple clients can be connected to a server.  A server can serve multiple clients simultaneously.  The connection to each client is handled by one thread. while (true) { Socket socket = serverSocket.accept(); Thread thread = new ThreadClass(socket); thread.start(); } Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 19. Applet Clients Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 20. Applet Clients  The client can be an applet that connects to the server running on the host from which the applet is loaded.  HTML file must be located on the machine on which the server is running.  Server’s host name can be obtained by invoking getCodeBase().getHost() on an applet. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 21. Sending and Receiving Objects  Similar to the data of primitive types, we can send and receive the Objects.  ObjectOutputStream and ObjectInputStream is used for sending and receiving the objects on socket streams.  We can pass only serializable objects. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 22. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 23. Java Mail API  JavaMail is an API that is used to compose, write and read electronic messages.  The JavaMail API provides platform independent framework for sending and receiving mails.  The javax.mail and javax.mail.activation packages contains the core classes of JavaMail API. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 24. Steps to send email using JavaMail API    Get the session object. Compose the message Send the message Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 25. Steps to send email using JavaMail API 1. Get the session object  The javax.mail.Session class provides two methods to get the object of session public static Session getDefaultInstance( Properties props) public static Session getDefaultInstance( Properties props, Authentication auth) public static Session getInstance( Properties props) public static Session getInstance( Properties props, Authentication auth) Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 26. Steps to send email using JavaMail API 2. Compose the message  The javax.mail.Message class provides methods to compose the message.  But it is an abstract class so its subclass javax.mail.internet.MimeMessage class is mostly used. public MimeMessage (Session s) public void setFrom(Address address) public void addRecipients(Message.RecipientType type, String addresses) public void setSubject( String sub) public void setText( String msg) Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 27. Steps to send email using JavaMail API 3. Send the message  The javax.mail.Transport class provides method to send the message. public static void send(Message message) public static void send(Message message, Address [] address) Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)