Interview Questions and Answers - Order By Newest Q1241. 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 Q1242. 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 Q1243. 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 Q1244. 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 Q1245. 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 Q1246. 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 Q1247. 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 Q1248. 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 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 Q1250. 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 Q1252. 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 Q1253. 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 Q1255. 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 Q1256. 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 Ans. Shutdown hook is a thread that is invoked before the JVM is shut down. we can use it perform resource cleaning task. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  shutdown hook  jvm Try 1 Question(s) Test Q1258. Which interface is responsible for transaction management in JDBC ? Database
Ans. Connection Interface Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  jdbc Q1259. how to access the methods of an inner class? Core Java
Ans. It depends on the type of inner class
To access non static inner class method
new OuterClass().new InnerClass().getMethod();
To access static method of static inner class
new OuterClass.InnerClass().getMethod(); Sample Code for inner class Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  inner classes  nested aclasses Asked in 1 Companies Intermediate   frequent Q1260. Which memory segment holds String Pool in Java ? Core Java
Ans. String Pool resides in runtime constant Pool which is a part of Heap memory segment. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  string pool  memory management Expert   rare Q1261. What are the cursors available in Java ? Core Java
Ans. Enumeration
Iterator
List iterator Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  cursors  iterator Q1262. What is SWT ? SWT
Ans. SWT is an open source widget tool kit for developing rich, efficient and portable GUI applications. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  swt Q1263. Which is the highest level container which contains other widgets in SWT ? SWT
Ans. Shell Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q1264. Can we run Swing objects using SWT ? SWT
Ans. Yes Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q1265. What are the key components of SWT applications ? SWT
Ans. The Display and Shell classes are key components of SWT applications.
A org.eclipse.swt.widgets.Shell class represents a window.
The org.eclipse.swt.widgets.Display class is responsible for managing event loops, fonts, colors and for controlling the communication between the UI thread and other threads. Display is the base for all SWT capabilities. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q1266. Are SWT Widgets automatically Gabage collected ? SWT
Ans. SWT widgets are not automatically garbage collected. If you release an SWT widget, you have to call its dispose() method. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q1267. How do we do event handling using SWT ? SWT
Ans. We do it by registering listeners for respective widgets Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q1268. Explain Layout Managers in SWT ? SWT
Ans. A layout manager is responsible for arranging the user interface components of a container, e.g. a Composite, on the screen. SWT offers several standard layout managers.
Following are the layout managers offered by SWT
AbsoluteLayout
FillLayout
RowLayout
GridLayout
FormLayout Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q1269. Have you worked with the TreeViewer ? If yes , explain SWT
Ans. The TreeViewer class provides viewer support for displaying trees. This widget is used to display parent-child information with buttons to expand and collapse the tree.
We have to create and specify the LabelProvider and Content Provider classes. In the respective classes we specify the parent and child objects and their relationship. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q1270. Which class is used to create buttons and how many classes we have to create different button types ? SWT
Ans. Only a single class ie Button is used to create all button types. We distinguish among different types by specifying the style while creating a new button object. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve