Hello Friends, In this Blog Post I am going to let you know about a few more interview questions of core java related to Packages and Exception handling.
Core java interview questions covers all the important questions of the topics mentioned above.
These core java interview questions is a great help to remember all the important highlights and important topics from each java chapter.
These interview questions will surely help to understand a few very confusing concepts in java.
A programmer is writing the following statements in a program?
1. import java.awt.*;
2. import java.awt.*event.*;
Should he write both the statements in his program or the first one is enough?
event is a sub package of java.awt package. But when a package is imported, its sub-packages are not automatically imported into a program. So, for every package or sub-packages, a separate import statement should be written.
Hence it the programmer wants the classes and interfaces of both the java.awt and java.awt.event packages, then he should write both the preceding statements in his program.
How can you call the garbage collector?
We can call the garbage collector of JVM to delete any unused variables and unreferenced objects from memory using gc() method. This gc() method appears in both runtime and system classes of java.lang package. For example, we can call it as :
What is CLASSPATH?
The CLASSPATH is an environment variable that tells the java compiler where to look for class files to import. CLASSPATH is generally set to a directory or a jar(java archive) file.
What is JAR file?
A java archive file(JAR) is a file that contains a compressed version of several .class files, audio files, images files, or directories. JAR file is useful to bundle up several files related to a project and use then easily.
What is the scope of default access specifier?
Default members are available within the same package, but not outside of the package. so their scope is package scope.
What happens if the main() method is written without string args?
The code compiles but JVM can not run it, as it can not see the main() method with string args.
What are the checked exceptions?
The exceptions that are checked at compilation-time by the java compiler are called ‘checked exception’ The exceptions that are checked by the JVM called ‘unchecked exceptions’.
What is throwable?
Throwable is a class that represents all errors and exceptions which may occur in java.
What is super class for all exceptions?
Exception is the super class of all exceptions in java.
What is the difference between an exception and an errror?
an exception is an error that can be handled. It means when an exception happens, the programmer can do something to avoid any harm. But an error is an error that can not be handled, it happens and the programmer can not do anything.
What is the difference between throws and throw?
The Throws clause is used when the programmer does not want to handle the exception and throw it out of a method. Throw clause is used when the programmer wants to throw an exception explicitly and wants to handle it using a catch block. Hence, throws and throw are contradictory.
It is possible to re-throw exceptions?
Yes, we can re-throw an exception from catch block to another class where it can be handled.
So this was all about the Core java interview questions in this topic.
These Core java interview questions could be a great help in your college viva, academic study, and any job interview.
In the case of any queries, you can write to us at [email protected] we will get back to you ASAP.
Hope! you would have enjoyed this post about Core Java Interview Questions Part 14/Packages and Exception handling.
Please feel free to give your important feedbacks in the comment section below.
Have a great time!