Introduction to Java: for Beginners

Melody Mbewe - Oct 4 - - Dev Community

Introduction to Java

What is Java?

Java is a versatile, object-oriented programming language first released by Sun Microsystems in 1995. It's designed to be platform-independent, following the principle of "Write Once, Run Anywhere" (WORA). This means that Java code can run on any device or operating system that has a Java Virtual Machine (JVM) installed, without needing to be recompiled.

Image description

History
In June 1991, a small team of engineers at Sun Microsystems led by James Gosling (along with Mike Sheridan and Patrick Naughton) started a project called Green. This is to develop a programming language for small electronic devices such as television, setup-box, etc.

Image description

In 1993, the HTTP protocol and Mosaic browser arrived which made them to develop the language for the internet.

In 1995, they developed a browser named Webrunner which is capable of showing HTML content mixed with applets. Sun Microsystems officially announced Java at the SunWorld conference and Netscape agreed to include Java support in their popular Netscape Navigator browser.

In 2009, Sun Microsystems was bought by Oracle. It was initially named 'OAK' after an oak tree that stood outside his office. Then, it was renamed to 'JAVA' as the 'OAK' trademark was already used by Oak Technology.

Key features of Java include:

  1. Object-oriented: Java is built around the concept of "objects" that contain data and code.
  2. Platform independence: Java code can run on any platform with a JVM.
  3. Security: Java has built-in security features and a robust security framework.
  4. Multi-threaded: Java supports concurrent programming, allowing multiple threads to run simultaneously.
  5. Large standard library: Java comes with a comprehensive set of standard libraries and APIs.

Java is widely used for developing enterprise-level applications, Android mobile apps, web applications, and more.

Setting up Java Environment

To start programming in Java, you need to set up your development environment. Here's a step-by-step guide:

  1. Download and install the Java Development Kit (JDK):

  2. Set up environment variables:

    • Add the Java bin directory to your system's PATH variable.
    • Create a JAVA_HOME environment variable pointing to your JDK installation directory.
  3. Install an Integrated Development Environment (IDE):

    • While not strictly necessary, an IDE can greatly enhance your Java development experience.
    • Popular choices include IntelliJ IDEA, Eclipse, VScode, and NetBeans.
    • Download and install your preferred IDE.
  4. Verify your installation:

    • Open a command prompt or terminal.
    • Type java -version and press Enter. You should see information about your installed Java version.
    • Type javac -version to check if the Java compiler is correctly installed.

Your First Java Program

Let's create a simple "Hello, World!" program to ensure your Java environment is set up correctly and to introduce you to basic Java syntax.

  1. Open your text editor or IDE.

  2. Create a new file and name it HelloWorld.java.

  3. Enter the following code:



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


Enter fullscreen mode Exit fullscreen mode
  1. Save the file.

  2. Open a command prompt or terminal, navigate to the directory containing your HelloWorld.java file.

  3. Compile the program by typing:



javac HelloWorld.java


Enter fullscreen mode Exit fullscreen mode

This will create a HelloWorld.class file.

  1. Run the program by typing:


java HelloWorld


Enter fullscreen mode Exit fullscreen mode

You should see the output: Hello, World!

Congratulations! You've just written and run your first Java program.
Let's break down the code:

  • public class HelloWorld: This declares a public class named HelloWorld. In Java, the class name must match the filename.

  • public static void main(String[] args): This is the main method, the entry point of any Java program.

  • System.out.println("Hello, World!");: This line prints the text "Hello, World!" to the console.

As we continue learning Java, in the next article, we will discuss Java Syntax Fundamentals. We'll explore more complex concepts like variables, data types, control structures, object-oriented programming, and much more.

I'd love to hear about your experience with Java!
What aspect of Java are you most excited to learn about, and why?

If you found this article helpful, please consider following for more Java content. Your likes and comments are greatly appreciated – they help me understand what topics you're most interested in, allowing me to tailor future content to your needs.

Did you encounter any issues while setting up your Java environment? Share your experiences in the comments below, and let's problem-solve together!
Stay tuned for our next article on Java Syntax Fundamentals. Happy coding!

. . . . . . . . .
Terabox Video Player