Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
RESTful Web Services
Next article icon

Java Web Services

Last Updated : 24 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The services that are accessible across various networks are Java Web Services. Since JavaEE 6, it has two APIs defined by Java for creating web services applications.

  • JAX-WS for SOAP web services
  • JAX-RS for RESTful web services.

It is not necessary to add any jars in order to work with either of these APIs because they both use heavy annotations and are included in the standard JDK.

JAX-WS

The Jakarta EE API, known as JAX-WS, is used to develop and create web services, especially for SOAP service users. The development and deployment of web services clients and endpoints are made simpler by using annotations.

Two ways to write JAX-WS application code are:

  • RPC Style
  • Document Style

NOTE: JAX-RPC API was superseded by JAX-WS 2.0.

JAX-RS

JAX-RS is a framework for building RESTful web applications. Currently, there are two implementations for building JAX-RS :

  • Jersey
  • RESTeasy

Implementation of Java Web Services

1. Implementing SOAP Web Services with JAX-WS

There are certain steps to implement SOAP Web Services with JAX-WS

  1. First, you need to define Service endpoint interfaces (SEI) which specify the methods to expose as web service.
  2. Next, you need to implement SEI with a Java class.
  3. Then you need to Annotate the SEI and its implementation class with JAX-WX annotations to specify the web service details.
  4. Package web service classes to the WAR file and deploy it to a web server.

2. Implementing RESTful Web Services with JAX-RS

There are certain steps to implement RESTful Web Services with JAX-RS

  1. First you need to define the resources that represents the web services and its methods.
  2. Then you need to annotate the resource class and its methods with JAX-RS annotations to specify the web service package.
  3. At last we need to package the web service classes to the WAR file and deploy it to a web server.

Examples of Java Web Services

This is an example of how we can use JAX-WS to create a Java Web Service (JWS) using the data from the search results.

1. The SEI (Service Endpoint Interface), which shows the procedures of web services

Java
import javax.jws.WebMethod; import javax.jws.WebService;  @WebService public interface HelloWorld {     @WebMethod     String sayHello(String name); } 

2. Implement the SEI with java class

Java
import javax.jws.WebService;  @WebService(endpointInterface = "com.example.HelloWorld") public class HelloWorldImpl implements HelloWorld {     public String sayHello(String name) {         return "Hello " + name + "!";     } } 

3. Annotate the SEI and it's implementation class with JAX-WX annotations to specify the web services.

Java
import javax.jws.WebMethod; import javax.jws.WebService;  @WebService public interface HelloWorld {     @WebMethod     String sayHello(String name); }  import javax.jws.WebService;  @WebService(endpointInterface = "com.example.HelloWorld") public class HelloWorldImpl implements HelloWorld {     public String sayHello(String name) {         return "Hello " + name + "!";     } } 

Next Article
RESTful Web Services
author
omprakashkumawat1313
Improve
Article Tags :
  • Java
  • Geeks Premier League
  • Java-Networking
  • Geeks Premier League 2023
Practice Tags :
  • Java

Similar Reads

  • What are Web Services?
    The Internet is the worldwide connectivity of hundreds of thousands of computers of various types that belong to multiple networks. On the World Wide Web, a web service is a standardized method for propagating messages between client and server applications. A web service is a software module that i
    10 min read
  • RESTful Web Services
    REST or Representational State Transfer is an architectural style that can be applied to web services to create and enhance properties like performance, scalability, and modifiability. RESTful web services are generally highly scalable, light, and maintainable and are used to create APIs for web-bas
    5 min read
  • Applications of Web Services
    Web services are provided by various software and services that enable people to interact and communicate across the internet. Web services are typically composed of various languages and can still communicate with one another. A client sends a request to a web service, which then responds with an X
    14 min read
  • Servlet - Web Application
    Servlets are the Java programs that run on the Java-enabled web server or application server. They are used to handle the request obtained from the webserver, process the request, produce the response, then send a response back to the webserver Working With Servlets Working with Servlets is an impor
    7 min read
  • Java ServerSocket Class
    ServerSocket Class in Java provides a system-independent way to implement the server side of a client/server socket connection. The constructor for ServerSocket throws an exception if it can’t listen on the specified port (for example, the port is already being used). In the java.nio channel, Server
    4 min read
  • Operating System Services
    An operating system is software that acts as an intermediary between the user and computer hardware. It is a program with the help of which we are able to run various applications. It is the one program that is running all the time. Every computer must have an operating system to smoothly execute ot
    6 min read
  • Web Services in Cloud Computing
    Cloud computing web services are one of the integral parts of the modern Internet. They assist in getting in touch through various applications or systems with one another for the interchange of data and sharing functionalities with the help of the Internet medium. With the advent of technologies in
    11 min read
  • SimpleFileServer in Java
    A server is a computer that is dedicated solely to the purpose of serving. It serves files to its clients whenever requests are made, and it should always be available. A program running on a port within the server is used to handle requests. The term 'server' can refer to a physical or virtual comp
    7 min read
  • Services in Android with Example
    Services in Android are a special component that facilitates an application to run in the background in order to perform long-running operation tasks. The prime aim of a service is to ensure that the application remains active in the background so that the user can operate multiple applications at t
    10 min read
  • Service Client Module in Java
    A Client Module in Java is a set of classes and methods that are used to connect to, interact with, and consume services from a server. It is the front-end component of a client/server architecture. It is typically responsible for initiating communication with the server, sending and receiving data,
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences