Interview Questions and Answers - Order By Rating Q2221. 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 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 Q2223. 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 Q2224. 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) TestAns. 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 Q2226. 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. 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 Q2228. Is delete a keyword in Java ? Core Java
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 Q2229. 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 Q2230. 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 Q2231. 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 Q2232. Can we declare static variables as transient ? Core Java
Ans. It's weird that compiler doesn't complain if we declare transient with static variable because it makes no sense. At least a warning message saying "transient is useless in this situation" would have helped with code cleaning.
Static variables are never serialized and transient is an indication that the specified variable shouldn't be serialized so its kind of double enforcement not to serialize.
It could be that as it makes no different to the variable behavior and hence using both keywords with a variable are permitted. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  static  transient  serialization Asked in 1 Companies expert   rare Try 1 Question(s) Test Q2233. Which elements of a class are ignored during serialization ? Core Java
Ans. 1. Objects are serialized and not classes and hence Static variables are ignored.
2. Transient is an explicit declaration to ignore the variable during serialization and hence transient instance variables are ignored too.
3. Base class instance variables if the base class hasn't been declared serializable. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  serialization Asked in 1 Companies intermediate   frequent Try 1 Question(s) Test Q2234. 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 Q2235. Is it a good practice to use Asterick(*) in import statement to load multiple packages with single import statement ? Core Java
Ans. No, we should be lean in loading only packages which are required. Loading packages which are not being used result in memory overheads. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  import  import packages Asked in 1 Companies Q2236. 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 Q2237. Can we have multiple main methods in a single class ? Core Java
Ans. We can overload the main method by specifying different argument types. For example -
2 main methods with different arguments is perfectly legal
public static void main();
public static void main(String[] args);
The following are not legal as compiler will complain of duplicate methods
public static void main(String[] args);
public static void main(String[] args);
Even The following are not legal as we cannot overload on return types
public static String main(String[] args);
public static void main(String[] args); Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  main method Asked in 2 Companies Q2238. 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 Q2239. 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 Q2240. Explain various Searching and Sorting Algorithms ? Algorithm
This question was recently asked at 'HeadStrong,ServiceNow'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Search Algorithm  Sorting Algorithm Asked in 2 Companies basic   frequent Q2241. What is the problem with this code
double x=10.04;
int a = x;
Ans. It will give an error saying 'cannot convert from double to int' Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q2242. 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 Q2243. Scale yourself on Java on the scale of 1 to 10 General
Ans. [Open Ended Answer]
The objective of the question is to check how efficient one is in the language so that appropriate level questions are asked. Don't tell too high number if you are being interviewed for a junior or mid level position as the interviewer may throw advance level questions. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 17 Companies Q2244. How to make sure that no request are lost in client server application ? Solution
Ans. By keeping some sort of storage at the client side for each request and then matching it up against the response received to make sure that the request was well received.
A queue can be used for this purpose. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q2245. Trim a string without using String library method Core Java
This question was recently asked at 'Ariba'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  code  coding.string  trim a string Asked in 1 Companies Q2246. Why do you wan to stay in IT ? General
Ans. Coding , Science and Mathematics has always fascinated me. I have curious mindset that continuously look for solutions. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q2247. 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   Q2248. Why do you want to work here ? General
Ans. I believe that the company would provide a good ground for my career growth and learning. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q2249. Design an app to find 10 most visited urls Core Java
This question was recently asked at 'Wayfair'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q2250. Is there any relationship between Web.xml and Spring.xml ? Spring
Ans. No, there is no relationship between web.xml and spring.xml but you have to configure spring.xml in web.xml in order initialize beans when application starts up Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  spring  web.xml  spring.xml  deployment descriptor Asked in 1 Companies