Core Java Tutorial

This year we are celebrating 25 years of java, isn't it amazing to learn more about Java? Most people are aware of the java program and each year it’s getting bigger and better. Let me give a small introduction about this popular program, Java is a high level programming language first developed by Sun Microsystems and released in 1995. Java runs on almost all types of operating system platforms such as Windows, Linux, UNIX, and Macintosh. In this Core Java tutorial, you will be learning from basic to advanced level concepts, which will give you in-depth knowledge of the language. We have designed these Core java tutorial concepts to not only teach theoretical concepts but also practical examples. Are you excited to learn this tutorial? Let’s begin,

Introduction to Java program:

Java is one of the popular programming languages first developed by James Gosling and other engineers at Sun Microsystems. First, it was developed to use in the distributed environment setup of the internets. Java language developed to run on various platforms such as Windows, Linux, UNIX, and Macintosh. Java is an object-oriented language and works well with other languages too. Now Oracle has taken over the “Java '' Sun microsystems, so all the products of sun microsystem which come under Oracle license. In recent times, Java has become more than a language as time passes. It is also known as a “platform”, this is because it has its own runtime environment, has its own set of application programming interfaces, and distributed programs through RMI. Java is used to create executable contents and that can be distributed through networks. The name “JAVA” refers to the set of software tools to create and implement the executable contents using the Java programming language.

History and Versions of Java:

As I said earlier, java is a product of Sun Microsystems. The history of the java program starts with a green team of Sun Microsystems. The main aim to develop this program is to provide “simple, robust, platform-independent, portable, high performance, secured, object-oriented, and dynamic”. Now Java is used mainly in mobile devices, games, internet games, e-business solutions, and banking sectors. The following are the significant points of java history:

  1. James Gosling, Patrick Naughton, and Mike Sheridan first developed the Java project in 1991. The small team of Sun microsystem engineers called the “Green team”.
  2. At first, they designed java for small enterprises, and embedded systems in electronic appliances such as set up black boxes.
  3. Initially, it was named “Green talk” by James Gosling’s team and the file extension to save this file was .gt.
  4. After that, it was named “OAK” and developed as a part of the green project.
  5. OAK nothing but a symbol of strength and the national tree of countries like France, Romania, Germany, and the United States of America.
  6. In 1996, Oak was later named “JAVA” and it was an oak technologies trademark.
  7. James Gosling chooses the name “JAVA” because easy to spell and fun to call.
  8. Java is also an island of Indonesia where the first coffee was produced (also known as “java coffee”). This is a type of espresso bean.
  9. Java is just a technology name, not an acronym.
  10. At first, it was developed by Sun microsystems, now it is a subsidiary product of Oracle.

Versions details:

JDK beta -> 1995

JDK version 1.0 -> january 1996

JDK version 1.1 -> february 1997

J2SE version 1.2 -> december 1998

J2SE 1.3 -> may 2000

J2SE 1.4 -> february 2002

J2SE 5.0 -> september 2004

Java SE 6 -> december 2006

Java SE 7 -> july 2011

Java SE 8 LTS -> March 2014 (latest version).

Features of Java:

Java offers many advanced features, in the below diagram you will get some idea;

Features of Java

  1. Java is an object oriented programming.
  2. Encapsulation 
  3. Inheritance
  4. Abstraction
  5. Classes and objects
  6. Polymorphism

 In the future section, we will be explaining each feature in detail.

Why learn Java programming?

Java is a basic programming language for students and working professionals to become a successful software engineer when you are working in software companies. Here are some key advantages of the java programming language.

  1. Object oriented: In java, everything is known as an object. Java language can be extended easily because it was developed on the object model.
  2. Platform independent: Java is a compiled language when compared to other programming languages like C and C++. Java codes are not compiled into platform specific machines, rather than any platform independent bytecode. The byte code is distributed over the internet web and is interpreted by the Virtual machine or JVM.
  3. Simple language: Java language is designed to learn easily. If you know the basic concept of OOP Java, it makes it easy to understand the concepts.
  4. Secured language: java language is very secure to use because of the virus-free and tamper-free systems. Here most of the authentication techniques are designed on the basis of public key encryption.
  5. Architectural neutral system: Java compiler language generates an architectural and neutral system object file format. This feature makes the compiled code execution on many processors run on java runtime systems.
  6. Portable: being an architectural and neutral system doesn’t support any implementation dependency that makes java more portable software. The compiler is written in ANSI C that includes a clean portability boundary and POSIX subset.
  7. Robust: Java language makes less effort to eliminate any type of error-prone by implementing compile time error checking and run-time checking.

