What is Java?

Java Technology – Beginner Explanation

Java is both:

  • a programming language, and
  • a platform.

This means Java is used to write programs and also provides an environment to run those programs.


Java Software Distributions

Java software is available in different forms, depending on your need.


JRE (Java Runtime Environment)
  • JRE is required to run Java programs
  • It includes:
    • JVM (Java Virtual Machine)
    • Core Java libraries
  • JRE is mainly used by end users
  • If you only want to run a Java application, JRE is enough

JDK (Java Development Kit)
  • JDK is required to write and compile Java programs
  • It includes:
    • JRE
    • Java Compiler
    • Other development tools
  • JDK is mainly used by Java developers

In simple words:

  • JRE → Run Java programs
  • JDK → Write + Compile + Run Java programs

Java Distributions from Oracle

Oracle provides Java in the following editions:

1. JDK (Java Development Kit)
  • Used by Java developers
  • Includes:
    • Complete JRE
    • Tools for developing, debugging, and monitoring Java applications

2. Server JRE (Server Java Runtime Environment)
  • Used for server-side applications
  • Includes:
    • JVM
    • Server-related monitoring tools
  • Does not include:
    • Browser plug-in
    • Auto-update
    • Installer
  • Mainly used on servers, not on personal computers

3. JRE (Java Runtime Environment)
  • Used by end users
  • Contains everything required to run Java applications
  • Suitable for systems where development is not required

Important Java Concepts
  • Bytecode
    Java programs are compiled into bytecode, not directly into machine code.
  • JVM (Java Virtual Machine)
    JVM executes the bytecode and makes Java platform-independent
    (Write Once, Run Anywhere)

What is Servlet and Servlet Container?

Servlet – Beginner Explanation

Servlet (or Java Servlet) is a basic technology used to develop web applications in Java.

A Servlet is a Java class that runs on a special environment called a Servlet Container.

Important points about Servlets:

  • Servlets do not have a main() method
  • They are not executed directly
  • They are controlled and managed by another Java program called a Servlet Container

Servlet Application

A Servlet application usually contains:

  • One or more Servlets
  • One or more JSP (JavaServer Pages)

A JSP page is internally:

  • Translated into a Servlet
  • Then compiled and executed

Because of this, a web application can also be called a:

  • Servlet application
  • JSP application
  • Servlet/JSP application

All mean the same thing.


Servlet Container

A Servlet Container is like a web server, but with extra features.

A normal web server:

  • Serves only static content
    (HTML, CSS, images)

A Servlet Container:

  • Serves static content
  • Also generates dynamic content
  • Can execute Servlets and JSP pages

Because of this, a Servlet Container is also called:

  • Servlet Engine
  • Servlet/JSP Container

Role of Servlet Container

The Servlet Container works as a middle layer between the user and the Servlet application.

It does the following:

  • Receives requests from the user (browser)
  • Passes the request to the Servlet
  • Receives the response from the Servlet
  • Sends the response back to the user

Objective of a Servlet

The main purpose of a Servlet is to:

  1. Read data sent by the client
    (for example: form data)
  2. Process the data and generate a result
  3. Send the result back to the client
    (for example: HTML output)

In simple words:
Servlet = takes request → processes data → sends response

Basic Terms Before Diving into Web Development

Network

A network is a collection of two or more computers connected to each other.

We create a network to:

  • Share system resources (printer, files, internet)
  • Exchange information

Each computer in a network is called a node.

The Internet is called a network of networks.


Client

A client is a computer that requests information.

Example:

  • Your computer or mobile phone when you open a website


Server

A server is a computer that stores information or provides services to clients.

Types of servers include:

  • Database server
  • File server
  • Movie server
  • Internet server
  • Printer server

IP Address

In a network, every device is identified using an IP Address.

An IP Address is a unique number given to a computer or device.


Port

A port number is used to identify a specific application running on a server. Port numbers range from 0 to 65535, and some of these ports are reserved for well-known services.


Browser

A browser is a software used to open and navigate websites.

Examples of browsers:

  • Microsoft Internet Explorer
  • Mozilla Firefox
  • Google Chrome
  • Opera
  • Safari

A browser is also called a web client.

When you open a website in a browser, the browser acts as the actual client.


Web Server

A Web Server is a type of software that serves web resources.

Web servers mainly serve static resources, such as:

  • .html
  • .css
  • .js
  • Images

Every resource on the web has a unique address, called a URL.

When a user requests a web page through a browser:

  • The browser sends a request
  • The web server sends the response

Ways to Request a Resource

A resource can be requested in the following ways:

  • Enter a URL in the browser address bar
  • Click a hyperlink on a web page
  • Fill a form and click the submit button
  • Send a request using a program

The format of a request is IP_address:Port_number


HTTP Request and Response
  • A request sent by the browser is called an HTTP Request
  • A reply sent by the server is called an HTTP Response

Types of Web page

Static Web page
  • Does not take input from users
  • No database, file handling, or XML is used
  • Looks the same for all users

Example:

  • about page, history page, policy page etc.

Dynamic Web page
  • Takes input from users
  • Stores data using database, file handling, or XML
  • Looks different for different users

Example:

  • Gmail, Facebook

If 5 users open Gmail:

  • Each user sees a different inbox

HTTP (HyperText Transfer Protocol)

The Web Server and Web Client (Browser) communicate using HTTP.

Because of this:

  • A Web Server is also called an HTTP Server

HTTP allows:

  • Browsers and servers to exchange data
  • Communication over the Internet or an Intranet

Important points:

  • A Web Server runs 24×7
  • The client always starts the communication
  • A server never contacts a client directly

Localhost

Localhost refers to the same computer you are working on. In other words, it refers to the same system from which a request is made.

The IP address for localhost is 127.0.0.1
An internet connection is not required to run localhost.

We usually use localhost to test websites on our computer. Sometimes, we use localhost in coding to connect to a database server that is running on the same computer.