Core Java for Beginners

Qatestingleaders
4 min readJul 21, 2023

--

Java is a high-level, platform-independent programming language.

Java is made up of various objects. Sun Microsystems created it. Many programmers, websites, and video games are created using the Java programming language.

In Java, there are 7 characteristics: —
Object-oriented
Inheritance
Encapsulation
Polymorphism
Abstraction
Platform independent
multi-Threaded

Java support high performance, just in Time compiler is used by Java to enable great performance. The instructions are changed into bytecodes using it.

The Java IDEs are Eclipse and NetBeans.

There are some constructors in Java, whenever a new object is generated in a programme, the appropriate constructor for the class is called.
A method with the same name as the class is the constructor.
A default constructor will be built if the user doesn’t explicitly build one.
It’s possible to overload the constructor.
If a constructor with a parameter was established by the user, he or she should expressly create another constructor without a parameter.

In Java there are two main terms “Local variable” and “Instance variable”: -The definition of local variables and their range are contained within the method itself.

Instance variables are defined inside and outside of the method, and their scope is shared by the class.

In a class, all Java codes are defined.

Variables are characteristics that specify how a class is in a state.

Methods is a place where the business logic is defined. It includes a set of statements (or) instructions to satisfy a particular requirement.


Instance of a class is called object. It has state and behavior.
Every time the JVM encounters the “new()” keyword, an instance of that class will be created.

OOPs concepts are as follows:

Inheritance
Encapsulation
Polymorphism
Abstraction
Interface

Inheritance refers to the ability of one class to extend to another class. So the codes can be transferred between classes. The derived class is referred to as a subclass, whereas the original class is known as the super class.

Objective of the Encapsulation:
Protects the code from others.
Code maintainability.

Polymorphism means many forms.
Polymorphism is the ability of a single object to refer to either a super-class or a sub-class depending on the reference type.

The following conditions must be met by the sub-class method and the super-class method in order for method overriding to occur:

The same method name should be used.
The case ought to be the same.
Return type ought to be the same as well.
The main advantage of overriding is that it allows the subclass to supply more precise information than the superclass about that subclass type.

The correct answer is that method overloading can occur between classes or even inside the same class.

For method overloading, the child-class method together with the parent-class method (or) methods from the same class itself should meet the following requirements:

Same method name
Different argument types
There may be different return types

In Java, multiple inheritances are not possible. The Interface concept is presented as a solution to this issue.

An interface is a template that just contains method declarations — not the actual implementation of the methods.

The “Abstract” keyword placed before the class name allows us to build the Abstract class. Both “Abstract” and “Non-abstract” functions that are of a concrete class can be found in an abstract class.

Abstract Method:

The abstract method has a declaration and no implementation, and it has the keyword “abstract” in its name. A semicolon marks the end of a declaration.

Ordered: A collection’s storage of values as being based on the values that have been added to the collection. Consequently, we are able to iterate the collection’s values in a particular order.

Sorted: Sorting techniques can be used internally or externally to organise a bunch of things into a collection according to their characteristics.

An issue that can arise in the course of normal execution is known as an exception. When something fails during execution, a procedure may throw an exception. The execution is stopped before it completes the task if the exception couldn’t be handled.

If exception is handled, the process returns to normal. A subclass of java.lang is exceptions. Exception.

The flow of execution in Java is known as a thread. The main thread, which is created by JVM, is one of the threads that every Java programme possesses. By extending the Thread class or by implementing the Runnable interface, the user can create their own threads. Concurrent thread execution is used.

To make a thread wait in a waiting pool, use the wait () method. When a thread executes the wait () method, the thread instantly relinquishes the lock on the object and moves to the waiting pool. The Wait () function instructs a thread to wait for a specified period of time.

After the notify () (or notify all () method is executed, the thread will then reactivate.

The lock on the object is not immediately released by Wait() or any of the other methods indicated above until the thread that is presently running the synchronized code has finished. Most often, synchronization uses it.

--

--