What is java?
Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995. It is mostly used for building desktop applications, web applications, Android apps, and enterprise systems.
why use java?
- Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.)
- It is one of the most popular programming languages in the world
- It has a large demand in the current job market
- It is easy to learn and simple to use
- It is open-source and free
- It is secure, fast and powerful
- It has huge community support (tens of millions of developers)
- Java is an object oriented language which gives a clear structure to programs and allows code to be reused, lowering development costs
- As Java is close to C++ and C#, it makes it easy for programmers to switch to Java or vice versa
Object-Oriented Programming (OOP): Java supports OOP concepts to create modular and reusable code.
Platform Independence: Java programs can run on any operating system with a JVM.
Robust and Secure: Java ensures reliability and security through strong memory management and exception handling.
Multithreading and Concurrency: Java allows concurrent execution of multiple tasks for efficiency.
Rich API and Standard Libraries: Java provides extensive built-in libraries for various programming needs.
Frameworks for Enterprise and Web Development: Java supports frameworks that simplify enterprise and web application development.
Open-Source Libraries: Java has a wide range of libraries to extend functionality and speed up development.
Maintainability and Scalability: Java’s structured design allows easy maintenance and growth of applications.
Understanding the Hello World Program in Java
// A Java program to print Hello World!
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Output:
Hello World!
- // Starts a single-line comment. The comment is not executed by Java.
- public class HelloWorld defines a class named HelloWorld. In Java, every program must be inside a class.
- public static void main(String[] args) is the entry point of any Java application. It tells the JVM where to start executing the program.
- System.out.println("Hello, World!"); prints the message to the console.
In Java, every application begins with a class name, and that class must match the filename.
How to run the above code?
- Write code in a file like HelloWorld.java.
- The Java Compiler "javac" compiles it into bytecode "HelloWorld.class".
- The JVM (Java Virtual Machine) reads the .class file and interprets the bytecode.
- JVM converts bytecode to machine readable code i.e. "binary" (001001010) and then execute the program.
Comments in Java
The comments are the notes written inside the code to explain what we are doing. The comment lines are not executed while we run the program.
Single-line comment
// This is a comment
Multi-line comment
/*
This is a multi-line comment.
This is useful for explaining larger sections of code.
*/


Top comments (0)