CodeGym /Java Blog /Learning Java /How to start learning Java
Author
Pavlo Plynko
Java Developer at CodeGym

How to start learning Java

Published in the Learning Java group

The Java language

Java is not just a programming language. It's an entire software platform with extensive capabilities. The main components of the platform are:
  • Basic tools for writing and running Java programs.
  • Libraries and classes (the core of the language). They provide Java's basic programming capabilities: exception handling, multithreading, collections, logging, reflection, security, networking, XML processing, serialization, regular expressions.
  • Tools for deploying and automatically launching applications.
  • Tools for creating a frontend (GUI, user interface). These are found in the classes of the JavaFX, Swing, and Java2D libraries.
  • Libraries for working with databases remotely over the network, such as JDBC, JNDI, RMI and Java RMI-IIOP.
If you want to learn more about Java classes and tools, read the Oracle documentation. It has everything. Java JDK 1.0, the first version, included "only" a few hundred classes. But now that number has increased to several thousand. Over the life of the language, its creators have made a huge number of changes that increase its security, functionality and portability. Thanks to this continuous improvement and support from developers, Java has always been in step with the development of IT technologies. As a result, we now we have a state-of-the-art language whose main characteristics are:
  • Low barrier to entry.
    Learning Java is easier than most languages with a C-like syntax.

  • Object orientation.
    Programs in Java are built based on objects and interactions between objects. This lets you enjoy all the advantages of OOP.

  • Portability.
    Because an interpreter (the Java virtual machine) is used, programs can be run on various platforms and devices.

  • Platform independence
    A Java program written for one platform is compiled into intermediate byte code that can be run on other platforms, because it is interpreted by a JVM for each specific platform.

  • Advanced multithreading.
    Java tools let you control the execution of multiple threads, which means you can create multithreaded applications.

  • Security.
    Because the JVM has built-in bytecode verification, and Java has no manual memory management, tracks stack overflows, and has various APIs that let you control security, you can create really safe applications in Java.

  • Fault tolerance.
    The exception mechanism increases programs' fault tolerance and reduces the number of errors, both at compile time and run time.

  • Interpretability.
    The Java interpreter can execute Java bytecode on any machine that has a JVM and JRE.

  • Distributability.
    Java has tools for creating distributed applications.

  • Performance.
    A JIT (just-in-time) compiler provides high speed performance comparable to C and C++.

How to start programming in Java?

To start learning Java from scratch, you should dig into some basic concepts: what's included in the Java language, what's a Java program, and how does it run? Then move on to the language's syntax and basics, and study libraries. After reading a couple of articles about Java, you can tackle the basics. The following flowchart clearly demonstrates the sequence of steps: How to start learning Java - 2

What do you need to program in Java?

First, you need to install software for developing and running programs — the Java Development Kit (JDK). After that, configure the JDK on your computer, download and install an integrated development environment (IDE), which is an environment for software development. The most popular IDE is IntelliJ IDEA. Alternatives are Eclipse, NetBeans, JCreator, and even an ordinary text editor.

Installing Java on your computer

As we've already seen, when we learn Java from scratch, the first step is to install the JDK. For this, you need to perform a few simple operations:
  1. Go to the Oracle website.
  2. Select and download the installation file for your operating system.
  3. Perform the installation, following the installer's recommendations.
  4. Set an environment variable if you're using Windows.

Basic definitions

If you're just starting to learn Java, you will certainly encounter the following terms: JVM stands for Java virtual machine. This is a platform-dependent software module that serves to interpret the source bytecode into machine code and executes it. JRE stands for Java Runtime Environment. It includes the JVM implementation for a specific platform and a set of libraries needed to run Java programs. JDK stands for Java Development Kit, which is a set of developer tools needed to write Java programs. It includes a compiler, JRE, standard Java libraries, documentation, and various utilities. Source code is found in a text file written in the Java language with the .java extension. Bytecode is machine-independent low-level code that consists of a set of instructions for the JVM. Machine code is binary machine instructions that are executed directly by the processor. Compile means to convert source code to bytecode. Interpret means to convert bytecode to machine code. A platform is a software and hardware environment for running programs. The most popular platforms are Microsoft Windows, Linux, Solaris OS and Mac OS. This diagram will help you better understand the concepts of JVM, JRE and JDK: How to start learning Java - 3

