R4R
Right Place For Right Person TM
 

R4R Java Core Java Faqs
Previous

Home

Next

300 Core java interview questions

151. How can you add and remove nodes in Jtree?

// program

152. What is the method to expand and collapse nodes in a Jtree?

//program

153. What is the use of JTable ?
Ans: 
JTree is a method to display hierarchical data although it doesn't contain data while provide a simple view of data( JTree displays its data vertically). Each row displayed by the tree contains exactly one item of data, which is called a node.Each tree has a root node from which all nodes descend.

154. What is meant by JFC ?
Ans:
The Java Foundation Classes (JFC) are a graphical framework for building portable
Java-based graphical user interfaces (GUIs). The  JFC consists of the Abstract Window Toolkit (AWT), Swing and Java 2D. Together, they provide a consistent user interface for Java programs, regardless whether the underlying user interface system is Windows, Mac OS X or Linux.

155. What is the class in Swing to change the appearance of the Frame in Runtime?
Ans:

156. How to reduce flickering in animation ?

157. What is meant by Javabeans ?
Ans: Java Beans( jsp:useBean) is used for the purpose of reusable, platform-independent and portable to create sophisticated application . Beans are dynamic generated hence easily to customized. 

JavaBeans  (Syntax:   <jsp:useBean id=" " scope="page|request|session|application" class=" " type=" " beanName=" " />)

                        id="beanInstanceName"
                        scope="page|request|session|application"

                                  page:  valid until page is complete.
                                  request: bean instance lasts for the client request.
                                  session: bean lasts for the client session.
                                  application: bean instance created and lasts until application ends.

                        class & type ="package.class"
                        beanName="{package.class | <%= expression %>}".

158. What is JAR file ?
Ans:
The main purpose of  JAVA  ARCHIVE( jar) file is store many file inside one archive act as ZIP file. A  .jar file is generally used for distribute Java Application or libraries in the form of classes, associated with metadata and resource such as test, image, doc, etc. A JAR must contain manifest file locate in the path META-INF/MANIFEST.MF.

159. What is meant by manifest files ?
Ans:
A manifest file is a specific file contained within a JAR archive file, use to define extension and package related data. If a JAR file is intended to be used as an executable file, the manifest file specifies the main class of the application. The manifest file is named MANIFEST.MF.

160. What is Introspection in Java?
Ans:
Introspection is the mechanism to analyzing a bean's design patterns to reveal the bean's properties, events, and methods, size, color etc. It controls the publishing of beans and discovery of bean operations and properties. Introspection provide great advantage in beans by implement two property which is-

  1. Reuse- Java Beans able to implementing the appropriate interfaces, design conventions, and extending the appropriate classes provide the reusability concept in program.
  2. Portability- Portability means write components once, reuse them everywhere without extra specification means no platform-specific issues is contend with component.

161. What are the steps involved to create a bean ?

162. Say any two properties in Beans ?
Ans:
Two property in Beans is--

  • getProperty()
  • setProperty()

163. What is persistence in Java ?
Ans: 
Two Type-- Beans Persistence  and Java Persistence API

164. What is the use of beanInfo ?
Ans:
BeanInfo classes provides a high degree of control over how a bean appears and behaves at design time. BeanInfo classes are design-time-only classes. If a bean implementer wants to provide information regarding methods, properties when they can provide a bean info class by implementing BeanInfo interface and provide information regarding the bean properties, methods etc.

165. What are the interfaces you used in Beans ?
Ans: 
The Serializable interface is used in Beans.

166. What are the classes you used in Beans ?
Ans:
Package.class.

167. What is the difference between an Abstract class and Interface?
Ans:
Repeat  

168. What is user defined exception ?
Ans:
Use the following program--

/*
 * Save as a FileUpload.java
 * Program for Upload file content from a Text file.
 * Use as a User Define Exception "File Not Found Exception"
 */

package r4r.co.in;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class FileUpload {

    public static void main(String[] args) {
        //File path store in file name
        
       // String filename = "C:\\R4R\\waste.txt"; (Actual file Path and name)

        /*
         * Now for Generate Exception, just rename the file
         * Command upper Syntax line, and use this
         */

         String filename = "C:\\R4R\\wastage.txt"; //Fake file, for Generate Exception

        String string = System.getProperty("LINE SEPRATOR:filename");
        StringBuffer buffer = new StringBuffer();
        try {
            //File load into buffer
            FileReader reader = new FileReader(filename);
            BufferedReader br = new BufferedReader(reader);

            //read single line from the file
            System.out.println("Parameter from the file:");
            String line;
            while ((line = br.readLine()) != null) {
                buffer.append(line).append(string);
                System.out.println(line.toString());
            }
           } catch (IOException ioe) {
            System.out.println("Exception Generate: " + ioe.getMessage());
        }

    }
}

Result: Exception Generate: C:\R4R\wastage.txt (The system cannot find the file specified)


169. What do you know about the garbage collector ?
Ans:
Repeat 

170. What is the difference between C++ & Java ?
Ans:
Repeat 

171. How do you communicate in between Applets & Servlets ?
Ans:
 Applet can communicate with servlet by using GET and POST method, that means when applet is send data to servlet used GET method( must URL encode, name and value) and receive value from POST method. URL connection work as a bridge between applet and servlet.
 Following syntax is used  for such connection:-

     
//Establise a connection between applet and servlet
        String location = "http://      ";
        URL servlet = new URL(location);
        URLConnection connection = servlet.openConnection();

        //Bridge is ready to send data as output and receive input
        connection.setDoInput(true);
        connection.setDoOutput(true);

        //Don't used catch version of URL connection
        connection.setUseCaches(false);
        connection.setDefaultUseCaches(false);  //Use this also

        //Send  HTTP request for binary data transfer
        connection.setRequestProperty("Content-Type", "value - the value associated with it");
        //Now, Data is ready as input and output transfer
       
connection.getOutputStream();

172. What is the use of Servlets ?
Ans:
Uses of the servlet is-

  • Servlet is generally used for providing dynamic content into web server. 
  • Servlet can able to access the large set of APIs available for the Java platform.
  • Servlet use a standard API that is supported by many Web servers.
  • Servlet is loaded into once into memory can called as many time as needed.
  • Servlet is provide uniform API( Java application programming interface) for maintaining session data from client browser throughout Web server.
  • Servlet can able to handle multiple request concurrently in the synchronize manner.

173. In an HTML form I have a Button which makes us to open another page in 15 seconds. How will do you that ?
Ans:
Use the following Program--

174. What is the difference between Process and Threads ?
Ans: 

Process

Threads

  1. Thread is a program which defines a separate path of execution, the thread is the smallest unit of dispatchable code.
  2. Threads have direct access to the data segment of its process.
  3. Threads can directly communicate with other threads of its process.
  4. Threads have almost no overhead because it is a single executed program.
  5. Changes the behavior of main thread (cancellation, priority change, etc.) may affect  the other threads of the process.
  1. A process is a program that is executing.
  2. Processes have their own copy of the data segment of the parent process.
  3. Processes generally use inter process communication to communicate with sibling processes.
  4. processes have considerable overhead.
  5. Changes to the parent process doesn't affect its child processes.


175. How will you initialize an Applet ?
Ans:
Repeat  

176. What is the order of method invocation in an Applet ?
Ans: 
Applet’s life cycle methods is used in an Applet invocation--

  • void init(): Initialization method called only once by the browser.
  • void start(): Method called after init() and contains code to start processing or stat the applet inside the browser.
  • void stop(): Stops all processing started by start ().
  • void destroy(): Called if current browser session is being terminated and free all the resource by applet.

177. When is update method called ?
Ans:
In Applet, whenever a screen needs redrawing (e.g., upon creation, resizing, validating, and write) the update method is called. By default, update method clears the screen and then calls the paint method, which normally contains all the drawing code.

178. How will you communicate between two Applets ?

179. Have you ever used HashTable and Dictionary ?

180. What are statements in JAVA ?
Ans:
In Java, Statements are a single instruction in a program – a single unit of code. Consider the following syntax:

  package r4r.co.in;

     public class R4R 
    {
	public static void main(String[] args) 
	{
		//single instruction in a program-- Statement
		int age=40;
		System.out.println("Age of Man is:" +age+"!");
	}
      }

181. What is JAR file ?
Ans:
Repeat

182. What is Java Native Interface( JNI) ?
Ans:
Java Native Interface (JNI) is a programming frame work that allows Java code running in a Java Virtual Machine (JVM). It is use to call the libraries written in other languages, such as C, C++ and assembly.

