HOME      BLOG       FORUMS      CONTACT       ABOUT

Core Java interview questions – Part 10

151. What is meant by Open Source ?
In general, open source refers to any program whose source code is made available for use or modification as users or other developers see fit. Open source software is usually developed as a public collaboration and made freely available.

152. How do you send data from an applet to Servlet ? What are the steps involved in it ?
You can use the java.net.URLConnection and java.net.URL classes to open a standard HTTP connection to the web server. The server then passes this information to the servlet in the normal way.

Basically, the applet pretends to be a web browser, and the servlet doesn’t know the difference. As far as the servlet is concerned, the applet is just another HTTP client.

153. What is polymorphism?
It is the ability of an object to behave differently on different situations for the same message.

54. What is a class, member and local variable?
Variables declared within a method are local variables. Variables declared within the class are member variables. Variables declared within the class with static modifier are class variables

155. How do I convert a numeric IP address like 66.29.36.130 into a hostname like www.javacertificate.net

String hostname = InetAddress.getByName("66.29.36.130").getHostName();

156. What is the difference between a constructor and a method?
A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator. We cannot invoke a constructor directly. A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.

157. What are the different inner classes types?
There are mainly four types available. They are Member classes, Nested top-level classes, Local classes, Anonymous classes

158. What is Nested top-level classes?
A class declared within a class with static modifier is called nested top level class. Any class outside the declaring class can access the nested top level class with the declaring class dot nested top level class. Top-level inner classes have access to static variables only .

159. What is Member classes?
A class declared inside a class without static modifier is called member class. Member classes are just like any other member methods or member variables.

160. What is Local inner classes ?
Local inner classes are class declared inside a block of code. They are visible only within the block of their declaration.

161. Can a top level class be private or protected?
No. A top level class can not be private or protected. It can have either “public” or no modifier.

162. How will you invoke any external process in Java?
By using Runtime.getRuntime().exec(….)

163. What is a package?
To group set of classes into a single unit is known as packaging. Packages provides wide name space visibility.

164. What is the use of assert keyword
Assert keyword validates certain expressions. It replaces the if block effectively and throws an AssertionError on failure. The assert keyword should be used only for critical arguments (means without that the method does nothing).

165. What is composition?
Holding the reference of the other class within some other class is known as composition.

Share

Tags: , , ,


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply