Raja has Published 469 Articles

What is the importance of "Java.lang.Class" in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

443 Views

The java.lang.Class is one of the most important class in Java and it can provide several utility methods like getClass(), forName() which is used to find and load a class. It can also provide methods like Class.newInstance() which is the backbone of reflection and allow us to create an instance of a class ... Read More

Must we implement all the methods in a class that implements an interface in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

9K+ Views

Yes, it is mandatory to implement all the methods in a class that implements an interface until and unless that class is declared as an abstract class.There are only two choices −Implement every method defined by the interface.Declare the class as an abstract class, as a result, forces you to ... Read More

How to set JAVA_HOME environment variables on Windows OS in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

2K+ Views

Once you have installed JDK version on your windows machine, you have to set up Environment Variables.Please find below steps to set the java pathGo to My Computer ---> Right Click on it ---> Advanced System Settings ---> Advanced Tab ---> Click on Environment VariablesNow you have to alter the ... Read More

How to rethrow an exception in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

19K+ Views

Sometimes we may need to rethrow an exception in Java. If a catch block cannot handle the particular exception it has caught, we can rethrow the exception. The rethrow expression causes the originally thrown object to be rethrown.Because the exception has already been caught at the scope in which the ... Read More

Why the main () method in Java is always static?

raja

raja

Updated on 30-Jul-2019 22:30:26

17K+ Views

Java main() method is always static, so that compiler can call it without the creation of an object or before the creation of an object of the class.In any Java program, the main() method is the starting point from where compiler starts program execution. So, the compiler needs to call ... Read More

How can we call garbage collection (GC) explicitly in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

2K+ Views

When there are no more references to an object, the object is finalized and when the Garbage Collection starts these finalized objects get collected this will done automatically by the JVM. We can call garbage collection directly but it doesn't guarantee that the GC will start executing immediately.We can call ... Read More

How to throw an exception from a static block in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

6K+ Views

A static block is a set of statements, which will be executed by the JVM before the execution of the main() method. At the time of class loading if we want to perform any activity we have to define that activity inside a static block because this block executes at ... Read More

Why do we need a copy constructor and when should we use a copy constructor in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

483 Views

A copy constructor is a parameterized constructor and it can be used when we want to copy the values of one object to another.Example:class Employee {    int id;    String name;    Employee(int id, String name)    {       this.id = id;       this.name ... Read More

Can a constructor throw an exception in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

6K+ Views

Yes, constructors are allowed to throw an exception in Java.A Constructor is a special type of a method that is used to initialize the object and it is used to create an object of a class using the new keyword, where an object is also known as an Instance of a class. Each ... Read More

Advertisements