Skip to main content

Socket (TCP & UDP) communication in Java

Socket communication in Java enables communication between two endpoints over a network. There are two main types of sockets: TCP sockets and UDP sockets. Let's explain both types with examples: TCP Socket Communication: 1. **Server Side**:    - The server creates a `ServerSocket` object to listen for incoming connections on a specific port.    - When a client connects, the server accepts the connection and creates a `Socket` object to communicate with the client.    - The server reads from and writes to the socket's input and output streams to communicate with the client. import java.io.*; import java.net.*; public class TCPServer {     public static void main(String[] args) throws IOException {         ServerSocket serverSocket = new ServerSocket(12345);         System.out.println("Server started. Waiting for client...");         Socket clientSocket = serverSocket.accept();         System.out.println("Client connected.");         BufferedReader in = new Bu

Experiment No: 1 - Study of Java Runtime Environment (JRE).

 

Experiment No: 1

 

Aim: Study of Java run time environment (JRE)

Theory: Java is a programming language and a platform. Platform Any hardware or software environment in which a program runs, known as a platform. Since Java has its own Runtime Environment (JRE) and API, it is called platform.


The history of Java is a fascinating journey that began in the early 1990s and continues to shape the modern software development landscape. Here's an overview of the key milestones and events in the history of Java:

  1. Origins (Early 1990s): Java's story begins with a team of engineers at Sun Microsystems, led by James Gosling, Mike Sheridan, and Patrick Naughton. Their goal was to create a programming language that could be used to develop software for consumer electronic devices, such as set-top boxes and interactive television.
  2. Green Project (1991): The project, initially known as the "Green Project," aimed to develop a language that could address the challenges of programming in the rapidly evolving digital landscape. The team's efforts were focused on creating a language that was platform-independent, secure, and easy to use.
  3. Birth of Java (1995): In 1995, Sun Microsystems officially unveiled Java to the world. The language was positioned as a versatile, platform-independent solution for building applications that could run on any device with a Java Virtual Machine (JVM). The release of Java 1.0 marked the beginning of a new era in software development.
  4. Applet Revolution (Mid-1990s): Java gained widespread attention with the introduction of Java applets, which allowed developers to embed interactive content within web pages. Applets promised to revolutionize the way people interacted with the web, offering dynamic and engaging user experiences.
  5. Java 2 Platform (1998): Sun Microsystems released the Java 2 Platform, Standard Edition (J2SE), which introduced significant enhancements and updates to the language and its libraries. Java 2 provided a more robust and feature-rich development environment, laying the groundwork for future innovations.
  6. Enterprise Java (Late 1990s - Early 2000s): Java's popularity continued to grow, particularly in enterprise environments. Technologies like Enterprise JavaBeans (EJB) and JavaServer Pages (JSP) emerged, enabling the development of scalable, distributed, and web-based applications.
  7. Open Sourcing (2006): In a landmark move, Sun Microsystems open-sourced the Java platform under the GNU General Public License (GPL). This decision paved the way for broader adoption of Java and fostered a vibrant ecosystem of developers, contributors, and communities.
  8. Oracle Acquisition (2010): Oracle Corporation acquired Sun Microsystems, becoming the steward of the Java platform. The acquisition raised questions about the future direction of Java and its governance, sparking discussions within the Java community.
  9. Java SE Releases: Over the years, Java has seen numerous releases, each introducing new features, enhancements, and improvements. From Java SE 6 to the latest Java SE 17, the platform has evolved to meet the changing needs of developers and users alike.
  10. Modern Java Ecosystem: Today, Java remains one of the most widely used and influential programming languages in the world. It powers a vast array of applications, from enterprise software and web services to mobile apps and cloud-native solutions. The Java ecosystem continues to thrive, driven by a passionate community of developers and organizations committed to its success.

 

 

·  Types of Java Applications

Java applications can be classified into several types based on their intended use and deployment environment. Here are the main types of Java applications:


  • Standalone Applications (Desktop Applications): Standalone applications, also known as desktop applications or window-based applications, are programs that run locally on a user's computer. They typically have a graphical user interface (GUI) and provide functionality such as word processing, spreadsheet manipulation, media playback, and more. Standalone Java applications are developed using libraries like AWT (Abstract Window Toolkit) or Swing.

  • Web Applications: Web applications are software applications that run on web servers and are accessed by users over the internet through web browsers. Java is widely used for building web applications due to its robustness, security features, and scalability. Technologies like Servlets, JSP (JavaServer Pages), JSF (JavaServer Faces), and Spring MVC are commonly used for developing Java-based web applications.

  • Enterprise Applications: Enterprise applications are large-scale, distributed software systems used by organizations to automate business processes and operations. Java is a popular choice for building enterprise applications because of its platform independence, strong support for distributed computing, and extensive ecosystem of frameworks and libraries. Technologies like EJB (Enterprise JavaBeans), Spring Framework, Hibernate, and JPA (Java Persistence API) are commonly used in Java enterprise development. 

  • Mobile Applications: Mobile applications, also known as mobile apps, are software applications designed to run on mobile devices such as smartphones and tablets. Java is used for developing mobile applications primarily for the Android platform. Android development is done using the Android SDK (Software Development Kit), which includes the Java programming language, along with additional libraries and tools specific to Android app development.

  • Embedded Applications: Embedded applications are software applications that are embedded within hardware devices and perform specific functions. Java is used in embedded systems development due to its portability, reliability, and security features. Embedded Java applications can be found in a wide range of devices, including set-top boxes, smart cards, industrial automation systems, and more.

  • Scientific and Research Applications: Java is also used in scientific and research applications for its versatility, performance, and support for numerical computing. Java libraries such as Apache Commons Math, JScience, and Weka provide tools and algorithms for scientific computing, data analysis, machine learning, and other research-oriented tasks.

 

·  Java Version History

 There are many java versions that has been released. Current stable release of Java is Java SE 21

  1.  JDK Alpha and Beta (1995)
  2. JDK 1.0 (23rd Jan, 1996)
  3. JDK 1.1 (19th Feb, 1997)
  4. J2SE 1.2 (8th Dec, 1998)
  5. J2SE 1.3 (8th May, 2000)
  6. J2SE 1.4 (6th Feb, 2002)
  7. J2SE 5.0 (30th Sep, 2004)
  8. Java SE 6 (11th Dec, 2006)
  9. Java SE 7 (28th July, 2011)
  10. Java SE 8 LTS (18th March, 2014)
  11. Java SE 9 (21st Sep, 2017)
  12. Java SE 10 (20th March, 2018)
  13. Java SE 11 LTS (25th Sep, 2018)
  14. Java SE 12 (19th March, 2019)
  15. Java SE 13 (17th Sep, 2019)
  16. Java SE 14 (17th March, 2020)
  17. Java SE 15 (15th Sep, 2020)
  18. Java SE 16 (16th March, 2021)
  19. Java SE 17 LTS (14th Sep, 2021)
  20. Java SE 18 (22nd March 2022)
  21. Java SE 19 (20th September 2022)
  22. Java SE 20 (21st March 2023)
  23. Java SE 21 LTS (19th September 2023)

 

·  Applications of Java:

  • Web Development
  • Enterprise Software Development
  • Mobile App Development
  • Desktop GUI Applications
  • Embedded Systems
  • Big Data and Analytics
  • Scientific Computing
  • Financial Services
  • Gaming
  • Educational Software

 

·  Features of Java:

  • Simple
  • Object-Oriented
  • Platform independent
  • Secure
  • Robust
  • Architecture neutral
  • Portable
  • Dynamic
  • Interpreted
  • High Performance
  • Multithreaded
  • Distributed 


·  Java Programming Environment and the Java Runtime Environment (JRE)

 What is the Java Programming Environment?

 Java Programming Environment:

The Java programming environment encompasses:


  • Programming Language: Java provides a robust, object-oriented programming language with features inherited from languages like C++ but with enhancements and simplifications.
  • API Specification: Java offers a comprehensive set of APIs (Application Programming Interfaces) covering a wide range of functionalities, allowing developers to build various types of applications.
  • Virtual Machine Specification: The Java Virtual Machine (JVM) specification defines an abstract computing machine that enables Java programs to run on any platform.
Key Characteristics of Java:
  • Object-Oriented: Java follows an object-oriented programming paradigm, allowing developers to model real-world entities as objects and organize code into classes and objects.
  • Architecture Neutral: Java source code is compiled into architecture-independent bytecode, which can run on any platform with a compatible JVM.
  • Portable: Java's bytecode can be executed on any platform with a JVM, making Java applications highly portable across different operating systems and hardware architectures.
  • Secure: Java incorporates various security features such as bytecode verification, sandboxing, and access control mechanisms to ensure the safety of executing code.
  • Robust: Java's strong memory management, exception handling, and type safety mechanisms contribute to its robustness, reducing the likelihood of runtime errors and crashes.
  • High Performance: Java offers high-performance execution through features like Just-In-Time (JIT) compilation, which dynamically translates bytecode into native machine code for efficient execution.
  • Multithreaded: Java provides built-in support for multithreading, allowing concurrent execution of multiple threads within a single Java application.
  • Distributed: Java facilitates the development of distributed applications with extensive networking capabilities and support for technologies like Remote Method Invocation (RMI) and Java Remote Method Protocol (JRMP).

Java Runtime Environment (JRE):

What is JRE?

Java Run-time Environment (JRE) is the part of the Java Development Kit (JDK). It is a freely available software distribution which has Java Class Library, specific tools, and a stand-alone JVM. It is the most common environment available on devices to run java programs. The source Java code gets compiled and converted to Java bytecode. If you wish to run this bytecode on any platform, you require JRE. The JRE loads classes, verify access to memory, and retrieves the system resources. JRE acts as a layer on the top of the operating system.

It also includes:

  • Technologies which get used for deployment such as Java Web Start.
  • Toolkits for user interface like Java 2D.
  • Integration libraries like Java Database Connectivity (JDBC) and Java Naming and Directory Interface (JNDI).
  • Libraries such as Lang and util.
  • Other base libraries like Java Management Extensions (JMX), Java Native Interface (JNI) and Java for XML Processing (JAX-WS).

What does JRE consist of?

JRE consists of the following components:

  • Deployment technologies such as deployment, Java plug-in, and Java Web Start.
  • User interface toolkits, including Abstract Window Toolkit (AWT), Swing, Java 2D, Accessibility, Image I/O, Print Service, Sound, drag, and drop (DnD) and input methods.
  • Integration libraries including Interface Definition Language (IDL), Java Database Connectivity (JDBC), Java Naming and Directory Interface (JNDI), Remote Method Invocation (RMI), Remote Method Invocation Over Internet Inter-Orb Protocol (RMI-IIOP) and scripting.
  • Other base libraries, including international support, input/output (I/O), extension mechanism, Beans, Java Management Extensions (JMX), Java Native Interface (JNI), Math, Networking, Override Mechanism, Security, Serialization and Java for XML Processing (XML JAXP).
  • Lang and util base libraries, including lang and util, zip, Java Archive (JAR), instrument, reflection, Collections, Concurrency Utilities, management, versioning, Logging, Preferences API, Ref Objects and Regular Expressions.
  • Java Virtual Machine (JVM), which comprise of Server Virtual Machine and Java HotSpot Client.

How does JRE work with JVM?


JRE has an instance of JVM with it, library classes and development tools. To understand the working of JRE let us see an example of a simple "Hello World" program.



import java.util.*
public static void main(String[] args){
System.out.println(?Hello world?);
}

Once you write this program, you have to save it with .java extension. Compile your program. The output of the Java compiler is a byte-code which is platform independent. After compiling, the compiler generates a .class file which has the bytecode. The bytecode is platform independent and runs on any device having the JRE. From here, the work of JRE begins. To run any Java program, you need JRE. The flow of the bytecode to run is as follows:


The following steps take place at runtime:

  • Class Loader
    At this step, the class loader loads various classes which are essential for running the program. The class loader dynamically loads the classes in the Java Virtual Machine.
    When the JVM is started, three class loaders are used:
    1. Bootstrap class loader
    2. Extensions class loader
    3. System class loader
  • Byte code verifier
    Byte code verifier can be considered as a gatekeeper. It verifies the bytecode so that the code doesn't make any sort of disturbance for the interpreter. The code is allowed to be interpreted only when it passes the tests of the Bytecode verifier which checks the format and checks for illegal code.
  • Interpreter
    Once the classes get loaded and the code gets verified, then interpreter reads the assembly code line by line and does the following two functions:
  • Execute the Byte Code
  • Make appropriate calls to the underlying hardware

In this way, the program runs in JRE.


Additional oral questions:

  1. What is the Java programming environment?
  2. Describe the key components of the Java Runtime Environment (JRE).
  3. What is the Java Virtual Machine (JVM), and what role does it play in the Java ecosystem?
  4. How does Java achieve platform independence?
  5. Explain the concept of bytecode and its significance in Java.
  6. What are the main characteristics of the Java programming language?
  7. Discuss the role of class libraries in the Java Runtime Environment.
  8. Describe the process of compiling and executing a Java program.
  9. Explain the difference between the Java Development Kit (JDK) and the Java Runtime Environment (JRE).
  10. Discuss the significance of the Java platform in modern software development.


Conclusion:

 In this experiment we studied JRE, JDK, and creation and execution of java file.

 

Comments

Post a Comment

Popular posts from this blog

Method Overloading in Java

Method Overloading in Java Method Overloading  is a feature in Java that allows a class to have multiple methods with the same name but different parameter lists. The methods can have a different number or types of parameters. The decision on which method to invoke is made by the compiler based on the arguments provided during the method call.  Example: public class Calculator {     // Method to add two integers     public int add(int a, int b) {         return a + b;     }     // Method to add three integers     public int add(int a, int b, int c) {         return a + b + c;     }     // Method to add two doubles     public double add(double a, double b) {         return a + b;     }     // Method to concatenate two strings     public String concatenate(String str1, String str2) {         return str1 + str2;     } } Method Overloading in Action: public class Main {     public static void main(String[] args) {         Calculator calculator = new Calculator();         // Overloaded meth

Java Runtime Environment (JRE)

Definition : Java Runtime Environment (JRE) is a set of software tools and libraries that enables the execution of Java applications. It provides the necessary runtime support for Java programs to run on various devices and platforms. Components of Java Runtime Environment (JRE): Java Virtual Machine (JVM): Definition: The JVM is a crucial component of the JRE responsible for executing Java bytecode. Functionality: It interprets Java bytecode or, in some cases, uses Just-In-Time (JIT) compilation to translate bytecode into native machine code for improved performance. Importance: JVM abstracts the underlying hardware, allowing Java programs to be platform-independent. Class Libraries: Definition: JRE includes a set of precompiled classes and methods that Java applications can utilize. Functionality: These classes cover a wide range of functionalities, from basic data structures to networking. Importance: Class libraries provide a foundation for developers, offering reusable code