Program lifecycle

A Java program's life begins when source code is written in a text file. Usually, this is done in a special programming environment called an integrated development environment (IDE), but simple programs can be typed into a text editor, even Notepad, which comes with any edition of Windows. The source code must be saved in a file with the .java extension. Example program: HelloWorld.java:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("This is my first program");
    }
}
Before this source code is executed, it must be compiled it into bytecode by a compiler. A compiler is a utility that is part of the JDK. It produces a file with the .class extension. This file contains bytecode, which are instructions for the JVM. Their format resembles assembly language. Our HelloWorld.java program will be compiled into a HelloWorld.class file. The Java platform does not provide tools for editing bytecode, but you can view it. To view the bytecode of a Java program, you can use the javap disassembler utility, which is included in the JDK. HelloWorld.class will contain the following bytecode:

Compiled from "HelloWorld.java"
public class HelloWorld {
  public HelloWorld();
    Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return

  public static void main(java.lang.String[]);
    Code:
0: getstatic #2 // Fieldjava/lang/System.out:Ljava/io/PrintStream;
3: ldc #3 // String This is my first program
5:invokevirtual #4// Methodjava/io/PrintStream.println:(Ljava/lang/String;)V
8: return
}
Now our program is stored in a compiled form in the HelloWorld.class file. To run it on any platform, the JRE must be installed. The JVM provides the ability to port Java programs to any platform. Execution means execution of the bytecode by the Java virtual machine. Programs are executed using the java utility. You need to specify the name of the compiled file. Execution happens as follows:
  1. The JVM is loaded into the computer's memory. Basically, this is a program that serves to run the Java programs we write.
  2. Using the bootstrap classloader, the JVM loads and initializes our class in memory. In our example, this is the HelloWorld class.
  3. Next, the JVM looks for a public static void main(String []) method in our class.
  4. The code of the main method is executed. If execution of the program requires other classes, they are loaded and initialized.
  5. After the code is executed, garbage collection is performed. This involves clearing memory and closing the JVM program.
When performing all of these actions, the JVM interprets (translates) the bytecode into a machine instruction for the processor, taking into account the operating system on which it is running. We can represent the lifecycle of a Java program in the following diagram: How to start learning Java - 4

Choosing and installing a development environment

To quickly and efficiently program in Java, you need a development environment — an application for writing Java programs. Among Java developers, the most popular IDEs are:
  • IntelliJ IDEA
  • Eclipse
  • NetBeans
According to a review of the popularity of Java development tools, prepared by RebelLabs in 2017, the leader was IntelliJ IDEA, Eclipse was second, and NetBeans ranked third, lagging significantly behind the top two leaders. Other IDEs represent a small fraction of the market, totaling no more than 3%. For beginners, installing IntelliJ IDEA Community Edition is sufficient. First, you get all the advantages of a modern IDE (auto-complete, code checking, code debugging, convenient integration with databases and servers) as well as support for many development tools and technologies. Second, you take the first step toward mastering the professional development tool used by most developers. Instructions on how to install IntelliJ IDEA are provided at the beginning of Level 3 of the CodeGym educational course.

How long does it take to learn Java?

You can probably learn the basics of Java and develop programming skills in 6 to 12 months, depending on how intensely you study. Take a structured approach: make a study plan, gather the necessary sources, and set aside a few hours a day for your studies. Don't forget that the key to learning how to program is practice.

Conclusion

Studying Java on your own is actually easier than you might think. You only need basic computer skills. To start learning Java effectively, follow a few simple steps:
  1. Install Java on your computer
  2. Learn the basic concepts
  3. Install a development environment
  4. Write and run your first program
Comments (1)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Mina Level 8, Rome, Italy
3 August 2019
You are great 😘😘