Open In App

Java File Format | .java Extension

Last Updated : 29 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Java is a high-level, object-oriented programming language. A source code file written in the Java programming language is saved with the extension .java. .Java file extension typically contains Java code that can be compiled into bytecode and executed on the Java Virtual Machine (JVM). The Sun microsystem developed it. It is a platform-independent programming language. It is used to develop Android applications, web applications, artificial intelligence, cloud applications, and much more.

Brief History

  • Java, designed by James Gosling and Mike Sheridan, originated at Sun Microsystems in the early 1990s. Java made its public debut in 1995 with the release of Java 1.0. This version included many features that are still fundamental to Java today.
  • Java 2, released in 1998, introduced significant enhancements, including the Swing GUI toolkit, the Collections Framework, and the addition of the assert keyword.
  • Java SE 7 (2011) and Java SE 8 (2014) brought significant language enhancements, including introducing the try-with-resources statement, the diamond operator, lambda expressions, and the Stream API.
  • Java SE 9, released in 2017, introduced the module system as part of Project Jigsaw. Java remains one of the most popular and widely used programming languages globally. It powers a vast array of applications, from mobile and web development to enterprise systems and embedded devices.

Features of the java

  • Platform Independence: Java programs can run on any device that has a Java Virtual Machine (JVM). This “Write Once, Run Anywhere” (WORA) capability is achieved by compiling Java source code into an intermediate bytecode that can be executed on any system with a compatible JVM.
  • Object-Oriented: Java follows the principles of object-oriented programming (OOP), including encapsulation, inheritance, and polymorphism. This allows for modular and organized code development.
  • Simple and Readable: Java’s syntax is designed to be simple, clean, and easy to understand. This contributes to code readability and reduces the likelihood of errors.
  • Robust and Secure: Java’s design includes features for automatic memory management (garbage collection) and strong type-checking, which enhances the robustness of applications.
  • Multi-Threading: Java provides built-in support for multi-threading, allowing developers to create concurrent and parallel applications.
  • Distributed Computing: Java supports the development of distributed applications through Remote Method Invocation (RMI) and Java Message Service (JMS). These features facilitate communication between different components in a network.
  • Dynamic Memory Allocation: Java automatically manages memory allocation and garbage collection, reducing the risk of memory leaks and simplifying memory management for developers.

Syntax of Java

Java




/*package whatever //do not write package name here */
 
import java.io.*;
 
class GFG {
    public static void main (String[] args) {
        System.out.println("GFG!");
    }
}


Explanation:

  • Class Declaration: The program begins with the declaration of a class named GFG using the class keyword.
  • main Method: The main method is the entry point of a Java application.
  • Print Statement: The System.out.println statement is used to print a line to the console.

Output

GFG!

Advantages of Java

  • Java is designed as an object-oriented programming language, promoting the principles of encapsulation, inheritance, and polymorphism.
  • Comes with an extensive and robust standard library (Java API) that provides a wide range of pre-built functions and classes.
  • Features automatic memory management through garbage collection and the virtual machine automatically takes care of memory allocation and deallocation.

Disadvantages of Java

  • In Java, memory is managed by garbage collection; the machine’s display is affected whenever the waste collector operates.
  • Uses a critical or significant amount of memory in comparison to other dialects such as C and C++.
  • In comparison to other languages, it is a slower language because it burns through memories.

Example Code: A simple code to add two numbers

Java




import java.util.Scanner;
 
public class SumCalculator {
    public static void main(String[] args) {
        // Create a Scanner object to read user input
        Scanner scanner = new Scanner(System.in);
 
        // Prompt the user to enter the first number
        System.out.print("Enter the first number: ");
        int num1 = scanner.nextInt();
 
        // Prompt the user to enter the second number
        System.out.print("Enter the second number: ");
        int num2 = scanner.nextInt();
 
        // Calculate the sum of the two numbers
        int sum = num1 + num2;
 
        // Display the result
        System.out.println("The sum of " + num1 + " and " + num2 + " is: " + sum);
 
        // Close the Scanner to avoid resource leak
        scanner.close();
    }
}
 
}


Output:

The sum of 5 and 6 is: 11

Conclusion

In conclusion, Java stands out as a versatile and powerful programming language that has significantly shaped the world of software development. Its “write once, run anywhere” philosophy, object-oriented nature, and extensive library support have made it a favorite among developers. Java’s portability, robustness, and scalability have contributed to its enduring popularity and widespread adoption in various industries. 
 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads