JavaRush /Java Blog /Random EN /How to start learning Java
Alex
Level 37

How to start learning Java

Published in the Random EN group

Java language

Java is not just a programming language, but a whole software platform with wide capabilities. The main building blocks of this platform are: How to start learning Java - 1
  • Basic tools for writing and running Java programs.
  • Libraries and classes are the core of the language. They provide the core functionality of Java programming: exception handling, multithreading, collections, logging, reflection, security, networking, XML manipulation, serialization, regular expressions.
  • Tools for deploying and automatically launching applications.
  • Tools for creating a frontend (GUI, user interface). These are the JavaFX, Swing, and Java2D library classes.
  • 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's all there. The first Java JDK 1.0 included "only" a few hundred classes. But now their number has increased to several thousand. During the life of the language, the authors have made a huge number of changes that increase its security, functionality and portability. Thanks to the constant improvement and support of the language by its developers, Java has always kept pace with the development of IT technologies. So now we have before us a modern language, the main characteristics of which are:
  • Low entry threshold.
    Java is easier to learn than most languages ​​with a C-like syntax.

  • Object orientation.
    Programs in Java are built around objects and their interactions to take full advantage of OOP.

  • Portability.
    Through the use of an interpreter - the Java virtual machine - programs are portable to various platforms and devices.

  • Platform Independence
    A program written in Java for one platform is compiled into an intermediate bytecode that can be run on other platforms by being interpreted by the JVM for each platform.

  • Developed multithreading.
    Java tools allow you to control the execution of multiple threads, which allows you to create multi-threaded applications.

  • Safety.
    With built-in bytecode verification in the JVM, Java's lack of manual memory management, stack overflow tracking, and the presence of various APIs that allow you to control security, you can create truly secure applications in this language.

  • Fault tolerance.
    The exception mechanism both during compilation and during direct execution increases the fault tolerance of programs and reduces the number of errors.

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

  • Distribution.
    Java has tools for building distributed applications.

  • Performance.
    The use of the JIT (Just-in-time) compiler provides high speed applications, comparable in speed to the C and C++ languages.

How to start programming in Java?

To start learning Java from scratch , it is advisable to understand the basic concepts: what the Java language includes, what a Java program is, and how it is executed. Then - move on to the syntax of the language, its basics, the study of libraries. After reading a couple of articles about the Java language, you can take on its basics.

The sequence of steps is clearly demonstrated by this flowchart:
Where to start learning Java - 2

What do you need to program in Java?

First you need to install the software for developing and running programs - JDK (Java Development Kit). After that, set up the JDK on your computer, download and install one of the IDEs (Integrated Development Environment) - this is a software development environment. The most popular IDE is IntelliJ IDEA. Alternatives are Eclipse, NetBeans, JCreator, and even regular notepad.

Installing Java on a Computer

As we have already found out, when we learn Java from scratch, the first step is to install the JDK . To do this, you need to do a few simple operations:
  1. Go to the Oracle website .
  2. Select and download the installation file depending on your operating system.
  3. Perform the installation following the instructions of the installer.
  4. Set up an environment variable if you are using Windows.
Here, for example, is a description of installing the JDK and the environment variable for the Windows operating system.

Basic definitions

If you have just started learning Java, you will certainly come across the following terms: JVM (Java Virtual Machine) - Java virtual machine. This is a platform-specific software module that interprets source bytecode into machine code and executes it. JRE (Java Runtime Environment) - Java runtime environment. Includes a platform-specific JVM implementation and a set of libraries required to run Java programs. JDK (Java Development Kit) is a set of developer tools needed to write programs in Java. Includes a compiler, JRE, a set of standard Java libraries, documentation, and various utilities. Source code is a Java text file with the .java extension .- machine-independent low-level code, which is a set of instructions for the JVM. Machine code is a set of machine instructions in binary format that are directly executed by the processor. Compilation is the transformation of source code into bytecode. Interpretation is the transformation of bytecode into machine code. A platform is a software and hardware environment in which programs and applications are executed. 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:
Where to start learning Java - 3

Program life cycle

The life cycle of a Java program begins with writing source code in text format. Usually, special development environments are used for this - Integrated Development Environment (IDE) , but simple programs can also be typed in a text editor, even in Notepad, which comes with any edition of Windows. The source code must be saved to a file with a .java extension. Program example HelloWorld.java:
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("This is my first program");
    }
}
Before executing this source code, it must be compiled into bytecode using a compiler. The compiler is a utility that is part of the JDK. As a result of its work, we will get a file with the .class extension. It contains bytecode - instructions for the JVM, the format of which 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 it is still possible to view it. To see what the bytecode of a Java program is, you can use the javap disassembler utility, which is included with the JDK. hello world. 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 compiled form in the HelloWorld.class file. For its execution on any of the platforms, an installed JRE is required. The portability of Java programs to any platform is provided through the use of the JVM. Program execution is the execution of bytecode by the Java virtual machine. Program execution is performed by the java utility, which needs to specify the name of the compiled file. Execution occurs in the following sequence:
  1. The JVM runs in the computer's RAM. In essence, this is a program that serves to execute Java programs that we have written.
  2. With the help of the initial class loader, the JVM loads and initializes our class in the computer's memory. In our example, this is the HelloWorld.
  3. Next, in our class, the JVM looks for the public static void main(String[]).
  4. Method code is executed main. If it is necessary for program execution, other classes are loaded and initialized.
  5. After the code is executed, garbage collection is performed - memory is cleared and the JVM program is closed.
When performing all 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. Schematically, the life cycle of a Java program can be represented as follows:
Where to start learning Java - 4

Choosing and installing a development environment

To program in Java quickly and efficiently, you need a development environment, an application for writing Java programs. The most popular IDEs among Java developers are:
  • IntelliJ IDEA
  • Eclipse
  • NetBeans
According to RebelLabs' Java Development Tools Popularity Survey of 2017, IntelliJ IDEA was the leader , followed by Eclipse in second place, and NetBeans in third place, well behind the pair of leaders. The share of other IDEs is small and does not exceed 3% of the total volume. A good comparison overview of these IDEs can be found here. For beginners, it is enough to install IntelliJ IDEA Community Edition. Firstly, you will get all the advantages of a modern IDE, such as hints, code checking, the ability to debug code, convenient integration with databases, servers, and support for many development tools and technologies. Secondly, you will take the first step in mastering the professional development tool used by most developers. Instructions for installing IntelliJ IDEA are provided at the beginning of the third level of the CodeGym online tutorial .

How long does it take to learn Java?

It will most likely take 6 to 12 months to learn the basics of Java and develop a programming skill, depending on the intensity of your training. To make this process systematic, make a study plan, collect the necessary resources, and allocate several hours a day for classes. Don't forget that the key to learning to code is practice.

Conclusion

When we learn Java on our own, it turns out to be easier in practice than in theory. For this, knowledge at the level of a personal computer user is quite enough. To effectively start learning Java, follow a few simple steps:
  1. Install Java on your computer
  2. Learn Basic Concepts
  3. Install the development environment
  4. Write and run your first program.
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION