Introduction To Java – How To Start Programming With Java?

Introduction to Java programming

  • In 1995, James Gosling Who Is Invented Java at Sun Microsystems, which was later bought by Oracle Corporation.

  • It is a straightforward programming language. Java makes writing, compiling, and debugging programming easy.

  • It makes it easier to make code that can be used more than once and programs that are made up of smaller parts.

  • Java is an object-oriented programming language that uses classes.

  • It is designed to have as few implementation dependencies as possible.

  • A general-purpose programming language that allows developers to write once and run it anywhere. Java code runs on all platforms that support Java.

  • Java programs are turned into byte code that runs on any Java Virtual Machine. Java’s syntax is similar to c/ c++’s.

History About Java

The History Of Java is really interesting.

It is a programming language made in 1991.

James Gosling, Mike Sheridan, and Patrick Naughton started the Java language in 1991 as part of a group of Sun engineers known as the Green team.

Sun Microsystems released the first version of Java to the public in 1996. This version was called Java 1.0.

It offers no-cost runtimes on popular platforms. Arthur Van Hoff rewrote the Java1.0 compiler in Java so that it would strictly follow its specifications.

With the release of Java 2, new versions were made with multiple configurations for different types of platforms.

In 1997, Sun Microsystems went to the ISO standards body and asked them to make Java official, but it didn’t take part in the process for long.

Sun used to give away most of its Java implementations for free, even though they were proprietary software.

Sun made money with Java by selling licenses for specialized products like the Java Enterprise System.

Sun gave away a lot of its Java virtual machine as free, open-source software on November 13, 2006.

Sun finished the process on May 8, 2007, making all of the core code for its JVM available under open-source distribution terms.

➡ Java was made with simple, strong, secure, fast, portable, multi-threaded, interpreted, dynamic, etc. as its guiding principles.

➡ James Gosling, who is known as the Father of Java, made Java in 1995.

At the moment, Java is used in mobile devices, programming for the internet, games, e-business, and many more.

Introduction For Java
Introduction For Java

Why is this Programming Language named Java?

The first name of Java is OAK, the team decided to give it a new name.

Silk, Jolt, revolutionary, DNA, dynamic, and other words were suggested.

These names were easy to spell and fun to say, but everyone who came up with them wanted them to show what technology is all about.

James Gosling said that Silk and Java were two of the best names. Since Java was a unique name, most of them liked it.

Java is the name of an island in Indonesia. It was on this island that the first coffee, which was called Java coffee, was made.

And James Gosling came up with this name while he was having coffee near his office. Note that Java is not an acronym; it is just a name.

Java Terminologies

Before learning Java, you should know these common Java terminologies.

1. Java Virtual Machine (JVM)

This is usually referred to as the JVM. There are three steps to running a program.

They have to write, compile, and run the program.

  • A Java programmer, like you and me, writes a program.

  • The compilation is done by the JAVAC compiler, which is a main Java compiler included in the Java development kit (JDK). It takes the Java program as input and makes bytecode as output.

  • During the Running phase of a program, the compiler’s code is run by the JVM.

Now we know that the Java Virtual Machine’s job is to run the bytecode created by the compiler.

Every Operating System has a different JVM, but the output after bytecode is run is the same on all of them.

This is why Java is called a platform-independent language.

2. Bytecode in the Development Process

As we’ve talked about, the Javac compiler in JDK turns Java source code into bytecode so that JVM can run it.

The compiler saves it as a.class file. A disassembler like javap can be used to see the bytecode.

3 . Java Development Kit (JDK)

When we learned about bytecode and JVM, we used the term “JDK.”

So, as the name suggests, it is a complete Java development kit that has everything, like a compiler, Java Runtime Environment (JRE), Java debuggers, Java documentation, etc.

For the program to run in Java, we need to install JDK on our computer so that we can write, compile, and run the Java program.

4. Java Runtime Environment (JRE)

JDK comes with JRE. The Java program can run on our computers because we have JRE installed, but we can’t compile it.

JRE has a browser, a JVM, plugins, and support for applets. A computer needs JRE so that it can run the Java program.

5. Garbage Collector

The objects can’t be deleted in Java. Garbage Collector is a program that JVM uses to get rid of or get back that memory.

Garbage Collectors can get back the things that aren’t mentioned.

So Java makes a programmer’s life easier by taking care of memory management.

But programmers should be careful with their code if they are using long-used objects.

Because Garbage can’t get back the memory of objects that are being pointed to.

6 . ClassPath

The classpath is the file path that the Java runtime and the Java compiler look for.class files to load.

By default, JDK provides many libraries. If you want to use libraries from outside your program, you should add them to the classpath.

Important Features Of Java

1. Power Of Compilation And Interpretation

Most languages are made with a goal in mind, either to be compiled or to be read and understood.

But Java gives you a lot of power because the Java compiler turns the source code into bytecode and the JVM runs this bytecode to make OS-dependent executable code.

2. Write Once Run Anywhere

As we’ve already talked about, a Java application creates a “.class” file that looks like our program but contains code in binary format.

It’s easy to use because bytecode doesn’t depend on the architecture of the machine it’s running on.

It’s the main reason why Java is used in the IT industry all over the world.

