Java Tutorial - Java is a robust and widely used programming language. This Java tutorial is designed for anyone who wants to learn Java from scratch. This tutorial will walk you through all Java concepts by using examples. Examples are 100 times better than text when it comes to understanding any concept. We have included all the concepts with an example to gain in-depth knowledge of Java
Table of Contents - Java Tutorial |
Java is one of the most popular programming languages. It was developed by James Gosling in the year 1991, and the purpose was to use it in his set-of-the-box projects. It was initially named ‘Oak’ which is a tree name that stood outside the Gosling’s office window and also went renamed it as a ‘Green’, but later it ended up with a name known as JAVA.
Sun Microsystems originally developed Java programming language in the year 1995 initiated by James Gosling, and it was the first core component system of Sun Microsystems. Java has got massive popularity among programming languages due to its flexibility to configure on multiple platforms. For example, J2EE is used for the development of Enterprise applications and J2ME is for mobile applications.
[Checkout: Thymeleaf vs JSP]
Object-oriented programming is at the heart of Java. Almost all Java programs are object-oriented to some extent. Object-oriented programming (OOPs) is a method to simplify software development and maintenance by following some rules.
Unlike the C compiler, the Java compiler produces and converts the source code into a unique format called bytecode. Bytecode is understandable by any JVM installed on any Operating System. Java’s runtime platform runs on top of the hardware platform of any OS. Due to this, Java source code can run on all OS and hence make Java a platform-independent language.
Java is declared the most secure programming language. It is secure as its source code runs in a virtual machine sandbox.
Java focuses on compile-time and runtime error checking thus reducing error-prone situations.
Are you interested in taking up Core Java Certification Training? then visit MindMajix to Enroll Now for Core Java Training |
Java bytecode is portable. You can carry it to any platform and it will work. It doesn’t require any implementation.
Java’s bytecode is close to native code and that is why it is faster than all other programming languages.
Java compiler created an architecture-neutral object file format. This facilitates the compiled code to work on many processors with JRE.
Java enables developers to code in such a manner that multiple tasks can be done simultaneously. This can enhance the user experience of any application due to its interactive nature.
Java is designed and developed to work in distributed environments on the internet.
[Related Article: Java Interview Questions]
To know how Java works, we need to understand 3 basic terms: JDK, JRE, and JVM.
JVM: JVM stands for Java Virtual Machine. It does not physically exist hence called a virtual machine. JVM converts bytecode into the language understood by a particular OS and is responsible for executing Java code line by line. It is also termed an interpreter.
JRE: JRE stands for Java Runtime Environment. It provides the runtime environment for executing Java code. It can only execute the existing code. We cannot develop code or build new applications using JRE. It contains a set of library class files and other files which JVM uses at runtime.
JDK: JDK stands for Java Development Kit. It contains JRE and development tools to develop Java applications and build new apples. Developing new applications, modifying existing applications, compiling java code, and executing them is possible through JDK.
For executing Java code, we need below 3 things installed in our machine
Nowadays, we have so many java tools available like Eclipse, Netbeans which makes coding interesting and easy.
[Related Article: Programming Languages in Data Science]
Java can be installed from oracle’s official website. Once it is installed, you can verify the version from the command prompt using the command “java -version” like below:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:Userspalakharshadbhai.sha>java -version
java version "1.8.0_171"
Java (TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot (TM) Client VM (build 25.171 -b11, mixed mode)
Once it is installed, we need to set it up in our system to run the java program effortlessly. To set up the Java environment in Windows, follow the below steps.
[Checkout: What is PyCharm]
Let us start by writing a simple Java program.
class Test {
//first sample program
public static void main(String args[]) {
System.out.println("Our first Java program");
}
The file which contains Java source code is called a source file.
[Related Article: Goldman Sachs Interview Questions]
Few things to consider while writing Java programs:
[Related Article: Linked List Interview Questions]
To compile the program, we need to pass the filename to the command javac like shown below:
javac Test.java
The javac compiler generated the .class file which is nothing but the bytecode version of the code written in the source file. Java bytecode is the intermediate presentation of the code which is understood by JVM. So, the output of javac cannot be executed directly.
To run the program, we need to pass the class name with the command java.
java Test
This will execute the bytecode and print the output:
Our first Java Program
Now, let us try to decompose the code and understand the keywords used in this code unit.
[Checkout: What is Site Reliability Engineering]
Data Types Variables and Arrays in Java | |
Data Types | Primitive Data Types |
Variables | Scope and Lifetime of Variables |
Arrays |
Control Statements in Java | |
Decision Making in Java | Looping Statements in Java |
Branching Statements in Java |
Classes and Objects in Java | |
Create a Classes in Java | Objects and Methods in java |
Constructors in Java | Garbage Collection in Java |
Access Modifiers in Java |
Abstraction in Java | |
Abstract Classes | Multiple Inheritance in Java |
Interfaces | Why interface is required? |
Key Points to remember about interfaces |
Exception Handling in Java | |
What is an Exception? | Exception Vs Error |
Exception Keywords in Java | Exception Handling Example |
Java’s Built-In Exceptions |
Multithreading in Java | |
Lifecycle of a Thread | Creating a Thread in Java |
Synchronization |
String Handling in Java | |
String Length | String Modification |
String Concatenation | Extraction |
Replace | Trim |
Case Conversion | String Conversion |
String Comparison |
Stay updated with our newsletter, packed with Tutorials, Interview Questions, How-to's, Tips & Tricks, Latest Trends & Updates, and more ➤ Straight to your inbox!
Name | Dates | |
---|---|---|
Core Java Training | Aug 05 to Aug 20 | |
Core Java Training | Aug 08 to Aug 23 | |
Core Java Training | Aug 12 to Aug 27 | |
Core Java Training | Aug 15 to Aug 30 |
Ravindra Savaram is a Content Lead at Mindmajix.com. His passion lies in writing articles on the most popular IT platforms including Machine learning, DevOps, Data Science, Artificial Intelligence, RPA, Deep Learning, and so on. You can stay up to date on all these technologies by following him on LinkedIn and Twitter.
1 /15
Copyright © 2013 - 2023 MindMajix Technologies