Warning: session_start(): open(/tmp/sess_c6cab40c2cb120b5ab08f4fca8bbf6c6, O_RDWR) failed: Disk quota exceeded (122) in /home/wvyrfnwn/learnshareit.com/wp-content/plugins/learnpress/inc/class-lp-page-controller.php on line 1007

Warning: session_start(): Failed to read session data: files (path: /tmp) in /home/wvyrfnwn/learnshareit.com/wp-content/plugins/learnpress/inc/class-lp-page-controller.php on line 1007

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 719

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 719

Warning: ftp_mkdir() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 562

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230
Java Tutorials: An Introductory Guide Into This Platform-Independent Language - LearnShareIT

Java Tutorials: An Introductory Guide Into This Platform-Independent Language

Java Tutorials

Few pieces of technologies have the impact Java has created on the industry. From the early days of the internet to the era of cloud computing, it is never late to learn and master this programming language.

These Java tutorials will help you understand what sets Java apart from the rest of the pack and how to get started with it.

Java Introduction

What Is Java?

Java is a programming language originally created by James Gosling when he worked at Sun Microsystems in 1995. Oracle assumed its development when it acquired Sun Microsystems in 2010.

The Java language is the core of the software development platform of the same name, which allows developers to create applications written in Java and able to run on various platforms.

Important Characteristics Of Java

Compared to other programming languages, Java has several advantages that have helped it earn widespread adoption in the industry.

Simple

If you are coming from other high-level languages like C/C++, Java offers a more cleaned-up syntax. There is no need to declare the header files or carry out pointer arithmetic.

Object-Oriented

Object-oriented programming (OOP) is at the core of the Java language. Many places choose Java to teach programming as this language provides a great introduction to OOP.

Secure

Java can sandbox your applications by running them in a dedicated virtual machine. Programs in this execution environment can’t reach other parts of the system. This actually contributed a big part to the early success of Java, when downloading programs from the internet was a huge concern.

Portable

Java’s original slogan was Write once, run anywhere (WORA). You can expect your programs to run on any device as long as they can run a Java virtual machine (JVM).

You don’t need to spend much effort adjusting your code to different systems since Java is platform-independent and architecture-neutral. With the presence of the runtime system, the compiled code can be easily interpreted and translated into native machine code at runtime.

Multithreaded

Modern software development pays more attention to concurrency because computer systems have faster processors with more cores. Java supports this out of the box and makes it quite manageable, even though concurrent programming isn’t easy to master.

Basic Terminology

Before getting started with your first Java programs, make sure to familiarize yourself with these fundamental concepts. You will run into them frequently when learning and writing in Java.

Java Virtual Machine (JVM)

To make Java platform-independent, you don’t need to compile your program to native executable code. Instead, your Java code will be turned into bytecode.

This is a special instruction set designed to be run inside a Java virtual machine. As the name suggests, it is a virtual machine running on top of your operating system. Part of a runtime environment, It is what executes the Java bytecode.

There are plenty of JVM implementations. You can use any of them to run Java programs as long as they follow the JVM specification. The official (reference implementation) is HotSpot, which is developed by Oracle.

Java Runtime Environment (JRE)

A JRE consists of a JVM, the class loader, class libraries, and other runtime utilities.

It combines the bytecode produced from a Java program with the required libraries before creating a JVM instance to execute the resulting code. Like JVMs, there are plenty of JRE options you can install.

Java Development Kit (JDK)

This is the set of tools for creating Java applications. The official JDK distribution from Oracle is based on the open-source implementation OpenJDK.

Install Java

As a beginner to Java programming, you will need to install a JDK and an IDE (integrated development environment).

JDK

You can use the free OpenJDK installers and similar implementations. They don’t require you to sign an agreement or create an account like Oracle’s commercial builds.

Linux

Many distributions have binary packages for OpenJDK that you can install with their package manager.

Ubuntu/Debian

sudo apt install default-jdk

Fedora

sudo dnf install java-latest-openjdk.x86_64

Arch Linux

sudo pacman -S jdk-openjdk

macOS

You can use the java formula from Homebrew to install the latest version of OpenJDK:

brew install java

Windows

Go to https://jdk.java.net/ and select the latest stable version (19, as of right now). Download the zip file for Windows, extract it, and follow the instructions inside.

IDE

There are plenty of great free IDEs that provide excellent support for Java programming:

  • IntelliJ IDEA (Community Edition)
  • Eclipse
  • NetBeans

In this tutorial, we use the free version of IntelliJ IDEA. Go to https://www.jetbrains.com/idea/download/

and click the Download button for the Community edition. The download will automatically start, wait for it to complete, and follow the instructions of the installer.

First Program

We will show you how to create a Java program with IntelliJ IDEA.

Open the program, and from the menu, select File > New > Project…

Name your project and select the directory to save it. Make sure the Language and Build system sections are set to Java and IntelliJ, respectively. The IDE should automatically detect the available JDK installation on your system and show it in the JDK section.

Click Click. IntelliJ IDEA will automatically create a file named Main.java.

Type in this snippet if the file doesn’t already have it:

On the menu, select Run > Run ‘Main.java’ (or select the right arrow icon on the toolbar) to compile the code and run the resulting program in a terminal at the bottom of the window.

You should see this line in the output:

Hello world!

Basic Java Syntax

The Hello world program demonstrates how a class declaration works, including some basic elements of Java syntax.

This public keyword defines the scope of the class Main, making it “public” and accessible to all other classes.

In its body, we declare the method main – the most important method in Java. It is the entry point of every Java program and takes a String array as its sole argument. When running a Java program, the runtime will look for this method and will throw an error if it isn’t found.

This method needs to be public so the JRE can execute it. The static keyword indicates that this method belongs to the class Main itself, not an instance of that class. As a result, you don’t need to create an instance of Main in order to invoke the main() method. The void keyword means the method shouldn’t return anything.

By using System.out.println, we are using the println() method of System.out to write into the standard output stream.

Java Tutorials – Summary

Java is a popular object-oriented language that you can use to develop a wide array of cross-platform applications. Your code will be translated to Java bytecode, which the JRE on the end-user system will run.

Follow Java tutorials on our website to learn more about this programming language and its features.

Leave a Reply

Your email address will not be published. Required fields are marked *