3. Sandbox Execution

With the help of a bytecode verifier, Java programs run in a separate space that lets users run their apps without affecting the system underneath.

Bytecode verifier also adds to security because its job is to check the code for any kind of access violation.

4. Dynamic Flexibility

Java is completely object-oriented, so we can add classes, add new methods to existing classes, and even make new classes by extending existing ones.

Native methods, which are functions written in other languages like C and C++, can also be used with Java.

5. High Performance

Java’s architecture is set up so that it has less overhead during runtime.

Sometimes, Java uses a Just In Time (JIT) compiler, which compiles code only when it’s called. This makes applications run faster.

6. Portable

We know that Java code written on one computer can be run on another.

Java is portable because its bytecode can be run on any platform. This is because its bytecode is platform-independent.

7. Multithreading

Java can handle multiple threads.

It is a feature of Java that lets two or more parts of a program run at the same time so that the CPU can be used as much as possible.

8. Distributed

We can make distributed applications using the Java programming language.

Remote Method Invocation and Enterprise Java Beans are used to create distributed applications in Java.

The Java programs can be easily put on one or more computers that are connected to each other through the internet.

9. Secure

We don’t have pointers in Java, so we can’t use out-of-bound arrays. If we try to do so, we get an ArrayIndexOutOfBound Exception.

Because of this, Java can’t be used to take advantage of a number of security flaws, such as stack corruption or buffer overflow.

Also, Java programs run in an environment that is separate from the environment of the operating system, which makes them safer.

10. Robust

Java is a robust language, which means it can be trusted. It is designed so that it checks for errors as early as possible.

It is because of this, the Java compiler can find errors that are hard to find in other programming languages. Java’s main strengths are its garbage collection, handling of exceptions, and memory allocation.

11. Simple

Java is a simple language because it doesn’t have complicated features like pointers, operator overloading, multiple inheritances, and explicit memory allocation.

12. Platform Independent

The compiler turns the source code into bytecode, and then the JVM runs the bytecode that was made by the compiler.

This bytecode can run on any platform, including Windows, Linux, and macOS.

This means that if we compile a program on Windows, we can run it on Linux, and vice versa.

Each operating system has a different JVM, but all of them produce the same result after running bytecode.

This is why we call Java a platform-independent language.

13. Object-Oriented Programming Languages

Object-oriented programming is a way of writing code in which the program is set up as a collection of objects, each of which is an instance of the class.

  1. Encapsulation
  2. Polymorphism
  3. Inheritance
  4. Abstraction

I already discussed all the things you need to know about this powerful programming language, from history, the developers of Java, different terminologies, and the important features.

You need to familiarize yourself with all the stuff for you to become a smart programmer in the future.

Example Code Of Java

public class helloWorld {

   /* This is my first java program .
    * This will print 'Hello World' as the output
    * This Tutorial is made by Glenn Magada Azuelo
    */

   public static void main(String []args) {
       //System.out.println is a command that can print the output of the program
      System.out.println("Hello World"); // print Hello World
   }
}

You can run this code in your code editor if you already downloaded it to your laptop or PC, but if you don’t, you can download it.

Here’s the link. NetBeans IDE, but if you wish to run this code online, we also have an online compiler in Java just copy and paste the code.

We also put the Java online compiler below. Just scroll down so that you can easily test or execute the source code in order to learn more about Java Programming Language.

Output

Hello World

You can test the above example here! ➡Java Online Compiler 

Code Explanation

  • Comments – Comments are used to explain code, and Java, C, and C++ all use them in the same way. Compilers don’t care about the comment entries, so they don’t run them. Comments can be one line long or more than one line long.

Single Line Comments :

// With a double back slash, you can make a single-line comment.

Multi-line Comments :

/* You need to declare a single back slash, an asterisk, and another asterisk, then a single back slash. Then put the text in the center */

  • import java.io.* – This means that you can import all of the classes in the io package. The Java io package gives you a set of input and output streams that you can use to read and write data to and from files and other input and output sources.

  • class – The class contains the data and methods that will be used in the program. Methods define how the class acts. In JAVA, the class GFG only has one method, called Main.

  • void – The keywords show that this method won’t give anything back. Our application starts up with the main() method.

  • System.in – This is the standard input stream, which is used to read characters from the keyboard or any other standard input device.

  • System.out – This is the standard output stream, which is used to show the results of a program on an output device like the computer screen.

  • println() – You can also use this Java method to show text on the console. It puts the text on the console and moves the cursor to the beginning of the next line. The next printing starts with the line after this one.

  • String []args – This is the string array that is passed to the main function. The array is called args. One can pick their own flexible name, but many developers use this name.

Audience

This tutorial for Java has been made for people who are just starting out with the Java programming language to help them learn about the basics and more advanced ideas.

Prerequisites

Before you try out the different types of examples in this reference, we assume you already know about computer programs and computer programming languages.

Conclusion

In this chapter, we talked about the Introduction to Java, which focuses on the history of Java, Java terminologies, and the important features of Java that you need to be familiar with.

I hope this article is useful to you and you learned a lot. See you in the next chapter.

What’s Next?

In the next chapter, you’ll learn how to set up an environment and install Java so that you can make different Java applications.


Leave a Comment