Raja has Published 760 Articles

What are the different steps involved to execute a Java program?

raja

raja

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

2K+ Views

Java program execution follows 5 majors stepsEdit - Here the programmer uses a simple editor or a notepad application to write the java program and in the end give it a ".java" extension.Compile - In this step, the programmer gives the javac command and the .java files are converted into ... Read More

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

raja

raja

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

14K+ 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

What are the differences between recursion and iteration in Java?

raja

raja

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

2K+ Views

The Recursion and Iteration both repeatedly execute the set of instructions. Recursion is when a statement in a function calls itself repeatedly. The iteration is when a loop repeatedly executes until the controlling condition becomes false. The primary difference between recursion and iteration is that recursion is a process, always applied to a function ... Read More

What are the differences between ClassNotFoundException and NoClassDefFoundError in Java?

raja

raja

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

4K+ Views

Both ClassNotFoundException and NoClassDefFoundError are the errors when JVM or ClassLoader not able to find appropriate class while loading at run-time. ClassNotFoundException is a checked exception and NoClassDefFoundError is an Error which comes under unchecked.There are different types of ClassLoader loads classes from difference sources, sometimes it may cause library JAR files missing or incorrect ... Read More

Can we define a parameterized constructor in an abstract class in Java?

raja

raja

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

3K+ Views

Yes, we can define a parameterized constructor in an abstract class.Conditions for defining a parameterized constructor in an abstract classWe need to make sure that the class which is extending an abstract class have a constructor and it can call the superclass parameterized constructor.We can call the superclass parameterized constructor ... Read More

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

raja

raja

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

1K+ 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

4K+ 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

363 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

4K+ 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

Can we write any code after throw statement in Java?

raja

raja

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

1K+ Views

No, we can not place any code after throw statement, it leads to compile time error Unreachable Statement.Throw keyword in JavaThe throw keyword is used to throw an exception manually.Whenever it is required to suspend the execution of the functionality based on the user-defined logical error condition, we will use this ... Read More

Advertisements