Getting started with Java programming!

Getting started with Java programming!

-About me!

Hello, My name is Vijay and I am here to share my learnings with you so that you can get started with Java programming. I will share step by step beginner-friendly approach. So let's get started.


What is a computer program?

  • A computer program is a set of instructions that run on a computer or other digital devices.

  • The computer understands only (0's and 1's) which is a binary instruction.

  • Most of the programs are written in high-level code (Human readable) and must be translated to machine code


Introduction to Java and its history:

Java was developed by James Gosling and a team of researchers at Sun Microsystem, Inc. in 1995. They wanted to develop a more robust language, portable, Object Oriented, interpreted and dynamic.

James Gosling

Previously in other languages code was translated by the compiler to the specific type of computer. But Java on other hand converted the code to byte code which was interpreted by JRE(Java Runtime Environment) or JVM(Java Virtual Machine) which was introduced by Java. By translating Bytecode for the host computer, the JRE functions as a virtual computer. Due to its ability to be written once and run on many different platforms, Java has become very popular for use on the Internet.


Advantages of Java

  1. Java is open source

  2. Java is object-oriented

  3. Java is easy to learn

  4. Java Web Application is used to create dynamic websites. Java provides support for web application through Servlets and JSPs.

Explanation of Java Virtual Machine and Compiler:

In languages like C and C++, the code is compiled into platform-specific machine code. Hence these languages are called compiled languages. In other languages like python and javascript, the code is not compiled as the computer executes instructions directly and hence these are called interpreted language. But does both! How? let's see.......

  • The source code (.java file) is compiled by the compiler and converted to a machine-independent encoding called bytecode. The class file generated is independent of the machine/OS. This all happens at compile time.

  • During run time, this class file is then passed through Java Virtual Machine.

  • The class loader inside the JVM loads the byte code from the disk and puts that byte code in the memory.ClassLoader runs 3 process:

    1- Loading
    2- Linking
    3- Initializing

  • JVM has a byte code verifier required for the security of the program. The bytecode verifier verifies the program only after the bytecode is loaded.

  • JIT stands for Just-in-time compiler and is part of the Java Virtual Machine (JVM), it is used to speed up the execution time.

After going through the JVM we get the Native machine code. Compilation Done!

Compiler: A computer program that translates source code to machine code.

Setting up the development environment

Let's get you up and running with Java programming.

Download the latest Java Development Kit installation file for Windows 10 to have the latest features and bug fixes.

  1. Using your preferred web browser, navigate to the Oracle Java Downloads page.

  2. On the Downloads page, click the x64 Installer download link under the Windows category.

  3. The installation wizard welcome screen appears. Go with the default settings and continue.

  4. We have to set Java environment variables to enable program compiling from any directory. Follow the steps below:

  5. In the windows search bar, type system environment variables. Click on advanced -> Environment variables -> System Variable -> Path -> Edit -> New -> Put this path there( C:\Program Files\Java\jdk-17.0.1\bin) -> Click on Ok

Some applications require the JAVA_HOME variable. Follow the steps below to create the variable:

  • In the Environment Variables window, under the System variables category, click the New… button to create a new variable.

  • Confirm the changes by clicking OK in the Environment Variables and System properties windows.

  • Run the java -version command in the command prompt to make sure Java is installed correctly:

  • If installed correctly, the command outputs the Java version. Make sure everything works by writing a simple program and compiling it. Follow the steps below:

Please refer to this link for any query regarding installation:https://phoenixnap.com/kb/install-java-windows

Let's test and see the simple Hello World program:

Creating the "Hello, World!" program

public class Example{
      public static void main(String[] args){
           System.out.print("Hello World");
        }
}

Write this code on Notepad, and save as an example.java file on Desktop. Open the command prompt, In the command prompt change the directory to the file's location and use the following syntax to compile the program.

javac example.java

After a successful compilation, the program generates a .class file in the file directory

java Example

The output shows that the program runs correctly, displaying the Hello world! message.

To download Eclipse Ide follow this link:

https://www.eclipse.org/downloads/

Conclusion:

Congratulations! You've now completed our Getting Started with Java Programming blog. In this blog we learned the origin of Java, JVM and its architecture, Compiler, setting up a development environment and running our first Hello World program. Java is a versatile and widely-used programming language that can open up a wide range of career opportunities. Whether you're interested in building desktop applications, mobile apps, or web development, Java can help you achieve your goals.