Skip to content
Home » Blog » Java Basics: Installation, JDK vs JVM, and Writing Your First Program

Java Basics: Installation, JDK vs JVM, and Writing Your First Program

Java is one of the most powerful programming languages. It is also one of the most versatile in the world. It’s a great choice for building a strong foundation in programming. Whether you’re new to coding or preparing for FAANG interviews, mastering Java Basics will set you on the right path.

In this blog, we’ll start with the basics of Java, including how to install it, the key differences between JDK and JVM, and writing your first Java program. In upcoming posts, we’ll dive deeper into topics like variables, data types, loops, and functions. This will build a solid foundation for your coding journey.


1. Installing Java: Setting Up Your Development Environment

Before diving into coding, you need to install Java on your machine. Java programs run on the Java Virtual Machine (JVM), which interprets the compiled code and allows it to run on any platform that supports Java. The Java Development Kit (JDK) provides tools needed to develop and execute Java programs, including the compiler that converts your code into machine language.

Steps to Install Java:

  1. Download JDK: Visit the Oracle website and download the latest version of JDK.
  2. Install JDK: Follow the installation instructions specific to your operating system.
  3. Set Up Environment Variables: After installation, make sure to set up the JAVA_HOME environment variable so your system can recognize the location of the JDK.
  4. Install an IDE: An Integrated Development Environment (IDE) simplifies coding in Java. Popular IDEs include IntelliJ IDEA, Eclipse, and NetBean. I recommend Using Visual Studio Code by Microsoft

Once installed, test the setup by running this command in your terminal or command prompt:

java -version
Java

This will display the version of Java installed on your machine.


2. Difference Between JDK and JVM: Why You Need Both

It’s important to understand the roles of JDK and JVM in Java development.

  • Java Development Kit (JDK): The JDK is a software development kit that includes everything you need to develop Java applications, such as the Java compiler, libraries, and documentation. The JDK is used by developers to write and compile Java programs.
    • (more about [JDK] comming soon)
  • Java Virtual Machine (JVM): The JVM is a runtime environment that executes Java bytecode. When you compile a Java program, the code is converted into bytecode that can be executed by the JVM, making it platform-independent.
    • (more about [JVM] comming soon)

In summary, the JDK is essential for writing and compiling code, while the JVM is necessary for running the compiled code on your machine.


3. Writing Your First Java Program

Now that you have Java installed, let’s write a simple Java program. Open your IDE and create a new Java project. In the main class file, write the following code:

// Your First Java Program: Hello World
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
Java

Explanation:

  • public class HelloWorld: This defines a class (more about [Classes] coming soon) named HelloWorld. In Java, every program must have at least one class.
  • public static void main(String[] args): This is the main method, the entry point of the program (more about [main method]) coming soon).
  • System.out.println(“Hello, World!”): This prints “Hello, World!” to the console.

Once you run this program, you should see the output: “Hello, World!” This is the classic starting point for learning any programming language.


4. Java Basics : Upcoming Topics

In the next posts, we’ll dive deep into the following Java basics:

  • Variables and Data Types
  • Conditional Statements
  • Loops
  • Functions and Methods

Each of these topics will help you build a stronger understanding of Java, preparing you for more advanced topics like Object-Oriented Programming (OOP) and Data Structures and Algorithms (DSA).


Conclusion

In this post, we covered the essential steps to get started with Java, including installation, understanding the differences between JDK and JVM, and writing your first Java program. As we move forward, we’ll explore Java’s core features in more detail, helping you build a strong foundation for your FAANG preparation.

Stay tuned for the next post, where we’ll dive deeper into Java’s variables and data types! till then don’t forget to check out these

Check out More here and don’t forget to Subscribe


Discover more from Lets Crack Faang

Subscribe to get the latest posts sent to your email.

Leave a Reply

Your email address will not be published. Required fields are marked *

Discover more from Lets Crack Faang

Subscribe now to keep reading and get access to the full archive.

Continue reading