Write & Compile Java Program
...
Duration
25 hoursCourse Price
$ 399.004.5 (23)
AutomationTraining4u is a leading training and consultancy group which impart knowledge on the particular program with the best trainers in IT having more than 10+ years of experience. We focus on real time based training & practical knowledge.
Training with Automation Training4U will benefit on the following ways in one’s career:
An instance of a class is called an object. An object consists of methods and classes that depict its state and perform operations. A Java program contains a lot of objects instructing each other their jobs. This concept is part of core Java. The object has state and behavior.
Whenever the JVM reads the “new()” keyword then it will create an instance of that class.
Example:
public class Addition{ public static void main(String[] args){ Addition add = new Addition();//Object creation } } |
The above code creates the object for the Addition class.
All Java codes are defined in a Class. Java encapsulates codes in various classes that define new data types. These new data types are used to create objects. It has variables and methods.
Variables are attributes which define the state of a class.
Methods are the place where the exact business logic has to be done. It contains a set of statements (or) instructions to satisfy the particular requirement.
Example:
public class Addition{ //Class name declaration int a = 5; //Variable declaration int b= 5; public void add(){ //Method declaration int c = a+b; } } |
OOPs concepts include:
Inheritance means one class can extend to another class. So that the codes can be reused from one class to another class. The existing class is known as the Super class whereas the derived class is known as a sub class. Inheritance lets a derived class inherit the methods of a base class.
Example:
Super class: public class Manupulation(){ } Sub class: public class Addition extends Manipulation(){ } |
Inheritance is applicable for public and protected members only. Private members can’t be inherited.
The Purpose of Encapsulation is:
Example:
We are declaring ‘a' as an integer variable and it should not be negative.
public class Addition(){ int a=5; } |
If someone changes the exact variable as “a = -5” then it is bad.
In order to overcome the problem we need to follow the below steps:
So that the above code can be modified as:
public class Addition(){ private int a = 5; //Here the variable is marked as private } |
The below code shows the getter and setter.
Conditions can be provided while setting the variable.
get A(){ } set A(int a){ if(a>0){// Here condition is applied ......... } } |
For encapsulation, we need to make all the instance variables as private and create setter and getter for those variables. Which in turn will force others to call the setters rather than access the data directly.
Polymorphism means many forms.
A single object can refer to the super-class or sub-class depending on the reference type which is called polymorphism.
Example:
Public class Manipulation(){ //Super class public void add(){ } } public class Addition extends Manipulation(){ // Sub class public void add(){ } public static void main(String args[]){ Manipulation addition = new Addition();//Manipulation is reference type and Addition is reference type addition.add(); } } |
Multiple inheritances cannot be achieved in java. To overcome the problem of multiple inheritance, Interface concept is introduced.
An interface is a template which has only method declarations and not the method implementation.
When a Java program contains more than one method with the same name but with different properties, then it is called as method overloading.
A vector class provides the ability to execute a growable array of objects. A vector proves to be very useful when you don’t know the size of the array in advance or if we need one that can change the size over the lifetime of a program.
An Exception is a problem which could occur during the normal flow of execution. A method can throw an exception when something wails at runtime. If that exception couldn’t be handled, then the execution gets terminated before it completes the task.
If we handled the exception, then the normal flow gets continued. Exceptions are a subclass of java.lang.Exception.
Example for handling Exception:
try{ //Risky codes are surrounded by this block }catch(Exception e){ //Exceptions are caught in catch block }
|
There are two types of Exceptions. They are explained below in detail.
A) Checked Exception:
These exceptions are checked by the compiler at the time of compilation. Classes that extend Throwable class except Runtime exception and Error are called checked Exception.
Checked Exceptions must either declare the exception using throws keyword (or) surrounded by appropriate try/catch.
For Example, ClassNotFound Exception
B) Unchecked Exception:
These exceptions are not checked during the compile time by the compiler. The compiler doesn’t force to handle these exceptions. It includes:
Two different ways to handle exception are explained below:
a) Using try/catch:
A risky code is surrounded by try block. If an exception occurs, then it is caught by the catch block which is followed by the try block.
Example:
class Manipulation{ public static void main(String[] args){ add(); } Public void add(){ try{ addition(); }catch(Exception e){ e.printStacktrace(); } } } |
b) By declaring throws keyword:
At the end of the method, we can declare the exception using throws keyword.
Example:
class Manipulation{ public static void main(String[] args){ add(); } public void add() throws Exception{ addition(); } }
|
The advantages of exception handling are as follows:
Below are the Exception Handling Keywords:
a) try:
When a risky code is surrounded by a try block. An exception occurring in the try block is caught by a catch block. Try can be followed either by catch (or) finally (or) both. But any one of the blocks is mandatory.
b) catch:
This is followed by try block. Exceptions are caught here.
c) finally:
This is followed either by try block (or) catch block. This block gets executed regardless of an exception. So generally clean up codes are provided here.
Lazy loading is a kind of setting that decides whether to load the child entities along with the parent entities or not. When enabling this feature, the associated entities will be loaded only when they are requested directly. The default value of this setting is ‘true’ which stops the child entities from loading.
We can fetch records from the database by the query method of JdbcTemplate. There are two interfaces to do this:
The Dispatcher Servlet class works as the front controller in Spring MVC.
The states of an object in hibernate are:
If we mark a class as mutable=”false”, the class will be treated as an immutable class. The default value of mutable is “true”.
In HashTable, when two different keys have the same hash value, then it leads to hash-collision. A bucket of type linked list is used to hold the different keys of the same hash value
You need to extend Exception class to create custom exception. If you want to create Unchecked exception, then you need extend Runtime Exception.
No, you cannot directly call run method to start a thread. First you need to call start method to create a new thread. If you call run method directly, it won’t create a new thread and it will be in same stack as main.
This method is used to invoke garbage collection for clean up unreachable object but it is not guaranteed that when you invoke System.gc() , garbage collection will definitely trigger.