Previous | Home | Next |
Q.133 How can you add and remove nodes in Jtree?
Q.134 What is the method to expand and collapse nodes in a Jtree?
Answer: 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.
Answer: 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.
Q.137 What is the class in Swing to change the appearance of the Frame in Runtime?
Q.138 How to reduce flickering in animation ?
Answer: 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.
(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 %>}".
Answer: The main purpose ofJAVA 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.
Answer: 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.
Answer: 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:
Reuse: Java Beans able to implementing the appropriate interfaces, design conventions, and extending the appropriate classes provide the reusability concept in program.
Portability: Portability means write components once, reuse them everywhere without extra specification means no platform-specific issues is contend with component.
Q.143 What are the steps involved to create a bean ?
Answer: Two property in Beans is:
- getProperty()
- setProperty()
Answer: Two Type of persistence in java:
- Beans Persistence
- Java Persistence API
Answer: 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.
Answer: The Serializable interface is used in Beans.
Answer: Package.class.
Answer: Repeat
Answer: 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()); } } }
Answer: Repeat
Answer: Repeat
Answer: 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();
Answer: 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.
Q.155 In an HTML form I have a Button which makes us to open another page in 15 seconds. How will do you that ?
Answer: Use the following Program:
Answer:
Process | Threads |
Thread is a program which defines a separate path of execution, the thread is the smallest unit of dispatchable code. | A process is a program that is executing. |
Threads have direct access to the data segment of its process. | Processes have their own copy of the data segment of the parent process. |
Threads can directly communicate with other threads of its process. | Processes generally use inter process communication to communicate with sibling processes. |
Threads have almost no overhead because it is a single executed program. | processes have considerable overhead. |
Changes the behavior of main thread (cancellation, priority change, etc.) may affect the other threads of the process. | Changes to the parent process doesn't affect its child processes. |
Answer: Repeat
Answer: 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.
Answer: 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.
Q.160 How will you communicate between two Applets ?
Q.161 Have you ever used HashTable and Dictionary ?
Answer: In Java, Statements are a single instruction in a program – a single unit of code. Consider the following syntax:
packager4r.co.in; publicclassR4R { publicstaticvoidmain(String[]args) { //singleinstructioninaprogram--Statement intage=40; System.out.println("AgeofManis:"+age+"!"); } }
Answer: Repeat
Answer: 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.
Answer: All the swing components are derived from abstract javax.swing.JComponent class.
Answer: 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.
Answer: Repeat- Swing extends AWT by adding many components and services.
Q.168 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 ?
Answer: 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.
Q.170 How will you call an Applet using a Java Script function ?
Answer: 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>
Answer: 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:
- public Canvas()
- public void addNotify()
- public void paint(Graphics graphic)
Answer: Repeat -Similar to communicate in between Applets & Servlets
Answer: Repeat
Answer: 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.
Answer: The layout for Toolbar is Flow Layout.
Answer: 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.
Answer: 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:

Answer: The corresponding Layout for Card in Swing CardLayout.
Answer: Repeat
Answer: Repeat
Q.182 What is difference in between Java Class and Bean ?
Previous | Home | Next |