Different applications of Core java programming:

 Now we are using Java SE (standard edition) 8.0, which offers java advancements, widespread popularity, and multiple configurations built on various platform types. For example J2EE for enterprise applications and J2ME for mobile applications.

The latest versions of J2 named Java SE, Java ME, and Java EE. Java is popularly called “Write once and run anywhere”.

Some of the important applications are;

  1. Multithreaded: Java includes a multithreaded feature that enables us to write programs and that performs various tasks. This feature allows software developers to construct any interactive application that runs smoothly on various platforms.
  2. Interpreted: the java byte code is designed to translate them to fly on the native machine instructions and isn't able to store anywhere. The development process in Java is more rapid and analytical this is because the linking is a lightweight process and incremental procedure.
  3. High-performance system: With the help of just in time compilers, java language enables high performance.
  4. Distributed system: Java language designed to offer a distributed environment of the internet.
  5. Offers a dynamic environment: Java is more dynamic than any other language like C or C++. Java programs consist of the excessive amount of run-time information that is used to resolve access and verify objects on run time environment.

Core Java Certification Training

  • Master Your Craft
  • Lifetime LMS & Faculty Access
  • 24/7 online expert support
  • Real-world & Project Based Learning

JDK, JRE, and JVM in core Java:

In this section, we are going to explain different environment setups of Java such as JDK, JRE, and JVM.

First, let me discuss JVM:

1. JVM (Java virtual machine):

Java virtual machine is a type of abstract machine. This one is called a virtual machine because you can’t see them physically. The java virtual machine offers a runtime environment where you can execute the java bytecode. With the help of the java virtual machine, you can also run the programs which are written in any other languages (You can take C and C++) and will be compiled to Java byte code.

You will get a Java virtual machine for both hardware and software platforms. Java virtual machine, Java runtime environment, and java development kit are platform dependent because each operating system is configured using multiple different platforms. One important point to be noted here, Java is platform-independent, and three notions of java virtual machine available such as specifications, instances, and implementations.

The main tasks of JVM are as follows;

  1. Loading of codes
  2. Verifying codes
  3. Code execution
  4. Offers runtime environment

2. Java runtime environment (JRE):

JRE means Java runtime environment and it is written as a Java RTE. Java runtime environment consists of software tools that are used to develop java applications. This is used to provide the runtime environment and also the implementation of Java virtual machine. This one physically exists. Java virtual machine also consists of a set of libraries and other files that JVM that uses.

The following diagram will explain the JVM activities which are released by other companies.

Java runtime environment

3. JDK or Java development kit:

JDK means java development kit. The java development kit is a type of software development environment tool kit, used to develop only java applications and java applets. This Java development kit physically exists. The JDK contains JRE and development tools.

JDK is an implementation of the given java platforms which are released by Oracle corporations;

  1. Standard edition of java platform
  2. Enterprise edition of java platform
  3. Micro edition of java platform

The java development kit consists of a java virtual machine (JVM) and a few other resources such as an interpreter or loader (Only java codes), a compiler or (java c), an archiver or (jar), and a documentation generator (Javadoc) to complete the implementation of java application.

JDK or Java development kit

Core java architecture (JVM architecture) overview:

The main purpose of core java is to define specifications, implementations, and Runtime instances. The following diagram explains the JVM internal architecture; this consists of a class loader, execution engine, and memory as shown below:

JVM architecture

Let me explain about components in brief:

1. Classloader:

The class loader is a fundamental component of JVM and acts as a subsystem that is used only for loading the class files. When you run the java program, first it will be loaded by the class loader. You can see three built-in class loaders in core java,

  1. Bootstrap class loader: This is considered to be a first-class loader that can be used as a superclass of the extension class loader. It will load only the rt.jar file that consists of java class files like java. lang package, java.util package classes, java.sql package class, and java.net package classes, etc.
  2. Extension class loader: this one is a child class loader of bootstrap and parent system class loader. It helps to load the jar files which are located in the directory $JAVA_HOME/JRE/lib/ext directory.
  3. system/ application class loader: This is one of the child class loaders of an extension class loader. This class loader helps to classify the classpath. Classpath will be set as the current directory by default. This process is also known as the application class loader.

There are various internal class loaders available offered by JAVA. Suppose you want your own set of class loaders, you just need to extend the class loader class.

2. Class or method area:

Here class or method area helps to store the per-class structures like runtime constant pools, the code used for methods, and fields or method data.

3. Heap:

This is available in the form of a run time data area where you can allocate the objects.

4. Stack:

Usually, core java stacks store data formats. This consists of local variables and partial results. The stack plays a vital part in the method invocation and returns. Here each thread consists of a private java virtual machine stack and creates the same thread multiple times.

5. Program counter Register:

The program counter register holds the address of the java virtual machine instructions which are being executed.

6. Native method stack:

This component contains the native methods used for application development.

7. Execution engine:

This execution engine consists of the following components:

  1. Virtual processor
  2. Interpreter helps to read the bytecode stream that executes the instructions.
  3. Just-in-time or JIT compiler used to improve the application performance. JIT compiler compiles the part of byte data code that offers similar functionality and reduces the compilation time. The term “Compiler” referred to as a translator that transfers the set of instructions to a java virtual machine that specifies CPU.
8. Java native interface:

Java native interface is a type of framework that offers an interface to communicate between any two applications which are written in any programming language like C, assembly programs, and C++. In general, the core java uses the native interface to send information to the console windows and interact with operating system libraries.

Core Java variables and data types:

First, let me discuss Core java variables,

A variable is nothing but a container that holds the value during the execution of Java programs. The variables are assigned with data types. Variable is used to locate the memory. There are three types of core java variables such as local, instance, and static types.

Variable: A variable is a name given to a reserved area that allocates the memory. In short, you can refer to it as a name of a memory location. This is a combination of “vary + able” where value can be changed.

Types of variables:

  1. Local variable
  2. Instance variable
  3. Static variables

Core Java variables and data types

Local variables are declared inside the body of the method. One important point, you can use the variable within that method and methods in the class even aware that the variables exist or not.

A local variable cannot be defined by using any “Static” keywords.

Instance variable can be declared inside the class library but it is visible outside the method body. It can’t be declared as a “Static”. The name was given “instance” because the value is instance-specific and not shared among many other instances.

Static variables are declared as static, and this cannot be declared as a local. Here you can create a single copy of the static variable and share them among other instance classes. Memory allocation of static variables happens when the class is loaded in the memory location.

Subscribe to our youtube channel to get new updates..!

Core java data types:

Data types define the different sizes and values that can be stored in the data variables. There are two types of data types available:

  1. Primitive data type
  2. Non-primitive data type

Let me explain them one by one,

Primitive data types include Boolean, char, int, long, float, and double whereas non-primitive data types include classes, arrays, and interface.

Core java primitive data types are the fundamental building blocks of data manipulation. These are also considered as most basic data types of java language.

The following diagram explains the core java data types:

Core java data types

The examples for primitive data types are;

  1. Boolean data type
  2. Char data type
  3. Short data type
  4. Byte data type
  5. Int data type
  6. Float data type
  7. Long data type.

Non-primitive data types: These types of variables are mostly used in the writing of program codes. The examples are classes, arrays, and interfaces, etc.

How to deal with the Unicode system using Core Java?

First, we know the definition of Unicode, Unicode is a universal international standard character encoding that represents the words written in the user-defined programming language.

Why does core java use the Unicode system?

There are many languages used in Unicode;

  1. ASCII or American standard code for international interchange for the United States of America.
  2. ISO 8859-1 is used for the Western European language.
  3. KOI -8 used for the Russian language.
  4. GB18030 and BIG-5 used for the Chinese language and so on.

The problems which you can deal with Unicode system:

  1. A particular code value specifies the different letters in the various program language standards.
  2. The encoding for languages with large characters sets the variable length. Some common characters are encoded as a single byte, two-byte, or other that requires more bytes.

To solve these types of problems a new language was developed using Core java, that is the Unicode system.

In the Unicode system, a character holds the 2 bytes, and core java also uses the 2 bytes for characters.

Lowest value: \u0000

Highest value: \ uffff

Core java operators and keywords:

Core java operators are types of symbols and used to perform multiple operations. For instance, +, -, *, / etc.

There are many types of java operators available such as,

  1. Unary operators
  2. Arithmetic operators
  3. Shift operators
  4. Bitwise operators
  5. Logical operators
  6. Ternary operators
  7. Assignment operators.
Core java Unary operators:

The core java unary operator requires only one or a single command. In general, unary operators are used to performing various operations like,

  1. Increment or decrement the values one by one.
  2. Negation of an expression.
  3. Inverting any value of a Boolean.
Core java keywords:

The java keywords are also called “Reverse words”. The keywords are a particular form of words that acts as a key to a code. These keywords are predefined words, which cannot be used as an object or variable name.

List of Core java keywords:
  1. Abstract: Abstract keyword is used to declare an only abstract class. The abstract class offers the implementation of interface classes. This consists of abstract and non-abstract methods.
  2. Boolean: Boolean keyword is mainly used to declare the Boolean type variables. This can be of true or false values.
  3. Break: Break keywords are used to break the loop or switch statements. This will break the current flow of the specific program at the given condition.
  4. Byte: Byte keywords are used to declare a variable that consists of 8-bit data values.
  5. Catch: Case keywords are used to catch the exception handling generated by “Try” statements. This should be used after the “try” block only.
  6. Case: Case keywords are used with switch statements to terminate or block the program.
  7. Continue: Continue keywords are used to continue the programming loop. This will continue the current program flow and skip the code at the specified condition.
  8. Do: Do keywords used in the control statements declare only loops. This keyword iterates any part of the program multiple times.
  9. Enum: Enum keyword is used to specify the fixed set of constants. Enum constructors can be of type “private” or “default”.
  10. Final: Final keywords are used to indicate if any value holds a constant value type. This will be applied with a variable. The final keyword also restricts the users.
  11. Null: Null keywords are used to specify the reference that does not refer to anything. This also removes the garbage value.
  12. Package: Package is used to declare a core java package that consists of classes.
  13. Private: Private keywords are used as an access modifier. This is used to indicate the method or variable may be accessed only within a class.
  14. Protected: Protected keywords are used as an access modifier. It can be accessible within java packages and outside the package through any inheritance only. This protected keyword can’t be applied to the class.
  15. Public: Public keywords are used as an access modifier. This is used to specify the items which are accessible anywhere. The public keyword has the widest scope among any other modifiers.

Core Java classes and objects:

As I said earlier, Java is an object-oriented programming language. So we can assume that this program has the object-oriented feature, so core java supports the following concepts:

  1. Inheritance
  2. Polymorphism
  3. Abstraction
  4. Encapsulation
  5. Classes
  6. Objects
  7. Message passing
  8. Methods

Now let’s know the definitions of classes and objects:

Objects: Objects consist of states and behaviors. For example, a dog- this consists of various states like color, breed, name, and behaviors, barking, and eating. One more definition, an object is an instance of a class.

Class: A class can be defined as a blueprint or templates that specify the behavior or state that object possesses the support type.

Core Java Certification Training

Weekday / Weekend Batches

Classes in core java:

We already know the definition, now it’s time to know the sample program;

Public class Dog {

String breed_type;

Int age;

String color_type;

…..

…..

}

The below are the three types of class variables available;

  1. Local variables: These types of variables are defined inside the methods, blocks, and constructors. The variables are declared and initialized within the given methods and the variables will be destroyed when you complete the methods.
  2. Instance variables: Instance variables are types of variables within a class but visible outside any method. These instance variables are initialized when the class gets instantiated. Instance variables are accessed from inside any constructors, blocks, and methods.
  3. Class variables: the class variables are the type of variables that are declared within a given class, outside methods, by using static keywords.

Conclusion:

I hope I have given full justice to this amazing programming tutorial. In this core java tutorial, we have tried to cover almost basic to advanced level concepts. This tutorial is best suited for those who are already known about computer programs and software programming languages. To get in-depth knowledge in this Core java tutorial, best practice of few java related basic programs. Learning only the theoretical part is not enough to get into top MNC; you should get some practical experience or hands-on experience through joining the online course for a better understanding.

Find our upcoming Core Java Certification Training Online Classes

  • Batch starts on 28th Oct 2021, Weekday batch

  • Batch starts on 1st Nov 2021, Weekday batch

  • Batch starts on 5th Nov 2021, Fast Track batch

Global Promotional Image
 

Categories

Request for more information

Webinar

Python tutorial for beginners

5th April | 08:00 AM

150 Registered

Kavya Gowda
Kavya Gowda
Research Analyst
Kavya works for HKR Trainings institute as a technical writer with diverse experience in many kinds of technology-related content development. She holds a graduate education in the Computer science and Engineering stream. She has cultivated strong technical skills from reading tech blogs and also doing a lot of research related to content. She manages to write great content in many fields like Programming & Frameworks, Enterprise Integration, Web Development, SAP, and Business Process Management (BPM). Connect her on LinkedIn and Twitter.