More interview questions and answers |
---|
ThreadPools are useful when you need to limit the number of threads running in your application. Built in thread pools in the java.util.concurrent package. |
A constructor is a member function of a class that is used to create objects of that class. |
What is the difference between frame work and api? Why we called collections framework? |
instanceof operator is used to check whether the object is an instance of the class or subclass or interface. |
StringBuffer |
Yes! We can invoke the main() method of one class in another class. Since main() method is a static method, it can be invoked by using the class name with the method name. |
What is the difference between java command line arguments and C command line arguments? |
In C command line arguments, values are passed in the main() method having the two parameters. |
The == and eqauls() method, both are used to check the equality of the two strings, but in the different sense. |
Abstract class is a class that can not be instantiated and having zero or more abstract method. |
If you modify a variable or method by a static modifier it means there is only one copy of that variable or method shared by all theinstances of that class. A class can not be modified as static,but an inner class. |
If you modify a class with a final keyword, it means, this class can not be subclassed. No class can inherit the features of the final class. If you try to this, an error will result. |
JavaBeans is an API reusable, platform indepent component writtenin java programming language. |
One of the most powerful feature of Java is its multithreading mechanism. |
The java.lang.reflect package provides the information about the code, i.e. objects and classes. |
Serialization can be obtained in a class by implementing the java.io.Serializable interface. |
No! Methods can\'t be overloaded based on the return type. |
Why do we need a finalize() method when Garbage Collection is there ? |
Before performing the garbage collection the JVM called the finalize() method to cleanup the resources such as closing the file or socket connection etc. |
AWT(Abstract Window Toolkit} and Swing are the components of the JFC(Java Foundation Classes), and used for creating the GUI(Graphical User Interface). |
A heavyweight component is one that is associated with its own native screen resource. |
An applet life cycle contains the following methods:*init()*start()*stop()*destroy()Besides these your applet can implement the paint() method. |
The browser starts execution of an applet with the init() method. This method is used for initialization of the component. |
An Exception is an abnormal condition that may occur during the program execution. |
When an exception is thrown by a method, it must declare or handle it. |
You never know that the exception will be thrown or not. |
In java, there are three types of access modifiers: *public *protected *privateBut, there are four access control levels, burn itinto your mind. The fourth access control level isdefault. |
Besides access modifiers, the other modifiers in java are: *abstract, *static, *final, *strictfp, *transient, *volatile, *native, *synchronized, etc. |
Yes! synchronized is a modifier in java. It is used for synchronized a resource if multiple threads want to access the resource. |
Polymorphism is a useful mechanism in java. Polymorphism means \'one name with multiple implementaions.\' |
Inheritance is the mechanism of using the features of one class into another class. |
Using the same method name with different arguments list is called method overloading. |
Using the same method name with the same argument list and return type called method overriding. However in Java 5, the ruturn type of the overrriding method may be changed with the subtype of the overridden method. |
No! Java does support array within array.We can achieve multidimensional arrays using it.Example:int[][][] m=new int[3][3][2]; |
Java does not support multiple inheritance. But we can achievethis using interface. |
Yes! There are many reporting tools in java: * JFreeChart * Prefuse * JasperReports * jCharts * JFreeReport |
Java is a pure Object oriented programming language originally developed by Sun Microsystems, released in 1995 and has the capability in its platform independency. |
A Class is a just like a container which containsvariables and methods. The variables make up thestate and the methods describe the behavior of theclass. |
A method is a group of instructions enclosed by the curly braces{}. |
Java is a pure Object oriented programming language and supports: * Class * Object * Abstraction * Encapsulation * Polymorphism * Inheritance, etc. |
Binding up the data and methods into a singleunit, i.e. class is called encapsulation. |
Inheritance is the mechanism of using the features of one class into another class. |
A Java source code is compiled by java compiler(javac) and converted into the bytecode. |
Identifiers are just the name of the variables, methods, classes, interfaces etc. |
There are two types of modifiers in Java: * Access Modifiers, * Non-access modifiers. |
Primitives data types in java are: * boolean * char * byte * short * int * long * float * double |
The wrapper classes serve the two purpose: * It wraps the primitive to an object so that primitives can be used in the activities which are reserved only for the objects. * Converting primitives to and from String objects. Java provides the Wrapper class for each of the primitives in java. Some of these are: * Boolean * Character * Byte * Short * Integer * Long * Float * Double |
Java provides the automatic garbage collection facility. |
A final keyword is used to prevent the inheritance if it is used with the methods and classes. |
You can think of interface as a fully abstract class. |
An array is simply a data structure that stores the similar types of elements with sequence of consecutively numbered. int a[]=new int[3]; |
The Singleton is a Design Pattern for allowing onlyone instance of your class. |
Constructors are the special member functions which have the same name as the class name. The most important thing is that they don\'t hava return type. Constructors may be overloaded. If you don\'t provide a constructor for the class, the compiler will supply the defualt one. Constructors can have any of the access modifiers. Example: public class MyClass{ int i; int j; public MyClass(){} protected MyClass(int i){} private MyClass(int i,int j){} } |
Casting is the process of assigning the value of one type of variable to another type of variable. |
What is the difference between final, finally and finalize ? |
final is a keyword used for the following things:- |
Packages are the container for the classes. |
* String * Thread * ArrayList * Vector * HashMap |
* ArrayList * Vector |
What is the difference between java.applet.* and java.applet.Applet ? |
When you import java.applet.*, it means you are importing all the classes available in the java.applet package. When you import java.applet.Applet, it means you are importing the single class. It is better to import the classes that you need instead of importing all the classes in the package. |
The java.lang is the default package which is automatically imported in each of the java source file. |
Anonymous class is one that has no name. Java provides the anonymous inner classes with different flavours. An anonymous inner class can also be declared even in the argument list of the method. |
An interface tells that what a class can do. It is a good object oriented design to use interfaces in your program. When a class implements the interface, it is actually contracting to implement all the functionality of the interface. Interfaces also support multiple inheritance. |
If a class implements the serializable interface, it means that state of objects of that class can be serialized and deserialized. This interface has no methods. |
If you want prevent serialization of the fields(variables), mark them transient. The transient variable can\'t be serialized. |
The throw keyword is used to throwing the exceptionmanually in the program. |
Yes! Multiple catch statement can be used in exceptions, but with some general rules. |
Yes! The try statement can be nested within another try block. |
Thread is a light weight process. |
Multithreading allows two or more parts of the same program to run concurrently. |
What is the 2 way of creating a thread ? Which is the best way and why? |
Two way of creating the thread in java are: * Extending the Thread class * Implementing the Runnable Interface.Both ways provides the same functionality. |
The method to find if a thread is active: boolean isAlive() |
The sleep() method moves the thread to waitingstate for particular time. |
No! In multi-threading environment a thread can start the another thread but it can not be a member of another thread. |
MIN_PRIORITY MAX_PRIORITY NORM_PRIORITY |
Garbage collector thread belongs to low priority. |
this keyword is used to point to the currently executing object. |
How can you find the length and capacity of a string buffer ? |
The StringBuffer is a class that has a mutable sequence of characters. |
There are two ways to compare the two strings in java: |
The System class provide systemlevel functionality to Java applications. |
flush() |
The StreamTokenizer is class in Java that takesan input stream and parses it into \"tokens\",allowing the tokens to be read one at a time. Each byte read from the input stream is acharacter in the range from \'u0000\' to \'u00FF\'. |
The values assigned to the variables of an objectmake up the state of the object. |
An applet is a tiny Java program that can run on browser and can be included in an HTML page, much in the same way an image is included in a page. |
Two methods help here:public java.net.URL getDocumentBase();public java.net.URL getCodeBase(); |
The life cycle of an Applet: * init() * start() * stop() * destroy() |
Applets are loaded and executed within a web browser, and hence you can load specific URL. |
The getDocumentBase() method returns \"the URL of the document in which the Applet is embedded.\" |
In java applets, the parameter tag is used in the html used to send parameter to applet. In applet you can read the parameters passed by html code. |
What is the difference between getAppletInfo and getParameterInfo ? |
The getAppletInfo() method returns the string that describes the applet. The getParameterInfo() method returns an array of string arrays that specify the name,type, and description of each of the parameter. |
Sometimes you need to allow two or more applets to communicate on the Web page. |
Events represent the activity that occurs between the user and the application. |
An event listener is an object used to handling a particular kind of event. |
The adapter classes allow you to use the Listener Interfaces without having to create a body for every method. Adapter class provides the empty implementation for Listener interface\'s method. |
* MouserListener * MouseMotionListener |
* public void mouseClicked(MouseEvent e) * public void mouseReleased(MouseEvent e)) * public void mouseOver(MouseEvent e) * public void mouseDoubleClicked(MouseEvent e) * public void mousepressed(MouseEvent e) |
A Panal and the Frame, both are the component of the Abstract Window Toolkit(AWT). A panel is a component which can be embedded in a frame, and a frame is nothing but a window application an can embed all the components. Frame-is a top level container. while the panel is sub-level container..not the top level container.. |
The default layout of panel is flowlayout. The default layout of frame is border layout. |
A Choice is a compact form that requires you to pull it down to see the list of available choices. |
The different types of Layouts are : * FlowLayout, * BorderLayOut, * GridBagLayout, * GridLayout, * CardLayout. |
A CardLayout object is a layout manager for a container.It treats each component in the container as a card. |
What is the difference between GridLayout and GridBagLayout? |
GridLayout class puts all the components in a rectangular grid and is divided into an equal sized rectangles and each component is placed inside a rectangle. |
The classes that implements java.util.Set interface (such as, HashSet,TreeSet) do not support duplicate elements. |
Swing is a library of GUI controls which improves upon the Abstract Window Toolkit. |
Applet is component of AWT whereas JApplet is a component of Swing. JApplet is a Swing version of Applet. |
The javax.swing package has the following classes to create the swing the component: * Buttons and Labels * Checkboxes and Radio Buttons * Lists and Combo Boxes * Borders * Menus * The PopupMenu Class * The JScrollPane Class * The JSplitPane Class * The JTabbedPane Class * Scrollbars and Sliders * Dialogs |
In javax.swing package, Using the JTabbedPane class, you can have several components, such as panels, share the same space. |
Jtree is a just like a tree which is used to disply the items in the form of the tree. |
Using the JTable class you can display tables ofdata, optionally allowing the user to edit the data. |
The JFC(Java Foundation classes) tells you how to create graphical user interfaces (GUIs) for applications and applets, using the Swing components. |
JAR file is a file format based on the popular ZIP file format and is used for aggregating many files into one. A JAR file is essentially a zip file that contains an optional META-INF directory. |
The manifest file is named MANIFEST.MF. In Java ,a manifest file is a specific file contained within a JAR file. |
A javaBean property has the two methods: * setProperty() * getProperty() |
BeanInfo classes provides a high degree of control over how a bean appears and behaves at design time. |
The Serializable interace is used in Beans. |
Classes that are available in java.beans package : |
Difference between java and C++ : * C evolved into C++, and C++ transmuted into Java. |
A process is a program in execution, whereas a single process can contains multiple threads. |
You can initialize your applet using the init() method. |
The order of invocation in Applet is : * init() * start() * paint() * stop() * destroy() |
The update() method is defined by the AWT and is called when your applet has requested that a portion of its window be redrawn. The problem is that the default version of update() first fills an applet with the default background colour and then calls paint(). |
JNI stands for Java Native Interface. The Java Native Interface (JNI) enables the integration of code written in the Java programming language with code written in other languages such as C and C++. |
All the swing components are derived from abstract javax.swing.JComponent class. |
The following tag is used for this purpose : tag upload file. |
The layout for toolbar is Flow Layout. There is no Specific Layout for adding ToolBar. |
We can add panel to a Frame : Panel p = new Panel(); Frame f =new Frame(\"My frame\"); f.getContentpane().add(p); |
The corresponding Layout for Card in Swing CardLayout. |
AWT supports lightweight components. Light weight componenets can be created using Java without mixing any other language code. |
The Java Bean is simple java class which is contains Getters and Setters methods nothing else. |
Applets are the tiny java program runs under the control of web browser and dynamically downloaded over the internet. Browser takes care of the life cycle of the Applet, i.e. calling the init(), start(), paint(), stop(), destroy(), etc methods. |
Java achieve inheritance using two notions : By extending the class and implementing the interface. |
Java is not fully object oriented language, because not all values in Java are Objects.� |
The Object class is the root class of all the Java classes. |
What is the exact difference in between Unicast and Multicast object ? Where we will use ? |
Unicast object means there is one receiver. Use multicast to allow one-to-many connections. |
Why there are some null interface in java ? What does it mean ? |
Interface which does not contain any variables and methods. |
As of December 2008, the latest version of Java is 1.6.0_11 |
What is mean by class loader ? How many types are there? When will we use them ? |
Class loaders determine when and how classes can be added to a running Java environment. |
Public is an access modifiers tells that this method can be accessed anywhere inside or outside the package by any class\' object reference. |
String class provides the immutable character sequence whereas StringBuffer class objects are mutable characters sequence. |
Wrapper classes are used to \"wrap\" the primitives data types into objects so that they can be included in the activities which are reseved for the objects. |
Default modifier in Interface is public access modifier. |
No! An abstract method or abstract class can\'t be marked as a final. |
Can we declare variables inside a method as Final Variables? |
Yes! we can declare variables inside a method as final variables. |
A Thread is considered to be dead when it completes its run() method. |
Yes we can have constructors in an applet. But applets don\'t usually have constructors because an applet isn\'t guaranteed to have a full environment until its init() method is called. |
Both types of exceptions are drived from the class Exception. |
Two types of multi-tasking : * Process based multi-tasking. * Thread based multi-tasking. In Process based multitaskin, more than one processes run concurrently. Whereas In Thread based multitasking multiple threads executes concurrently. A single process may contain several executing threads sharing the same address space. |
The filter driver determines the total bandwidth of the disk. I/O filters generally used for reading from one stream and writing another stream. |
Yes, An applet can communicate with another applet on different. Since an AppletContext will be created for a single page. If it is in multiple pages, different applet context will be there for different applets. But even if the applets are on different pages, they run under the same JVM, so we can create an class similar to AppletContext say this class AppletRegistry, which holds references to all the applets running in the JVM, and this class can be use to hand over the reference to whoever needs it for communication. This registry should maintain a static hashtable that should keep the map of all the applet objects. |
== compare reference objects . |
Both Abstract class and interface can\'t be instantiated. |
singleton :- |
static variable:- also called class level variable . |
final class :- A final class is a class that can't be extended. |
What is difference between Event propagation & Event delegation? |
What are the restrictions of an applet & how to make the applet access the local machines resources? |
Serialization is the process of producing Stream of bytes from the object and writing it into the output source such as file. |
A method cannot be overloaded on the bases of return types because the compiler will check only the method signature( name of the method and the arguments). |
What should you do get your browser compatible with swing components? |
When you navigate from one applet to another what are the methods called? |
What is the difference between Trusted and Untrusted Applet ? |
Exception handling using try-catch-finally for normal termination. |
To maintain cleanup code while exception handling in try catch block. |
Yes, Synchronized means thread safe i.e. only one thread will be executed at a time. |
No, Java doesn\'t support multiple inheritance with class, but it supports with iterface. |
Yes! Multi-dimensional arrays can be represented by arrays of arrays. var v = new array(3,4,5); |
Methods are similar to functions or procedures that are available in other programming languages. |
Interpretation happens at runtime(which means while running the Java program) ,turns it into native code. |
JVM is a Java virtual machine, JVM is a process that executes a computer program compiled into Java bytecode. Through bytecode java achieves interoperability (platform independent). |
Source code for a Java class is called a compilation unit. Forms the input for the Java compiler (javac). |
Static variable is also known as class variable, global variable. |
GC is automatic memory management, which is a collector attempts to reclaim garbage or memory occupied by objects that are no longer in use by the program(unreferenced objects). Advantage of GC is memory efficient, automatically done.Can be done By nulling the reference, assigning a reference to another, annonymous object etc. |
A resource leak is where memory is being steadily consumed by resources that are no longer being used. In java this situation arises when references to objects that are no longer required. To avoid this you should remember to set all variables to null as soon as you are finished with the reference. This will allow the gc to free up the memory that the objects were consuming. |
What is the difference between interface and abstract class ? |
What is the difference between public private, protected and static? |
1) The scope of the private members is anywhere within the class. 2) The scope of the protected members is anywhere with in the same package and only subclass of the different package. 3) The scope of the public members is anywhere!. static members are Common across all objects Also called class variable.A static variable cannot access instance method. |
A subclass can re-implement superclass method to provide subclass specific implementation. Accesibility modifiers of superclass and subclass and return type, method signature must be same. |
A class having only one instance. |
Array have limitations: Size fixed, Homogeneous. While Vector is growable array, allows duplicate elements,ordered, not sorted, Accepts any number of null values. Synchronized,Heterogeneous. It is class of Collection interface. |
What is the difference between final, finally and finalize ? |
Package is group classes interfaces. Two types built-in package and user defined package. The package statement should be the first line. Provides access protection. Removes naming collision. |
What is the difference between java.applet.* and java.applet.Applet ? |
java.lang package by default,imported implicitly. |
Anonymous classes make our code compact. They can be declare and instantiate a class at a time. They do not have a name. They are local class only . This section covers the following topics: |
Marker Interface |
interface contains abstract class. |
Converting the state of an object into a byte stream. Serializability of a class is enabled by the class implementing the java.io.Serializable interface. |
Through transient keyword. |
Runtime exceptions are unchecked exceptions, we can handle them through try catch block. try { ... do stuff ... } catch (SomeException e) { e.printStackTrace(); throw e; } |
Throw is used to propagate an exception to its caller inorder to let the calling method to handle an exception rather than implementation method.Throw keyword is always used at block level but not at method signature level. All built-in exceptions are automatically thrown by the JVM. But, built-in exceptions can be programmatically thrown by the developer using throw keyword. All user defined exceptions must be programmatically thrown using �throw� keyword. Syntax: throw |
yes multiple catch statements can be used but it depends upon number of try block which throws an exception. |
Yes, try { try { throw new Error(\"oops\"); } finally { console.log(\"finally\"); } } catch (ex) { console.error(\"outer\", ex.message); } |
A thread is a smallest unit of dispatchable code. Defining, Instantiating, and Starting threads by Extending Thread class Implementing Runnable interface Methds to Prevent Thread execution Sleep() Join() |
A large program is split into multiple tasks, assign a thread for each task and execute them concurrently is called as multithreading. |
What is the 2 way of creating a thread ? Which is the best way and why? |
Defining, Instantiating, and Starting new Threads The code which we want to run as a thread of execution is written inside a run() method. We can define a thread either by: 1. Extending a java.lang.Thread class 2. Implementing a java.lang.Runnable Interface. Runable is better than extending Thread. it shares the same object to multiple threads. if you extends Thread, you can\'t extend another class |
thread.isAlive() method. |
Threads communication is possible in java. A first thread registers with a gateway for receiving communication. Registration includes identifying a location for receiving messages. The gateway maps message payloads received from second threads to the location of the first thread. The first thread detects a payload in the location and consumes it for processing. |
If the thread is not allowed to perform any operations for a particular period of time, then use sleep() method. The sleep() method suspends currently executing thread for the specified time. Join() The currently running thread is suspended until the invoking thread completes its execution (and entered into dead state). The currently executing thread joins at the end of the invoking thread. This is used when the currently executing thread cannot continue until the invoking thread completes its execution. |
There may be situations when two or more process are put into waiting state simultaneously to get the resources holding by each other.In this position each would be waiting for the other process to release the resource. So both processes gets locked, waits for the each other\'s resource to released. This situation is called deadlock. |
Every thread in java has some priority. The valid priority range is 1 to 10, where 1 is the least and 10 is the max priority. The Thread class defines the following constants to set some standard priorities: 1) Public static final int MIN_PRIORITY (1) 2) Public static final int NORM_PRIORITY (5) 3) Public static final int MAX_PRIORITY (10) The thread with highest priority may get (cannot guarenteed) the chance of first execution. Two threads have the equal priority, we cannot determine which thread will be executed first. Thread class defines following methods to get and set the thread priorities: 1) Public final int getPriority() 2) Public final void setPriority(int priority) Default Priority By default, every thread is set with default priority which is 5. The default priority of the main thread is also 5. |
low(MIN priority) |
How can you find the length and capacity of a string buffer ? |
public int capacity() Returns the current capacity. The capacity is the amount of storage available for newly inserted characters, beyond which an allocation will occur. Returns: the current capacity. public int length() Returns the length (character count). Specified by: length in interface CharSequence Returns: the length of the sequence of characters currently represented by this object. |
CompareTo(), Compare() method |
The package java.lang contains classes and interfaces that are essential to the Java language. These are: Object, superclass of all classes in Java. Thread, the class that controls each thread in a multithreaded program. Throwable, the superclass of all error and exception classes in Java. Classes that encapsulate the primitive data types in Java. Classes for accessing system resources and other low-level entities. Math, a class that provides standard mathematical methods. String, the class that represents strings. Because the classes in the java.lang package are so essential, the java.lang package is implicitly imported by every Java source file. In other words, you can refer to all of the classes and interfaces in java.lang using their simple names. |
java.lang.Object java.io.StreamTokenizer class takes an input stream and parses it into \"tokens\", allowing the tokens to be read one at a time. The stream tokenizer can recognize identifiers, numbers, quoted strings, and various comment styles. |
What is the difference between a scroll bar and a scroll panel? |
What is the difference between menuitem and checkboxmenu item. |
What is meant by vector class, dictionary class , hash table class,and property class ? |
Vector is a array whose size can be grown or shrink. Allows duplicate elements. It is an ordered collection based on index. Vector is a class of List Interface which is from collection framework. Allows any number of null values. By default, vector elements are not sorted. It is a synchronized collection (thread-safe), since it is a legacy class. Stack is sub class of Vector. Dictionary is an abstract class. Hash table and property are inherited from Map interface which is not derived from collection interface. Based on hashing mechanism. Keys cannot be duplicated but values can be duplicated. Both keys and values are unordered i.e., the entries in Hashtable are unordered. Neither key nor value is null. By default, hashtable entries are not sorted. By default, Hashtable is a synchronized Map. Properties are usually configured in property file with .properties extension. The entries in property file are key, values and separated with equal (=) symbol. Though the Properties class is inherited from Hashtable, but both keys and values must be string objects only. The advantages of using properties file is, the changes can be made in one place, which are reflected across all other placess in our code. |
Set Interface has no duplicate elements. HashSet, Linked Hashset, TreeSet class not allows duplicate elements. |
What is the class in Swing to change the appearance of the Frame in Runtime? |
We can reuse the code by javabeans.Developers can use software components written by others without having to understand their inner workings. |
JAR stands for Java ARchive. It\'s a file format based on the popular ZIP file format and is used for aggregating many files into one. The JAR format also supports compression, which reduces the size of the file and improves download time. |
public class Introspector extends Object. he Introspector class provides a standard way for tools to learn about the properties, events, and methods supported by a target Java Bean. For each of those three kinds of information, the Introspector will separately analyze the bean\'s class and superclasses looking for either explicit or implicit information and use that information to build a BeanInfo object that comprehensively describes the target bean. |
What is the diffrence between an Abstract class and Interface? |
Yes! We can also defined our own exceptions according to our requirment. We can do this by extending the Exception class, in this class we override the toString() method. |
Garbage collector removes the unreferenced objects from heap memory. By nulling the reference By assigning a reference to another By annonymous object etc. The finalize() method is invoked each time before the object is garbage collected. This method can be used to perform cleanup processing. This method is defined in Object class as: protected void finalize() The gc() method is used to invoke the garbage collector to perform cleanup processing. The gc() is found in System and Runtime classes. public static void gc() |
Two main drawbacks with C++ language are : Platform dependent and won�t support Internet and WWW. To solve these problems, James Gosling developed a new language called JAVA at sun Microsystems in 1991, which is platform independent and supports WWW & Internet. C++ supports operator overloading multiple inheritance but java does not. Everything (except fundamental types) is an object in Java (Single root hierarchy as everything gets derived from java.lang.Object). Java does not support pointers, templates, unions, operator overloading, structures etc. C++ supports structures, unions, templates, operator overloading, pointers and pointer arithmetic. Java support automatic garbage collection. Java, there is a Thread class that you inherit to create a new thread and override the run() method. C++ has no built in support for threads. Java doesn\'t provide multiple inheritance C++ does support multiple inheritance. |
A statement forms a complete unit of execution. The following types of expressions can be made into a statement by terminating the expression with a semicolon (;). Assignment expressions Any use of ++ or -- Method invocations Object creation expressions |
Java Native Interface (JNI) is a programming framework that enables Java code running in a Java Virtual Machine (JVM) to call and be called by[1] native applications (programs specific to a hardware and operating system platform) and libraries written in other languages such as C, C++ and assembly. |
The Java Foundation Classes (JFC) are a graphical framework for building portable Java-based graphical user interfaces (GUIs). JFC consists of the Abstract Window Toolkit (AWT), Swing and Java 2D. Together, they provide a consistent user interface for Java programs. Encompass a group of features for building graphical user interfaces (GUIs) and adding rich graphics functionality and interactivity to Java applications |
A Bean is a Java class, but a Java class does not have to be a bean. Bean reusable software. A Java class is meant to carry out the different database operations like retrtieveing data, inserting data and updating data. |
What is the mapping mechanism used by Java to identify IDL language ? |
The idlj compiler uses the IDL-to-Java language mapping to convert IDL interface definitions to corresponding Java interfaces, classes, and methods, which can be use to implement client and server code. |
CGI (Common Gateway Interface) is an attempt at providing users with dynamic content. It allows users to execute a program that resides in the server to process data and access database to produce the relevant data. They are written in the native operating system and then stored in a specific directory. A servlet is an implementation of Java that aims to provide the same service as CGI does, but instead of programs compiled in the native operating system, it compiles into the Java bytecode which is then run in the Java virtual machine. Though Java programs can be compiled into the native code, they still prefer to compile in the Java bytecode. |
Interface provides service details not the implementation details to the user. �It is used to achieve full abstraction. �By interface, we can achieve multiple inheritance. |
Because of primitive data types.Multiple Inheritance, Operator Overloading not possible in java. |
java doesn\'t support multiple inheritance directly because it leads to overiding of methods when both extended class have a same method name. this will leads to ambiguity in executing. |
Object is the root class for all java classes. |
If we have a local variable declared in the run method then all the existing thread will hava a separate copy for that variable. If we are using the instance variable in the run method then this will be shared by all the existing variable. |
What is Constructor and Virtual function? Can we call virtual? |
The main function of constructor to do initialisation followed by instantiation. It is calle to create an object. A constructor resembles an instance method, but it differs from a method in that it has no explicit return type. Constructors often have the same name as the declaring class. Default constructor(no parameter). Parameterised Constructor (with parameter) |
What is the difference in between C++ and Java ? can u explain in detail? |
Java supports classes, but does not support structures or unions. Write once, run anywhere, Platform independent (Interoperability). Due to byte code and run by JVM. C++ supports multiple inheritance but java doesn\'t. Pointers are not in java, All classes in Java ultimately inherit from the Object class. Java does not support operator overloading. |
What is the exact difference in between Unicast and Multicast object ? Where we will use ? |
Unicast is a one-to one connection between the client and the server. A multicast packet is from one machine to one or more. The difference between a multicast packet and a broadcast packet is that hosts receiving multicast packets can be on different lans |
Why there are some null interface in java ? What does it mean ? |
Null Interfaces know as Marker Interfaces having no method.There is a method clone() in Object class.Examples Serializable, Cloneable. |
Serializable, Cloneable. |
What is meant by class loader ? How many types are there? When will we use them ? |
The Class.forName() loads the class into the JVM. It loads the class into the JVM for further use. We use this when we want to load JDBC-ODBC drivers. Class Loader is a part of JVM used to load the classes dynamically. It will load the classes based on demand. Diffrent types of class loaders are extension class loader, system class loader and bootstrap class loader. Bootstrap class loader loads the classes in rt.jar and i18n.jar, extension class loader loads the class in ext dir, system class loader loads all other classes in the class path. two type. 1) Static Loading. 2) Dynamic Loading. Dynamic way is done by the help of class.forName(); Extensions Class Loader,System Class Loader. |
A message given to a Web browser by a Web server. The browser stores the message in a text file. The message is then sent back to the server each time the browser requests a page from the server. Every time the user loads the website, the browser sends the cookie back to the server to notify the website of the user\'s previous activity. Each cookie is effectively a small lookup table containing pairs of (key, data) values session cookie and persistent cookie. |
public is a access modifier, static means dosent belongs to an object, void means main does not return any value, main( ) is the method called when a Java application begins. |
Passed at the time of running the java program. Java application can accept any number of arguments from the command line. This allows the user to specify configuration information when the application is launched. Java application can accept any number of arguments from the command line. when you invoke an application, the runtime system passes the command line arguments to the application\'s main method via an array of Strings. Each String in the array contains one of the command line arguments |
String is immutable and stringbufffer is mutable |
What are the restriction for static method Purpose of the file class? |
Can we declare variables inside a method as Final Variables? |
A package is a namespace that organizes a set of related classes and interfaces. Java platform provides an enormous class library (a set of packages) suitable for use in your own applications.It is a group of classes, interfaces Advantage is reusability. Packages are of two types. User defined package, built in package. |
A Canvas object provides access to a Graphics object via its paint() method. |
What will happen to the Exception object after exception handling? |
inter thread communication can be done by 3 methods wait(), notify(),notifyall(). |
Describe difference between method overriding and overloading? |
Both are type of polymorphism, method overloading having same method name but different parameter list (number, order, type), it is resolved at compile time so it is known as Early binding. Method overriding having same method name, parameter list and return type is also same.It is resolved at runtime therefore called Late binding. |
What is the restriction on an Overridden methods’ accessibility ? |
If we are overriding the method in the same package\'s class then it must not be the private member. If we are overiding the method is the other package\'s class, then it must not be the private and default. |
What is the restriction on an Overridden methods’ accessibility ? |
Can a method be overloaded by different return type but same argument type? |
No! For method overloading, the parameter list must be changed. Method overloading does not depend the on return type. |
Can a method be overloaded by different return type but same argument type? |
Super class constructors are always executed before subclass constructors is called as constructor chaining. �this()� is used to call matching constructor from the same class. �super()� is used to call matching constructor from immediate superclass. |
Contructor can be overloaded,i.e. a single class can hava more than one contructor. A construct may call to another constructor. The first statement in the constructor must be a call to either this() or super() but not both. The super() will call the matching superclass constructor according to the number of arguments passed in the super(). A this() will call the overloaded constuctor in the same class according to the parameter list. The called constructor may also make a call to the other constructor using this(). This type of contructor calling in the same class is called constructor chaining. |
When we make a call to the method, we may pass some values in the parameter list. When we pass the actual value of the variable, it simply pass the copy of the variable not actual value. Hence change in the copy of that variable will not affect the actual value of that variable. When we passed the object reference into the parameter list in to a method call, we are actually passing the copy of bits that refer to the object somewhere into the memory not actual value of the object. If we modify the object using the reference of that object will also affect the actual value of that passed object. |
Means that all variables must first be declared before they can be used.the operating system allocates memory and decides what can be stored in the reserved memory |
What is a difference between An interface and an abstract class? |
We can write query in both JSP page and servlet. It depends upon you. But it is better to separate classes to make a database connection, pass the reference to the JSP page and write query using JSTL 2.0(Java Standard Tag Library). |
Constructors are the special member, they do not have a return type. We can call the methods explicitly but constructors are called automatically when we create the object using the new operator. The purpose of constructor is to allocate the memory to the object and initialize the class\' variables. If you don\'t provide the constructor in your class, the compiler will insert the default constructor. |
Object can be represented as a sequence of bytes that includes the object\'s data as well as information about the object\'s type and the types of data stored in the object. After a serialized object has been written into a file, it can be read from the file and deserialized that is, the type information and bytes that represent the object and its data can be used to recreate the object in memory. Most impressive is that the entire process is JVM independent, meaning an object can be serialized on one platform and deserialized on an entirely different platform. Classes ObjectInputStream and ObjectOutputStream are high-level streams that contain the methods for serializing and deserializing an object. |
What are differences between procedural and object oriented language? |
Object Orientated Programming and Procedure Oriented Programming are basically two different paradigms for writing code. In procedural programming the main emphasis is on procedure while in object oriented the data is important part. on the same hand data is more secured in object oriented program. Procedural programming separates the data of the program from the operations that manipulate the data. The fundamental advantage of OO programming is that the data and the operations that manipulate the data (the code) are both encapsulated in the object. Object Oriented programming deals with the elemental basic parts or building blocks of the problem, whereas Procedural programming focuses on the steps required to produce the desired outcome. In OOP, decomposing the problem into smaller discrete pieces called \"Objects\". |
What are differences between procedural and object oriented language? |
A class is a construct that defines a collection of properties and methods. It can be viewed as a template. Object is an instance of a class. |
Threads block or enters to waiting state on I/O, so that other threads may execute while the i/o Operation is performed. |
A transient variable is a variable that may not be serialized. It is not stored as part of its objects persistent state. The value of the variable can\'t be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null. |
The JDK provides a reusable embodiment of the pattern in the form of the java.util.Observer interface and the java.util.Observable class. Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects. In Observer Pattern, object maintains a list of its dependents and notifies them automatically of any state changes, usually by calling one of their methods. It is mainly used to implement distributed event handling systems. |
List is an ordered collection of elements. The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index. Unlike sets, lists typically allow duplicate elements. The List interface includes operations for the following: * Positional access * Search * Iteration * Range-view Useful methods of the List Interface: * add() * clear() * contains() * get() * isEmpty() * listIterator() * remove() * size() |
Thread.sleep(1000) method hands over the control to other thread for a particular time period. Whereas Thread.yield() method causes the currently executing thread object to temporarily pause and allow other threads to execute according to the scheduling algorithm the CPU is running on. |
No! The finalize method is invoked by the JVM/GarbageCollector on Objects which are no longer referenced. |
What is the initial state of a thread when it is created and started? |
The thread is in ready state. |
Can we declare an anonymous class as both extending a class and implementing an interface? |
No. An anonymous class can extend a class or implement an interface, but it cannot be declared to do both |
What is the differences between boolean & operator and && operator? |
When we use boolean & operator between the two operands then both the operands are evaluated. If we are using the && operator between the two operands then second operand is evaluated if the first operand is true. |
An abstract method does not have a body. It contains only method signature terminated by a semicolon instead of curly braces. Abstract method can be declared only within the abstract class or within the interfaces. The definition to the abstract method will be provided by the class which extends the abstract class or implements the interface. |
The System.out writes to the \"standard output\". The System.err writes to \"standard error\". These two streams are setup by the operating system when the Java program is executed, and can be redirected with the uses of \"|\", \">\", etc. on the command line. You can redirect the output of the System.out to any other file. The following example can help to understand the concept : public class Test{ public static void main(String args[]){ System.out.println(\"Output of System.out\"); System.err.println(\"Output of System.err\"); } } First Execution - C:>java Test Output of System.out Output of System.err Second Execution - C:>java Test > abc.txt Output of System.err In the second execution we diverted only the std output stream and std err stream remained unchanged. i.e., by this way, we can handle error stream separately. |
What is the difference between synchronized block and synchronized method ? |
Both the synchronized method and block are used to acquires the lock for an object. When you mark a method synchronized, then you are forcing every thread which calls that method to lock the monitor. If you expect a synchronized() {} block in the calling code, it is possible that some code which calls your method might neglect to use synchronized() and end up with a threading problem in your program. synchronized code always use objects as locks to prevent other threads from entering the synchronized block. For instance methods, they are synchronized on the \'this\' reference, and for static methods they are synchronized on the instance of the Class object method belongs to. Best practice is to minimize the code inside synchronized blocks because they prevent concurrent threads from executing - losing any advantage of multi-threaded applications. Synchronized blocks help let those portions of a method that do not access shared resources to be run simultaneously while still keeping those parts that need to be shared thread-safe. |
You can not force the JVM for the garbage collection. However you can call the System.gc() method in your program to tell the JVM that it may the time to perform garbage collection. But it is upto the JVM that if will call the System.gc() method or not. There is no way to force the JVM, it works fine without programmer\'s intervention. |
Yes, we can call the constructor but within the another constructor of the same class using the this(). |
We can call the superclass constructor by making a call to super() in the subclass constructor. |
What must be the order of catch blocks when catching more than one exception? |
When you use multiple catch blocks, it is important to remember that exception subclasses must come before any of their superclasses. This is because a catch statement that uses a superclass will catch exceptions of that type plus any of its subclasses. Thus a subclass would never be reached if it came after its superclass. Further, in Java, unreachable code is an error. |
How can we call a method or variable of the super class from child class ? |
We can use super.methodNme() or super.variableName. |
If you are overriding equals() method of a class, what other methods you might need to override ? |
If you are overriding equals() method of a class, then the other methods you might need to override is hashCode(). |
Externalizable is an Interface that extends Serializable Interface. Java provides Externalizable interface that gives you more control over what is being serialized. This interface defines 2 methods: readExternal() and writeExternal() and you have to implement these methods in the class that will be serialized. In these methods you\'ll have to write code that reads/writes only the values of the attributes you are interested in. |
Does garbage collection guarantee that a program will not run out of memory? |
Garbage collection does not guarantee that a program will not run out of memory. It ispossible for programs to use up memory resources faster than they are garbage collected. As garbage collection is JVM dependent then It is possible for programs to use memory resources faster than they are garbage collected.Moreover garbage collection cannot be enforced,it is just suggested. |
A native method is the Java interface to non-Java code. It is Java\'s link to the \"outside world\". A native method is a Java method whose implementation is provided by non-java code. A native method is one for which the body of the method is defined elsewhere, entirely outside the Java Virtual Machine, in a library. Only methods can be declared as native. A native code is written in a non-Java language, typically C or C++, and compiled for a single target machine type. Syntax : native public void Native1( ) ; |
What is the difference between a continue statement and a break statement? |
break completely exits the loop. Continue skips the statements after the continue statement and keeps looping. |
If a class implements the interface, it must provides the definition to all the methods declared in the interface or it must be the abstract class. If it is an abstract class then the first concrete subclass must provides the definition to the interface\'s mathods and abstract methods of the abstract class. |
THe notify() method wakes up a single thread waiting on the object and passes the control of the monitor to it. The notifyAll() method will wake up all the threads waiting on the object and will select a thread to pass control to it. The unselected thread will again go back to sleep in the JVM scheduler list and they will need yet another call to notifty (or notifyAll) in order to wake them up. The notifyAll() method is the same as the notify() method. The only difference is that in this case all the threads from the non-empty wait set of the object are removed and are re-enabled for thread scheduling in stead of only one thread from the wait set being picked arbitrarily, removed, and re-enabled for thread scheduling as is the case in notify() method. |
The wait() method is defined in the Object class. The method should only be called by a thread that has ownership of the object\'s monitor, which usually means it is in a synchronized method or statement block. Threads - wait() method do : * the wait() method causes a thread to release the lock it is holding on an object; allowing another thread to run. * the wait() method is defined in the Object class. * wait() can only be invoked from within synchronized code. * it should always be wrapped in a try block as it throws IOExceptions. There are actually three wait() methods 1. wait() 2. wait(long timeout) 3. wait(long timeout, int nanos) The timeout is measured in milliseconds. when wait() is called, the thread becomes disabled for scheduling and lies dormant until one of four things occur: 1. another thread invokes the notify() method for this object and the scheduler arbitrarily chooses to run the thread 2. another thread invokes the notifyAll() method for this object 3. another thread interrupts this thread 4. the specified wait() time elapses |
The different stated of a thread : * NEW : A Fresh thread that has not yet started to execute. * RUNNABLE : A thread that is executing in the Java virtual machine. * BLOCKED : A thread that is blocked waiting for a monitor lock. * WAITING : A thread that is wating to be notified by another thread. * TERMINATED : A thread whos run method has ended. |
What is the difference between static and non static inner class ? |
A non-static inner class may have object instances that are associated with instances of the class\'s outer class. A static inner class does not have any object instances. |
The Reader/Writer classes is character-oriented and the InputStream/OutputStream classes is byte oriented. |
Static methods are class bound rather than runtime object type bound. That means they cannot be overridden since polymorphism doesn\'t hold. We can\'t override the static methods. We know overriding depends upon the inheritance. Since the static methods are not inherited, hence we can not override static methods. If u try to that, you are actually redefining the superclass version of the static method, this is not an override. |
When does a compiler supplies a default constructor for a class? |
If a class has no constructors, then the compiler provides a default constructor for that class. |
An uncaught exception results in the uncaughtException() method of the thread\'s ThreadGroup being invoked, which eventually results in the termination of the programin. |
What are the different ways in which a thread can enter into waiting state? |
A thread can enter into waiting state in 3 ways: * sleep() method. * wait() method. * suspend() method. |
Resource bundle used to contain locale-specific objects. When your program needs a locale-specific resource, a String for example, your program can load it from the resource bundle that is appropriate for the current user\'s locale. This allows you to write programs that can: * be easily localized, or translated, into different languages. * handle multiple locales at once. * be easily modified later to support even more locales. The Java ResourceBundle class eases the process of separating localized resources from an application\'s source code, but you may want to extend the ResourceBundle class to better fit your needs. |
Numeric promotion contexts allow the use of an identity conversion or a widening primitive conversion. Numeric promotion is the conversion of a smaller numeric type to a larger numeric type,so that integer and floating-point operations may take place. In numerical promotion,byte, char, and short values are converted to int values. The int values are also convertedto long values, if necessary. The long and float values are converted to double values. Numeric promotions are used to convert the operands of a numeric operator to a common type so that an operation can be performed. In java, if u are arithematic operator on the operands then : * If either operand is of type double, the other is converted to double. * Otherwise, if either operand is of type float, the other is converted to float. * Otherwise, if either operand is of type long, the other is converted to long. * Otherwise, both operands are converted to type int. |
What is the difference between the prefix and postfix forms of the ++ operator? |
Prefix ++ operator first increments the value of operand by 1 and then return the value. Postfix ++ operator first reutrn the value and then increments the value of operands by 1. |
What is the difference between a switch statement and an if statement? |
Both the statements provides the condition checking of the expressin but Switch statement reduces the complexity of using the multiple if-else clause. |
The hashCode() is id number allocated to an object by JVM. Objects in Java have hash codes associated with them. An object\'s hash code is a signed number that identifies the object (for example, an instance of the parent class). An object\'s hash code may be obtained by using the object\'s hashCode() method as follows: int hashCode = SomeObject.hashCode(); The method hashCode() is defined in the Object class and is inherited by all Java objects. In order for the Java Collections to work properly (and everything else in Java), the equals() and hashCode() methods must be compatible. Here, compatible means that if equals() reports that two instances are the same, then the hashCode() of both instances must be the same value. |
The File class encapsulates the files and directories of the local file system. The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file. |
What is the difference among JVM Spec, JVM Implementation, JVM Runtime ? |
A Java virtual machine or JVM is a virtual machine that runs Java byte code. This code is most often generated by Java compilers, although the JVM has also been targeted by compilers of other languages. The JVM has a stackA stack is a data structure that works on the principle of Last In First Out (LIFO). This means that the last item put on the stack is the first item that can be taken off, like a physical stack of plates. A stack-based computer system is one that is base based architecture. The JVM has instructions for the following groups of tasks * Load and store * Arithmetic * Operand stack management (push / pop) * Type conversion * Control transfer (branching) * Object Creation and Manipulation * Method invocation and return * Throwing exceptions |
The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. A hashmap is not synchronized and faster than hashtable. The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. HashMap does not guarantee that the order of the map will remain constant over time. |
Java is strictly pass-by-value. A common misconception exists that parameters in Java are passed by reference. They are not. Parameters are passed by value. Java doesn\'t pass method arguments by reference, it passes them by value i.e. it simply copies the bit pattern holding by the references. |
What do you mean by immutable ? How to create an immutable object ? |
Immutable objects means the value of that object can not be modify by applying operations on them. Java Provides the String class to create the mutable string objects. String s = new String(\"Immutable string.\"); |
A weak reference is a reference that does not protect the referenced object from the garbage collector. |
Object cloning means creating the identical object of any object. If you say : obj1=obj2; In the above statement obj1 is not actually making another copy of object, it simply makes the copy of reference bits. For this purpose java provides the clone() method for object cloning. This method is defined by the Object class. |
An object pool is a set of initialised objects that are kept ready to use. Object pooling is a way to manage access to a finite set of objects among competing clients. in other words, object pooling is nothing but sharing of objects between different clients. Pooling basically means utilizing the resources efficiently, by limiting access of the objects to only the period the client requires it. Object pooling can offer a significant performance boost; it is most effective in situations where the cost of initializing a class instance is high, the rate of instantiation of a class is high, and the number of instantiations in use at any one time is low. |
We know that an object is ready to garbage collected if it is not reachable by any reference. JVM has the facility for the reference counting. Suppose a parent object that has a reference to its child object, which has a reference back to its parent. These objects will never have a reference count of zero even though they may be unreachable by the roots of the executing program. Another disadvantage is the overhead of incrementing and decrementing the reference count each time. Because of these disadvantages, reference counting currently is out of favor. Garbage collection have some disadvantages: * The application�s working set may be larger. * Performance may not be as good as if you hand-optimize memory management (for more details, see �Performance�). * A common design pattern whereby resources are tied to the lifetime of objects does not work effectively under GC. * You must ensure that for any object you want to be long-lived you maintain a chain of strong references to it from a root object, or resort to reference counting for that object. |
The Tag interface defines the basic protocol between a Tag handler and JSP page implementation class. It defines the life cycle and the methods to be invoked at start and end tag. |
Static method hava some of the following restrictions : * Static methods can not be overridden. * Static methods can only be invoked directly without object reference within the same class and with the class name in another class. * There is only one copy of static method for the entire class. * They are available before creating the instance of the class. * Static method can\'t be declared as final or abstract. |
The JIT (just-in-time compiler), also known as dynamic translation, is a technique for improving the runtime performance of a computer program. Java program is compiled into an intermediate language called bytecodes, and it can be downloaded through the network and executed on any computers that have Java execution environment. JIT compiler is a program that turns Java bytecode into instructions that can be sent directly to the processor. The JIT is a code generator that converts Java bytecode into machine language instructions. Some Java Virtual Machines (VMs), including the VM in the Netscape Navigator browser, include a JIT in addition to a Java interpreter. Java programs compiled by a JIT generally run much faster than when the bytecode is executed by an interpreter. |
A Locale class represents a specific geographical, political, or cultural region. The Locale class allows you to control how multilanguage text is displayed in a Flash application at runtime. We and create a Locale object using the constructors in this class: * Locale(String language) * Locale(String language, String country) * Locale(String language, String country, String variant) |
The URL has a number of component parts. The URL locates a the resource over the internet. The URL class encapsulates Internet URLs. In a way, it does for the Internet resources what the File class does for local files. URL instance represents the location of a resource, and a URLConnection instance represents a link for accessing or communicating with the resource at the location. |
The two important TCP Socket classes : * Socket * ServerSocket Socket class allows us to read and write through the sockets. It provides two methods : getInputStream() and getOutputStream(). ServerSocket is used for normal two-way socket communication. |
Strings are immutable. But String s=\"Hello\"; String s1=s+\"World\" returns HelloWorld how ? |
String s=\"Hello\"; String s1=s+\"World\"; In the second line above, We are trying to concatenating the \"Hello\" and a new strign object \"World\". Here a new object is created \"HelloWorld\" and returned to the reference s1. Since string objects are immutable, the reference s is still pointing to \"Hello\". |
The classpath is the connection between the Java runtime and the filesystem. It defines where the compiler and interpreter look for .class files to load or the CLASSPATH is an environment variable that tells the Java compiler javac.exe where to look for class files to import or java.exe where to find class files to interpret. The class path can be set using either the -classpath option when calling an SDK tool (the preferred method) or by setting the CLASSPATH environment variable. |
A path tells the java compiler and java interpreter where ot find the classes they need to execute or import. Multiple entries in the class path are separated by a semicolon on Windows (;) and by a colon on UNIX (:). |
The Java collections framework is a set of classes and interfaces that implement commonly reusable collection data structures. A collection framework includes : * Collection Interface * Iterator Interface * Set Interface * List Interface * ListIterator Interface * Map Interface * SortedSet Interface * SortedMap Interface * HashSet & TreeSet Classes * ArrayList & LinkedList Classes * HashMap & Treemap Classes Vector & Stack Classes |
Yes! We can compile our java program without main() method. |
After method and constructor, Initialization blocks are the third place where the operations can be performed. Initialization block do not have identifier and they are of two types : * Instance initialization block. * static initializaton block. Static initialization block starts with the keyword static with opening and ending curly braces. Static initialization block is used to initialize the static variable of the class because they are available before any instance created of the class i.e. before executing the constructor. Hence static initialization block are the right place to initialize the static variable. |
How does a try statement determine which catch clause should be used to handle an exception? |
When an exception is thrown within the try block the JVM start searching from the first catch block associated with the try block, the first matching catch block is executed and rest are ignored. |
If a class doesn\'t have any constructors, what will happen? |
If a class doesn\'t have any constructors, the compiler will supply the default constructor. |
What will happen if a thread cannot acquire a lock on an object? |
If a thread cannot acquire a lock on an object, it will enter to the waiting state until it acquire the lock on that object. |
Coupling is the degree of dependence between the two modules. Coupling is broken down into loose coupling, tight coupling, and decoupled. Coupling is also used to describe software as well as systems. It is good to have low coupling between the modules for better object oreinted design. |
The following syntax is used to define the interface : accessModifier interface InterfaceName{ dataType var1; dataType var2; .............. .............. void method1(); void method2(); .............. .............. } Here accessModifier may be default or public. Interface may contain constant variables. These variables are implicitly public static final, you don\'t have to type it explicitly. Interface can have only public abstract methods, you dont have to type public abstract modifiers explicitly. |
An abstract class have abstract modifier in its declaration. An abstract class can contain instance variable, methods that can be concrete methods and abstract methods. An abstract class may not have any abstract method, that does not mean that it is not an abstract class. Example : public abstarct AbstractClass{ // instance variable int a; int b; //instance methods public int getValue(){} public void setValue(int){} //abstract method public int getMaxValue(); } |
The JVM heap is where the objects of a Java program live. The JVM\'s heap stores all objects created by an executing Java program. Objects are created by Java\'s \"new\" operator, and memory for new objects is allocated on the heap at run time. The JVM heap size determines how often and how long the VM spends collecting garbage. A Java Virtual Machine on 32-bit operating systems typically has a maximum heap size of 64Mb. You can modify the JVM heap size . |
Threads that work in the background to support the runtime environment are called daemon threads. Daemon threads are typically used to perform services for your application/applet. The virtual machine exits whenever all non-daemon threads have completed. Two methods are used in this context: public final void setDaemon(boolean isDaemon) public final boolean isDaemon() By default a thread you create is not a daemon thread. However you can use the setDaemon(true) method to turn it into one. Daemon thread is a low priority thread which runs in the back ground doing the garbage collection operation for the java runtime system. |
Volatile means the storage is likely to change at anytime and be changed but something outside the control of the user program. This means that if you reference the variable, the program should always check the physical address (ie a mapped input fifo), and not use it in a cashed way. Variables declared to be volatile will not be optimized by the compiler because the compiler must assume that their values can change at any time. We use volatile keyword to declare the volatile variable. |
Suppose You are having the four classes named A, B, C, and D. Assume that class A is the superclass of class B and class C. Now in a programming language, that support multiple inheritance, class D can inherit from the two classes B and C. Suppose class A has a variable v and this variable is inherited in the classes B and C. Again v is inherited by the class D from B and C. Now class D has indirectly inherited variable v form the class A but class D contain two version of the variable b inherited from classes B and C. This is the reason that Java does not support Multiple inheritance. This problem is called diamong problem, because if we desing it graphically, it looks like a diamond shape. |
Arraylist is faster than the Vector because ArrayList doesn\'t have synchronisation overhead, i.e. ArrayList has synchronized methods. |
Java is considered more secure than any other language because of its bytecode facility. Java applet\'s bytecode is dynamically downloaded over the network instead of the .exe file and executed by the JVM in the browser. So there is no overhead of virus or currepted file, because the JVM also checks the length of the bytecode. Security Implementation Mechanisms : * Java Authentication and Authorization Service (JAAS). * Java Generic Security Services (Java GSS-API). * Java Cryptography Extension (JCE). * Java Secure Sockets Extension (JSSE). * Simple Authentication and Security Layer (SASL). Java security services are separate from the security mechanisms of the operating system. Java provides security at various layers: * Application-Layer Security : At the application layer, application firewalls can be employed to enhance application protection by protecting the communication stream and all associated application resources from attacks. * Transport-Layer Security : Transport-layer security relies on secure HTTP transport (HTTPS) using Secure Sockets Layer (SSL). Transport security is a point-to-point security mechanism that can be used for authentication, message integrity, and confidentiality. * Message-Layer Security : In message-layer security, security information is contained within the SOAP message and/or SOAP message attachment, which allows security information to travel along with the message or attachment. |
The Phantom memory is a false memory. Memory that does not exist in reality. Phantom references point to objects that are already dead and have been finalised. |
Reflection is an API in java that allows an executing Java program to examine or \"introspect\" upon itself, and manipulate internal properties of the program. For example, it\'s possible for a Java class to obtain the names of all its members and display them. A reflection is what you see when you look in the mirror. Reflection is for dealing with class files you know very little about ahead of time. It is a powerful approach to analyze the class at runtime. If new classes are added into your application dynamically then Reflection is used to get the structure of the class. Example : import java.lang.reflect.*; public class ShowMethods { public static void main(String args[]) { try { Class c = Class.forName(args[0]); Method methods[] = c.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) System.out.println(methods[i].toString()); } catch (Throwable e) { System.err.println(e); } } } |
HotSpot is a JIT compiler. JIT is a part of the JVM that compiles Java bytecode to native machine code at runtime, to make your Java program run faster. HotSpot is the name of Sun\'s JIT compiler which is included in Sun\'s JVM. HotSpot generate native machine code for the CPU that they execute on. |
Creating too many threads in one JVM can cause the system to run out of memory or thrash due to excessive memory consumption. To prevent resource thrashing, server applications need some means of limiting how many requests are being processed at any given time. A thread pool offers a solution to both the problem of thread life-cycle overhead and the problem of resource thrashing. Methods in org.apache.avalon.cornerstone.blocks.threads that return ThreadPool ThreadPool AbstractThreadManager.getThreadPool(java.lang.String name) : Retrieve a thread pool by name. ThreadPool AbstractThreadManager.getDefaultThreadPool() : Retrieve the default thread pool. |
The comparable interface should be used when the current object is to be compared to objects of its type only. The comparator should be used when some external class is taking your class as a parameter for some comparison operation and it doesn\'t know how to compare the objects and expects you to give it. You have a set of objects where you want to sort it in both ascending and decending order. Just Comparable will not help you in this. Here you can implement your own comparator and pass it to the sorting algorithm to use. |
List is an ordered collection of elements by index. Key methods of List are : get(int index), indexOf(Object o), add(int index, Object o), etc. A Set cares about Uniqueness, it doesn\'t allow duplicates elements. The equals() method helps you to find out whether two objects are identical. A map stores the elements in the form of Key/Value pairs. Here key and value both are objects. A map cares about unique key (unique ID) to a specific value. You can search value in a Map by giving its key. |
Exceptions are the abnormal condition that you can handle by your program, but Error is an unrecoverable condition that can be handled by the program at runtime. Both Exceptiona and Error classes are drived from the class Trowable. Java running out of memory is an Error and can not be handled by the program. |
Java is an open source language that means you are free to download the java compiler and JVM. You don\'t have to buy these software. |
How do you send data from an applet to Servlet ? What are the steps involved in it ? |
The applet can send a GET/POST request to the servlet by opening a servlet URL with a query string. For example : // servlet URL URL url = new URL(getCodeBase(), \"/MyServlet?name=ABC\"); // open a connection to the servlet URLConnection servletCon = url.openConnection(); servletCon.setDoInput(true); // true, if we get data back // get the input stream from the servlet InputStream in = servletCon.getInputStream(); // read the response from the servlet .................. .................. } |
Different types of inner classes : * Regular inner classes. * Method local inner classes. * Anonymous inner classes. * Static nested classes. |
Nested top-level classes are declared within an enclosing class. Nested top-level classes are always defined with a static keyword. A nested top-level class/interface is defined as a static member of its enclosing class/interface, i.e. static inner classes are called nested top level classes. |
A member class is one that is declared within the class as like member varaibles and member functions. These classes are called inner classes, and can be instantiate with only if the enclosing class has been intantiated. |
No! A top level class can\'t be private or protected, it can only be either public or default. |
When invoked, the process starts but does not complete. Sometimes this may appear to be caused by the input that is being fed to the process which adds to the confusion over why the problem occurs.When you invoke any process from Java, you must use separate threads to pump data to/from |
Composition is a design technique that establishing relationships between classes. There are two fundamental ways to relate classes : inheritance and composition. Composition is an alternative way of inheritance to ralate classes. Example : class Fruit { //... } class Mango { Fruit fruit = new Fruit(); //... } |
Aggregation is a collection of several things grouped together or aggregation is a special kind of association that specifies a whole or a part of relationship. For example : A \'Car\', is consisted of an engine,a steering wheel, four tires, seats, gear box, fuel tank, engine oil tank, air filters etc. So all constituents of car are parts of it. Aggregation is transitive, i.e., if A is a part of B, and B is a part of C, then A is also a part of C. Aggregation is antisymmetric, i.e., if A is a part of B, then B is not a part of A. |
The methods of Object class are : * protected Object clone() : Creates and returns a copy of this object. * boolean equals(Object obj) : Indicates whether some other object is \"equal to\" this one. * protected void finalize() : Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. * Class extends Object> getClass() : Returns the runtime class of an object. * int hashCode() : Returns a hash code value for the object. * void notify() : Wakes up a single thread that is waiting on this object\'s monitor. * void notifyAll() : Wakes up all threads that are waiting on this object\'s monitor. * String toString() : Returns a string representation of the object. * void wait() : Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object. * void wait(long timeout) : Causes current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed. * void wait(long timeout, int nanos) : Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed. |
What is the relationship between synchronized and volatile keyword? |
When two or more threads access the shared variable and perform read/write operations, this variable should be declared within the synchronized method. The Java language allows threads that access shared variables to keep private working copies of the variables; this allows a more efficient implementation of multiple threads. The volatile modifier requests the Java VM to always access the shared copy of the variable so the its most current value is always read. Either put the variables in a synchronized method or block, or declare them volatile. |
What factors are used to decide using synchronized or volatile? |
Drawbacks of inheritance : * Difficulty of understanding complex hierarchy. * Makes writing a compiler harder, e.g. requires more dynamic type checking since type of an object can change during runtime. * Adversely affects execution speed, program size, program complexity, and incurs method passing overhead. * Inheritance forces a set of methods and fields on a class. You may not want some of these, and it is not necessary that all of these are required. There is no concept of partial inheritance. * Interface stability of base classes sometimes require even more complexity. |
What are the restrictions placed on the values of each case of a switch statement? |
The restrictions placed on the values of each case of a switch statement are : * The values of each case of a switch statement must be a compile time constant. * Only use the values that can be promoted to an int value, i.e. use byte, short, char, int only. |
If aaaa is an array then why aaaa.length why not aaaa.length()? |
In Java API, we have an Array class which has a variable named \"length\" to count the length of the array, hence we say, aaaa.length to count the length of the array. In the String class, we have a method named length(), which returns the length of the string. |
In most of the programming languages, variables can be assigned value in two ways : First, at the time of variable declaration. Second, later in the program. If you assigned value to variable later in the program, then the varaible will not hava a value at the time of compilation, it will be assigned a value at runtime. This runtime assignment of value to variable is called Dynamic typing. |
Assignment of value to the variable at the time of variable declaration is called static typing. |
Map is an Interface and HashMap is a class that implements the Map interface. HashMap is not serialized. |
An object is a runtime entity. It is an instance of the class and have its own state, made up of values assigned to all variables of its class collectively. An object will hava access to all the behaviours(methods) of its class. The object can be allocated memory using the \"new\" keyword. For Example : //class declaration class CrateObject{ } //Object creation CreateObject o = new CreateObject(); |
Java uses the unicode character set for all the characters and symbols of the world. The Unicode provides the Standard character set to support all language, platform, program. Before the invention of Unicode, many different character sets and encodings had to be used for different languages. It was not possible to store plain text files containing text from languages using different character sets in the same document. Unicode provides a unique number for every character. The Unicode Consortium is a non-profit organization founded to develop, extend and promote use of the Unicode Standard, which specifies the representation of text in modern software products and standards. |
What is a stream and what are the types of Streams and classes of the Streams? |
A stream is sequence of flowing data. Stream is an abstract class in Java, that is used to either read the data or write the data to/from a disk file, device, a network socket, other programs, a memory array etc. There are two types of streams that Java support : * Byte oriented streams. * Characters oriented streams. Classes of the Streams : * BufferedInputStream * BufferedOutputStream * BufferedReader * BufferedWriter * ByteArrayInputStream * ByteArrayOutputStream * CharArrayReader * CharArrayWriter * DataInputStream * DataOutputStream * FileInputStream * FileOutputStream * FileReader * FileWriter * FilterInputStream * FilterOutputStream * FilterReader * FilterWriter * InputStream * InputStreamReader * LineNumberReader * ObjectInputStream * ObjectOutputStream * OutputStream * OutputStreamWriter * PipedInputStream * PipedOutputStream * PipedReader * PipedWriter * PrintStream * PrintWriter * PushbackInputStream * PushbackReader * RandomAccessFile * Reader * SequenceInputStream * StreamTokenizer * StringReader * StringWriter * Writer |
TCP/IP is a reliable connection oreinted network protocol. It ensure that a file sent from one network node to another node is a complete file. UDP is a connectionless, unreliable network protocol. UDP is faster than TCP/IP. UDP is used where the speed of data transmission is more important than reliability. |
In multithreading environment multiple threads run concurrently, sometimes you need two thread to communicate to each other by forwarding the data. The multithread data access and communication classes are: Mutex, Condition, and Lock |
A thread group represents a set of threads. Every Java thread is a member of a thread group. In addition, a thread group can also include other thread groups. Threads can only access the ThreadGroup to which they belong. Thread groups provide a mechanism for collecting multiple threads into a single object and manipulating those threads all at once, rather than individually. A tree structure can be formed from ThreadsGroups containing other ThreadGroups. Java provides the ThreadGroup class for creating and managing the thread groups. The ThreadGroup class provides two constructors : ThreadGroup(String name) ThreadGroup(ThreadGroup parent, String name) |
Why is UTFDataFormatException thrown by DataOutputStream.writeUTF() when serializing a String? |
Why is OutOfMemoryError thrown after writing a large number of objects into an ObjectOutputStream? |
When you write a large number of objects into an Object output stream, these objects might be unreachable by the reference that the reference table is hoding. If they are not garbage collected by the JVM, resulting the running out of memory error. A call to the ObjectOutputStream.reset() method resets the object/handle table to its initial state, allowing all previously written objects to be eligible for garbage collection. |
The following code can help u to obtain serialVersionUID of a class import java.io.*; public class jk { public static void main(String args[]) { String s = new String(\"test\"); Class cl = s.getClass(); long uid = ObjectStreamClass.lookup(cl).getSerialVersionUID(); System.out.println(uid); } } |
This output of the above program : 10 |
The above program give an error in compilation, like a non-static field can be referenced from a static context. The problem lies in the variable i in print statement inside the main() method. The variable i can only be accessed through the object reference. |
The above program give an error in compilation, illigal start of expression at static int i in the static initialization block. |
The above program give 3 errors in compilation : 1. a non-static variable i can be referenced from a static context in the main method. 2. modifier static is not allowed in the static initialization block. 3. can\'t assign a value to final variable. |
The above program will give an error : can not assign a value to a final variable at i=10 in the static initialization block. |
Program will give error : illigal start of expression at \"static final int i=0;\" |
Program will give error : illigal start of expression at \"static int i=0;\" |
The program will give error : a non-static method display() can be referenced from a static context. |
Output of the program : 0 90 |
Output of the program : 0 90 |
Output of the program : 0 90 90 |
Output of the program : 0 90 |
The program will give an error : a non-static method display() can not be referenced from a static context. |
This keyword is basically a Java keyword ,\'this\' can be used to access class variables and methods. |
thread is the basically as basic unit of program execution. A process can have several threads running concurrently, each performing a different job, such as waiting for events or performing a time consuming job that the program doesn\'t need to complete before going on. When a thread has finished its job, the thread is suspended or destroyed. See also process. |
Throw is the bassically as a Java keyword that allows the user to throw an exception or any class that implements the \"throwable\" interface. |
Throws is the basically a Java keyword , It is used in method declarations that specify which exceptions are not handled within the method but rather passed to the next higher level of the program. |
Transaction is basscially an atomic unit of work that modifies data. A transaction encloses one or more program statements, all of which either complete or roll back. Transactions enable multiple users to access the same data concurrently. |
transient is the basically a keyword in the Java programming language that indicates that a field is not part of the serialized form of an object. When an object is serialized, the values of its transient fields are not included in the serial representation, while the values of its non-transient fields are included. |
try is the basically as a Java keyword that defines a block of statements that may throw a Java language exception. If an exception is thrown, an optional catch block can handle specific exceptions thrown within the try block. Also, an optional finally block will be executed regardless of whether an exception is thrown or not. |
It is basically a class or interface. |
Variable is the basically identifier, which item of data named by an identifier. Each variable has a type, such as int or Object, and a scope. |
Void is basically a type of Java keyword , It is used in method declarations to specify that the method does not return any value. void can also be used as a nonfunctional statement. |
Volatile is basically a Java keyword used in variable declarations that specifies that the variable is modified asynchronously by concurrently running threads. |
While is the basically a type of Java keyword, It is used to declare a loop that iterates a block of statements. The loop\'s exit condition is specified as part of the while statement. |
Wrapper is the type of object, its encapsulates and delegates to another object to alter its interface or behavior in some way. |
Class method is the bassically a that type method which is invoked without reference to a particular object. Class methods affect the class as a whole, not a particular instance of the class. Also called a static method. See also instance method. |
Clas variablw is the basscially a type of data item which is associated with a particular class as a whole not with particular instances of the class. Class variables are defined in class definitions. Also called a static field. See also instance variable. |
A pseudo-method that creates an object. In the Java programming language, constructors are instance methods with the same name as their class. Constructors are invoked using the new keyword. |
That is the bassically a java keyword which is used for the represent an instance of the class in which it appears. |
Web application archive file. A JAR archive that contains a Web module. |
A Utility class is bassicaly a class that contains grouped static functionality |
yes |
After a thread is started, via its start() method or that of the Thread class, the JVM invokes the thread\'s run() method when the thread is initially executed. |
The advantages of Spring framework are: |
Features of Spring : |
What are the various steps involved in a Spring beans life cycle? |
The bean factory performs several steps before a bean is ready is use: |
Piecing together beans within the Spring container is known as wiring. Wiring the beans means you are telling the Spring container what beans are needed and how the container should use dependency injection to tie them together. You should have some basic idea of XML for basic wiring of beans. |
A bean can be added in spring application using : |
The org.springframework.beans.factory.xml.XmlBeanFactory is a class that implements the BeanFactory interface. To create an XmlBeanFactory, pass a java.io.InputStream to the constructor. The InputStream will provide the XML to the factory. For example, the following code snippet uses a java.io.FileInputStream to provide a bean definition XML file to XmlBeanFactory. |
What are singleton beans and how can you create prototype beans? |
The singleton property of <bean> tells the context whether or not a bean is to be defined as a singleton. |
We use the <property> element to set the properties that reference other beans. |
You can embed a <bean> element directly in the <property> element. |
How will you handle the ambiguities of autowiring in Spring? |
When autowiring using byType or constructor, it\'s possible that the container may find two or more beans whose type matches the property\'s type or the types of the constructor arguments. What will happen if there are ambiguous beans suitable for autowiring? |
How will you wire a string value to a property whose type is a non-string? |
Yes. You can wire a string value to a property whose type is a non-string. The java.beans.PropertyEditor interface provides a means to customize how String values are mapped to non-String types. 7 |
The ThrowsAdvice lets you definebehaviour should an exception occur. ThrowsAdvice is a marker interface and contains no method but need to be implemented. A class that implements this interface must have at least one method with either of the following two signatures: * void afterThrowing(Throwable t) * void afterThrowing(Method m, Object[] o, Object target, Throwable t) |
The PreparedStatementCreator interface is a callback interfaces used by the JdbcTemplate class. This interface creates a PreparedStatement given a connection, provided by the JdbcTemplate class. Implementations are responsible for providing SQL and any necessary parameters. A PreparedStatementCreator should also implement the SqlProvider interface if it is able to provide the SQL it uses for PreparedStatement creation. This allows for better contextual information in case of exceptions. It has one method: PreparedStatement createPreparedStatement(Connection con) throws SQLException Create a statement in this connection. Allows implementations to use PreparedStatements. The JdbcTemplate will close the created statement. |
What are the benefits of the Spring Framework transaction management ? |
Spring Framework supports: |
PQSRQSRQ |
type var-name[]; |
We know about the variable access, Which is signifies to the ability of code in one class to access a variable in another class, in this case we\'ll looking at the other keywords that apply to variable declarations,but first we\'ll do a quick review of the difference between instance and local variables. |
Instance variable is basically a signifies inside the class but in the outside of any method and its initialized when class is initialized. its mainly a field which is belongs to the unique object.This is following in the code.: |
Local variable is basically use for the declared within a method, Its means mainly variable is not just initialized within the method, but also declared within the method, Local variable is basically in always n the stack but its not happening in the case of heap.if the variable is an object reference the object itself will still be created on the heap. |
final variable is basically declared by the final keyword , It makes impossible to reinitialize that variable once it has been initialized with an explicit value. |
If we mark to the instance variable as a transient variables , When we enter to the serialize the object declaring it then the java to ignore this variable. |
A Volatile modifier explains the JVM that a thread accessing the variable must always reconcile which is own private copy of the variable with the master copy of the memory . |
Static modifiers has a many special type of methods and variables which is treating as a concepts entirely separate from the other modifiers.the count will just be initialized back to a default value with each new instance. The answer to both the utility method always runs the same scenario and the keep a running total of instances scenario is to use the static modifier. Variables and methods are marked static which is belong to the class, That\'s why we can use static method or variable without having any instances of that class at all. We need only have a class available to be able to invoke a static method or access a static variable. |
Accessing Static method is very impotent for the any code .When instance of the classes in the code is absence then how to code is appropriate that we can use the accessing static method for make a appropriate code. |
Declaration rules is basically a identifying correctly constructed source files, package declarations, import statements, class declarations, interface declarations, method declarations, variable declarations, and identifiers. |
We just focusing about Source File Structure which is the kind of import and package issues .The following legal code declares a class Foo, in package com.geeksanonymous : |
We can use import function in the two ways : |
When we want our code to actually run, We have to get the ball rolling with a main() method. The following rules apply to the main() method : |
Interface implementation is a identifying class that correctly implement N an interface which is from java.lang |
When we create an interface We can define the functioning of the class i mean to say we can define whats the exactly the call can do .without saying anything about how the class will do it. Interface is basically a contract. |
In this interface we are allowed to put a constants in an interface,it would be much easier for programmers to remember names like HIGH_GRAVITY, LOW_BOUNCE, and HIGH_BOUNCE as opposed to knowing the exact int values corresponding to each of those. we have a following code : |
When we would like to implement an interface , we\'re agreeing to adhere to the contract defined |
The system identifies you by the user id and group id assigned to you by system administrator. You don\'t need to remember your user id and group id, the system translate username as user id and group name as group id. You need to know your username only. |
An Action class in the struts application extends Struts \'org.apache.struts.action.Action\" Class. Action class acts as wrapper around the business logic and provides an interface to the application\'s Model layer. It acts as glue between the View and Model layer. It also transfers the data from the view layer to the specific business process layer and finally returns the processed data from business layer to the view layer. |
The new operator instantiates a class by allocating memory for new object and returning a reference to that memory. The new operator also invokes the object constructor. The new operator dynamically allocates memory for an object. It has this general form: class-var = new classname( ); The reference returned by the new operator does not have to be assigned to a variable. The answer is that Java\'s simple types are not implemented as objects. Rather, they are implemented as \"normal\" variables |
Following is added into jdk1.5 .which was not into jdk1.5: Java Language Features Generics Enhanced for Loop Autoboxing/Unboxing Typesafe Enums Varargs Static Import Metadata (Annotations) Virtual Machine Class Data Sharing Garbage Collector Ergonomics Server-Class Machine Detection Thread Priority Changes Fatal Error Handling High-Precision Timing Support So many other new features has been added. |
Is actionform belongs to the model or view or controller in struts? |
ActionForm class is used to capture user-input data from an HTML form and transfer it to the Action Class. ActionForm plays the role of Transport Vehicle between the presentation Tire & Business Tier. |
It contains the statements which likely to throw an exception. If an exception is raised, the remaining statements in the try block are skipped. Try block must be followed by either catch or finally or both. The catch block is executed only if try block throws an exception. Catch block cannot be written without try block. For each try block there can be zero or more catch blocks. |
How do we config struts config file in spring configuration file? |
To use the Struts Spring plugin, add the ContextLoaderPlugIn to your Struts config file (usually struts-config.xml): |
Struts and webwork has joined together to develop the Struts 2 Framework. Struts 2 Framework is very extensible and elegant for the development of enterprise web application of any size. In this section we are going to explain you the architecture of Struts 2 Framework. |
The JRE is the environment within which the virtual machine runs.JRE JAVA Runtime Environment JVM JAVA Virtual Machine JRE is the container, JVM is the content. JRE=JVM+ rt.jar The JRE includes the JVM, which is what actually interprets the byte code and runs the program. To do this the JVM uses libraries and other files provided by the JRE. |
There are two types of Controllers in Struts. |
|
Collections is a class, contains methods such as sort(), binarySearch(), copy(), etc.ADD, Remove, Search, retrieve operations can be performed. |
EJB technology is the server-side component architecture for the Java 2 Platform, Enterprise Edition (J2EE) platform. EJB technology enables rapid and simplified development of distributed, transactional, secure and portable applications based on Java technology. |
|
|
|
This methods get the last col number for the sheet. |
|
We creates an object of the shape. In this object of the shape we are assigning rectangle shape and set the size and position. Initial values for x and y axis are 0.The height and width are 400 and 400 respectively. Then create an object of Shape and set values, fill type, background color and foreground color of the slide. Then finally add into slide. We are using setFillType(Fill.FILL_SHADE) method to set fill type, setBackgroundColor(Color.blue) method to set background color and setForegroundColor(Color.green) method to set the text color. |
Described the method addPicture(byte[] pictureData,int format)? |
This methods add a picture to the workbook and the return type is int of this method. In This method two parameters are passed into this method. The first parameter is pictureData and second parameter is format .The pictureData is byte form of the picture. In this example we are using Picture.PNG as format. |
|
Encapsulation, Inheritance and Polymorphism are the three OOPs Principles. Encapsulation: Is the Mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse. Inheritance: Is the process by which one object acquires the properties of another object. Polymorphism: Is a feature that allows one interface to be used for a general class of actions. |
What is the difference between prefix and postfix of -- and operators? |
The prefix form returns the increment or decrement operation and returns the value of the increment or decrement operation.The postfix form returns the current value of all of the expression and thenperforms the increment or decrement operation on that value. |
Finally block will execute whether or not an exception is thrown. If an exception is thrown, the finally block will execute even if no catch statement match the exception. Any time a method is about to return to the caller from inside try/catch block, via an uncaught exception or an explicit return statement, the finally clause is also execute. |
String objects are constants, whereas StringBuffer objects are not. String class supports constant strings, whereas StringBuffer class supports growable, modifiable strings. |
abcdefabcDEF |
The File class is used to create objects that provide access to the files and directories of a local file system. |
What is the difference between the File and RandomAccessFile classes? |
The File class encapsulates the files and directories of the local file system. The RandomAccessFile class provides the methods needed to directly access data contained in any part of a file. |
How many bits are used to represent Unicode, ASCII, UTF-16 and UTF-8 characters? |
Unicode requires 16-bits and ASCII requires 8-bits. Although the ASCII character set uses only 1-bits, it is usually represented as 8-bits. UTF-8 represents characters using 8, 16 and 18-bit patterns. UTF-16 uses 16-bit and larger bit patterns |
What is the relationship between an event-listener interface and an event-adapter class? |
An event-listener interface defines the methods that must be implemented by an event handler for a particular kind of event. An event adapter provides a default implementation of an event-listener interface. |
A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices. Only one item may be selected from a Choice. A List may be displayed in such a way that several List items are visible. A List supports the selection of one or more List items. |
The BeanFactory is provide an advanced configuration mechanism capable of managing beans of any kind of storage facility. |
java.lang.Object |
what do you think is the logic behind having a single base class for all classes? |
|
why most of the Thread functionality is specified in Object Class? |
|
what is the importance of == and equals () method with respect to String object? |
|
No. String is not a Wrapper class |
Using length () method of String class. |
How many objects are in the memory after the exeception of following code segment? |
String str1 = \"ABC\";String str2 = \"XYZ\";String str1 = str1 + str2;There are 3 Objects. |
The trim () eliminate spaces from both the ends of a string. |
what is the possible runtime exception thrown by substring () method? |
ArrayIndexOutOfBoundsException |
1. Running Java File with single command,directly run the file with java command and it implicitly compiles. 2. Added new String Methods e.g. isBlank() ,lines(),strip(), stripLeading(), stripTrailing(),repeat(int) 3.JEP 323, Local-Variable Syntax for Lambda Parameters . |
JDK 11 new features-- Local-Variable Syntax for Lambda Parameters |
var list = new ArrayList< String >() (var s1, var s2) -> s1 + s2 It was in Java 8 but got removed in Java 10. Now it’s back in Java 11 The JDK 11 also allow annotations to be added to lambda’s parameters without having to write full variable type name Function< String, String > append = (@NonNull var string) -> string + " World"; |
Oracle will soon roll out Java 12 in March 2019 and new releases |