183. What is the base class for all swing components ?
Ans: 
All the swing components are derived from abstract javax.swing.JComponent class.

184. What is Java Foundation Classes (JFC) ?
Ans: 
Swing/ JFC is the primary Java Graphical User Interface( GUI) widget toolkit, offers lightweight Java language specific GUI controls. It is consist of group of class, library
 
and services which add rich graphics functionality and interactivity to Java applications.

185. What is Difference between AWT and Swing ?
Ans:
Repeat  -- Swing extends AWT by adding many components and services.

186. Considering notepad/IE or any other thing as process, What will Happen if you start notepad or IE 3 times? Where 3 processes are started or 3 threads are started ?

187. How does thread synchronization occurs inside a monitor?
Ans:
A thread can acquire the lock for an object by using the synchronized keyword. Each monitor is associated with an object reference. When a thread arrives at the first instruction in a block of code it must obtain a lock on the referenced object. The thread is not allowed to execute the code until it obtains the lock. Once it has obtained the
lock, the thread enters the block of protected code. When the thread leaves the block, no matter how it leaves the block, it releases the lock on the associated object.

188. How will you call an Applet using a Java Script function ?
Ans:

189. Is there any tag in HTML to upload and download files ?
Ans:
Use the following program-

<html>
  <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
      <H1>Use as a upload file from system</H1>
      <form name="form" method="post" enctype="multipart/form-data" action="FileName">
          <BR>
          <input type="file" name="file" value="" size="30" />
          <BR><BR>
          <input type="Button" value="    SubmitDocument   " name="Submit" >
      </form>
  </body>
</html>

190. Why do you Canvas ?
Ans: 
Canvas class belongs to the java.awt  package. It is a rectangular area on which something drawing by using the methods of java.awt.Graphics.
 The Canvas class has only three methods:

  1. public Canvas()
  2. public void addNotify()
  3. public void paint(Graphics graphic)

191. How can you push data from an Applet to Servlet ?
Ans:
Repeat --Similar to communicate in between Applets & Servlets

192. What are the benefits of Swing over AWT ?
Ans:
Repeat  

193. Where the CardLayout is used ?
Ans:
CardLayout is unique in all other layout managers because it's class is used for switch between two panels. The CardLayout class manages two or more components (usually JPanel instances) that share the same display space and allow user to choose between the components by using a combo box.

194. What is the Layout for ToolBar ?
Ans:
The layout for Toolbar is Flow Layout.

195. What is the difference between GridLayout and GridbagLayout ?
Ans:
GridLayout class allow to all the components in a rectangular grid like structure of container. The container is divided into an equal sized rectangles and each component is placed inside a rectangle.
      The GridBagLayout class is a flexible layout manager that aligns components vertically and horizontally, without requiring that the components be of the same size. Each GridBagLayout object maintains a dynamic, rectangular grid of cells, with each component occupying one or more cells, called its display area.

196. How will you add panel to a Frame ?
Ans: Use the following Program--

/*
 * Save as a newFrame.java
 * Program dispaly JPanel add to JFrame
 */
package r4r.co.in;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class newFrame extends javax.swing.JFrame {

    private JLabel lable;

    public newFrame() {
        JFrame frame = new JFrame("Frame that hold JPanel");
        JPanel panel = new JPanel();
        frame.setVisible(true);
        frame.setSize(400, 200);
        panel.setLayout(null);
        lable = new JLabel("Lable add inside a panel");
        lable.setBounds(50, 10, 140, 30);
        //Lable add into frame
        panel.add(lable);
        //Add panel into Frame
        frame.getContentPane().add(panel);
    }

    public static void main(String[] args) {
        JFrame frame = new newFrame();
    }
}

Output:  
        

197. What is the corresponding Layout for Card in Swing ?
Ans:
The corresponding Layout for Card in Swing CardLayout.

198. What is light weight component ?
Ans:
Repeat 

199. What is bean ? Where it can be used ?
Ans:
Repeat 

200. What is difference in between Java Class and Bean ?


 
500 Java Objective Questions and Answer

Previous

Home

Next

New Updates

R4R
R4R
R4R
R4R
R4R
R4R
R4R
R4R