Java Programming Language: A Complete Beginner’s Guide

What is Java ?

  • Java programming language is a high-level object oriented, robust, secure platform, independent high-performance and portable programming language.
  • It was developed by Sun Microsystems (presently a subsidiary of Oracle) in 1995, James Gosling is considered the father of this language. At first named Oak, it was afterward rebranded to Java after Oak was as of now enrolled by another company.
  • It is also known as a platform as it provides its own GRE and API.

History of Java Programming Language:

  • The Java programming language, at first known as Oak, was made in 1991 by James Gosling and his group at Sun Microsystems.
  • It was rebranded as Java in 1995, motivated by the team’s affection for Java coffee.
  • This rebranding reflected its key reasoning: “Write Once, Run Anyplace” (WORA). By utilizing the Java Virtual Machine (JVM), it accomplished platform independence, stamping a major breakthrough within the program improvement industry.
  • The release of Java 2 brought noteworthy updates, including J2SE, J2EE, and J2ME versions, for desktop, enterprise, and portable applications.
  • Oracle Corporation’s securing of Sun Microsystems in 2009 advance moved its evolution, introducing features such as Generics, Lambda Expressions, and the Stream API in Java 8.
  • Today, this language powers frameworks like Spring Boot, Android development, and microservices architecture, solidifying its importance in modern software engineering.

Java example:

Here is a simple example that demonstrates a basic hello world program,

HelloWorld.java

class HelloWorld{

public static void main(String args[]){

System.out.println(“Hello World”);

}

}

Save the above file as HelloWorld.java

To compile:javac HelloWorld.java
To execute:java HelloWorld

 

Output:

Hello World

Explanation:

  • Class Declaration: A class is declared with the name HelloWorld. Every program in this language must include at least one class.
  • Main Method: The entry point for any program. It’s where execution starts.
  • System.out.println: This statement prints text to the console.

 

Compilation Flow:

When the program is compiled utilizing the javac tool, the source code is transformed into bytecode, which can be run on any platform that supports JVM.

Java How to Compile

 

Features of Java Programming Language

C++ vs Java:

Here’s a concise comparison between C++ and Java:

FeatureC++Java
Platform DependencyPlatform-dependent: Compiled code runs only on the same platform.Platform-independent: Uses JVM (Java Virtual Machine) for “Write Once, Run Anyplace” (WORA).
Programming ParadigmSupports both procedural and object-oriented programming.Absolutely object-oriented, but supports a few primitive types (e.g., int, char).
Memory ManagementManual memory management using pointers and delete/new.Automatic memory management using garbage collection.
PointersFully supports pointers, allowing direct memory manipulation.No direct pointer support (for security and simplicity).
CompilationCompiles directly to machine code, making it faster for some applications.Compiles to bytecode, which is interpreted by the JVM.
InheritanceSupports multiple inheritance using classes (with the risk of ambiguity).No multiple inheritance with classes (uses interfaces to achieve similar functionality).
Operator OverloadingSupports operator overloading for flexibility.Does not support operator overloading.
Templates vs GenericsUses templates for generic programming.Uses generics for type-safe programming.
Exception HandlingPartially supports exception handling, and it’s optional.Strongly enforces exception handling (e.g., try-catch blocks for checked exceptions).
Standard LibraryProvides STL (Standard Template Library) for data structures and algorithms.Provides a rich API with extensive libraries (e.g., Collections Framework, I/O, Networking).
Application DomainsWidely used for system-level programming, game development, and performance-critical apps.Commonly used for enterprise applications, Android apps, and web development.

Summary:

  • C++: Offers more control (e.g., with pointers and manual memory management), making it perfect for system programming and performance-critical applications.
  • Java: Focuses on simplicity, portability, and security, making it a stronger choice for cross-platform development and large-scale enterprise applications.

 

C++ Program Example

File: main.cpp

#include <iostream>

using namespace std;

int main() {

cout << “Hello C++ Programming”;

return 0;

}

Output:

Hello C++ Programming

Java Program Example:

File: Simple.java

class Simple{  

public static void main(String args[]){

System.out.println(“Hello User,Good Morning!!!”);

}

}

Output:

Hello User,Good Morning!!!

Why Java is not 100% object oriented programming language?

It is not 100% object oriented programming language because, it makes use of 8 primitive data types such as int,char, float, double, long,short,byte, boolean which are not object.

Why Java is platform independent programming language?

It is a platform independent programming language because of its byte code which can run on any system irrespective of its underlying OS.

 

Leave a Comment