Interview Questions and Answers - Order By Newest Q901. What is the difference between ServletConfig and ServletContext ? Java EE
Ans. http://www.java4s.com/java-servlet-tutorials/difference-between-servletconfig-and-servletcontext-in-java/ Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  ServletConfig  ServletContext Asked in 1 Companies Q902. Explain some of the features of Java ? Core Java
Ans. Object Oriented - Java is object oriented but isn't purely object oriented as we have primitives along with objects.
Platform Independent - As JVM provides the translation to the Machine code as per the underlying Operating System.
Interpreted as well as compiled - Java files are compiled as class files and then class files are interpreted by JVM.
Runs on a Virtual Machine - Which is JVM that acts as an independent sub environment.
Multi-threaded - As applications can run on single thread as well as multi thread.
Modularity - Through usage of Classes , methods and Interfaces.
Robust
Usage in variety of Application types - Web , Gaming, BigData. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve     frequent Q903. Name some of the Java Keywords ? Core Java
Ans. Static , Final , Synchronized, private , public , protected, volatile, transient, super, this,import , abstract,native,default (effective java 8), new Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java keywords   frequent Q904. Which operators in Java have highest precedence ? Core Java
Ans. Braces, i.e () and [] have the highest precedence Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java operators Q905. What is an exception and exception handling in Java ? Core Java
Ans. An Exception in java is the occurrence during computation that is anomalous and is not expected.
Exception handling is the mechanism which is used to handle such situations.
Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  exception handling Asked in 18 Companies basic   frequent Q906. How is hashcode calculated in java ?
or
What are the rules for hashcode calculation ? Core Java
Ans. General contract of hashCode is:
1.Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer,
2.If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
3.It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hashcode Asked in 1 Companies expert Q907. Why main method is declared static ? Core Java
Ans. static is the keyword that makes it accessible even without creating any object and using class name only. Making it non static would like creation of object upfront before calling the method. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  main method  static Asked in 4 Companies Basic Q908. Create a Class Bank with the methods to deposit and Withdraw ? Core Java
Ans. class Bank {
int balance;
Bank(){
balance = 0;
}
void deposit(int amount){
balance = balance amount;
}
int withdraw(int amount){
balance = balance - amount;
return balance;
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Basic Frequently asked in high end product companies. Ans. https://www.geeksforgeeks.org/lru-cache-implementation/ Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  cache  LRU cache  coding  code Asked in 10 Companies intermediate Q910. Can a constructor throw an exception ? Core Java
Ans. Yes Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q911. Can constructor be synchronized in Java ? Core Java
Ans. No, constructors can not be synchronized in Java. In fact using the keyword synchronized with a constructor results in compilation error. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies expert Q912. Will finally run if we have return statement and it exits the method early ? Core Java
Ans. finally will execute in all graceful situations - graceful executions as well as graceful exceptions. The only situation when finally block won't execute is when the app is abruptly stopped, killed or unplugged. Sample Code for finally Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  finally Intermediate Q913. What are different ways for Servlet authentication ? Java EE
Ans. HTTP Basic Authentication
HTTP Digest Authentication
HTTPS Authentication
Form Based Login Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q914. Is it mandatory to have a default constructor ? Core Java
Ans. No.
Default constructor is provided by compiler if no constructor is provided ( argument or no argument ) by us. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor  default constructor Asked in 1 Companies Try 1 Question(s) Test Q915. Which environment variables do we need to set in order to run Java programs? Core Java
Ans. PATH, CLASSPATH and JAVA_HOME Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  environment variables  path  classpath  java_home Asked in 3 Companies basic   frequent Q916. Can an application have multiple main methods within different classes ? If yes, How will the app decide which one to be executed ? Core Java
Ans. Yes we can have a main method with string[] argument in every class of an application. When we execute an app we specify the starting point i.e the class that will get the control first and hence main method of that class gets executed. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  main method Asked in 3 Companies Q917. Does importing a package imports all its sub packages too ? Core Java
Ans. No, but we can use wild card (*) to do so
For example -
import java.util.*
will import all packages with name starting with java.util Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  package   import packages Asked in 1 Companies basic Q918. What is the default value of a declared object reference ? Core Java
Ans. Null Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  object reference  null Asked in 1 Companies basic Q919. Is there a way to know size of an object in Java ? Core Java
Ans. No, Java doesn't have a sizeOf operator. In C / C++ , its required to determine how much memory allocation is required which is not the case with Java. Java handles memory allocation and deallocation intrinsically. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  sizeOf  size of object  sizeOf operator Asked in 1 Companies   rare Q920. What are the different ways to handle an exception ? Core Java
Ans. 1. Wrap the desired code in try block followed by a catch / finally to catch the exception
2. Declare the throws clause with exceptions that the code is expected to throw as an indication to the calling method to take care of it. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  exception handling Asked in 4 Companies Try 1 Question(s) Test Q921. How does Java handle integer overflows and underflows? Core Java
Ans. It uses those low order bytes of the result that can fit into the size of the type allowed by the operation. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  integer  data types Asked in 1 Companies   rare Ans. No, delete is not a keyword in Java. Destruction of objects is taken care by Java Garbage Collection mechanism. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  delete  keywords Asked in 1 Companies Ans. No exit is a method to exit execution of a program. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  exit  keywords  exit a program Asked in 1 Companies Q924. Who invokes a thread's run method ? Core Java
Ans. After a thread is started using a call to start method, JVM invokes the thread’s run method when the thread is initially executed. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  threads  thread run method Asked in 1 Companies Ans. Interface that is declared inside the interface or class, is known as nested interface. It is static by default. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  interface  nested interface intermediate Try 1 Question(s) Test Q926. What kind of thread is garbage collection thread ? Core Java
Ans. Daemon thread Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  garbage collection intermediate Try 2 Question(s) Test Q927. What is the difference between the Reader/Writer java.io hierarchy and the Stream class hierarchy? Core Java
Ans. The Reader/Writer hierarchy is character oriented, whereas the Stream class hierarchy is byte oriented. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java io  streams intermediate Ans. It's an object that reads from one stream and writes to another. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java io  io filter intermediate Q929. Can we convert a numeric IP address to a web host name ? Java EE
Ans. Yes, using InetAddress.getByName("<IP Address>").getHostName(); Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  ip address to hostname  INETAddress intermediate Q930. Difference between shallow copy and object cloning ? Core Java
Ans. Shallow copy is one of the way for object cloning, other being deep copy. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  cloning  shallow copy  object cloning basic