Advertisement :
   Log In    OR    Register  
  Topics :  
RMI Example

Home >>> Interview Questions on Java >>> questions and answer >>> Discuss these
Struts Tutorials:
Struts2 Tag CheckBoxList
, Checkbox, Iterator, IF
Struts2 Tag Library Example Struts2 Tiles Example Struts2 Tiles I18N Example Struts2 Questions Struts Tiles I18N Example Struts Eclipse MVC Struts2 Tags Struts2 Example and Tutorial Struts MVC Struts2 Validation
Hibernate Tutorials: Hibernate Case Study Class Hierarchy Persist Example Using Hibernate Interceptor Hibernate Questions with Answer Hibernate Many-to-Many Mapping Example Hibernate one-to-many Mapping Example Hibernate and ORM tools Spring Hibernate Example Hibernate SessionFactory Example Hibernate Mapping Class Hierarchy Hibernate Questions Hibernate SessionFactory Questions Spring Hibernate Example: Spring Hibernate Case Study

Written By : Amit
Title :
Java Interview Questions Answer
Description : Discuss these
More...


Written By : Girish
Title :
ThreadPoolExecutor Example code
Description : Explained with question answer
More...


Written By : Sameer1
Title :
Some Questions on
Description : Java J2EE Technology
More...

Tags/Keywords : interview questions Java, Java Questions
Author : Amit
Date (Year/Month/Date): 2009-01-25 Java Interview Questions and answer
 
Advertisement :
Java Interview Question 1:
How can you invert a String
"Questions and Answers of
technology" to another String
"technology of Answers and
Questions"?

Java Interview answer
Using java.util.StringTokenizer, the default
constructor uses following default delimitors
1. space (" ")
2. tab ("\t")
3. new line ("\n")
4. carriage return ("\r")
5. form feed ("\f")

Now StringTokenizer's nextToken() method
returns following words:
1. Questions
2. and
3. Answers
4. of
5. technology

Now placing these words in any order
is quite simple.

Another suggestion is to use String.split
as this method can split a string in array
and thus returning all the words.
Java Interview Question 2: What are the basic differences between ArrayList and LinkedList? As the name suggest ArrayList is a List implementation arround an Array (internally handled) and LinkedList is a List which has all the items linked together. So when an item is added/removed from an ArrayList, it internally creates another Array and transfer all the items to the new Array in case the capacity of the ArrayList is altered. Whereas in case of LinkedList, all items has internal links from one item to another. If an item is added or removed from LinkedList, then only the link is added or changed from one item to another. So if size of ArrayList or LinkedList is large, then addition or deletion or modification of items arround start or towards end of the ArrayList, results in lower performance. But in case of LinkedList, as link of the next or previous item only changes, performance is good. In case of retrieval/get operation, if any item is retrieved from the ArrayList, then it is just getting the item value from the Array with an index number, so performace is good. But in case of LinkedList, item is queried from the end which is closer to the index of the item queried. Suppose LinkedList is very large, and addition or removal from the middle, so relatively poor performance. Java Interview Question 3: Is it mandatory to have all the objects in an object hierarchy to implement java.io.Serializable to make the entire object graph persistable into a Hard disk? Or can this be possible, like class A ...... class B extends A implements java.io.Serializable. In this example, if B is persisted, will A also persist with values preserved? Java Interview answer No, in an object hierarchy if any of the class implements java.io.Serializable, then all subclass to this class in object graph persist. It is not required that all the subclass to implement java.io.Serializable, but mandatory for the supe class (like A) to implement Serializable Java Interview Question 4: In case of the following code, what is your observation about serialization and de-serialization? class A { public String name=""; public A(String name){ this.name = name; } } class B extends A implements java.io.Serializable { public B(String name) { super(name); } } Java Interview answer This will throw java.io.InvalidClassException exception while deserializing, as A is not Serializable, and doesn't have a default blank constructor, so the deserialization process cann't happen. Correction is either make A implements Serializable or add a default A() blank constructor in class A. Java Interview Question 5: Where to use abstract and interface in a design context/scenario? Java Interview Answer If the requirement is to provide a specification of contract between different modules/functionally, whereby complete implementation is provided at runtime, then interface is of choice. For example, JDBC API, it has most of the interfaces defined, and the implementation is left to the JDBC driver provider. Each vendor provided its own implementation of Connection, Statement and ResultSet, and these implementations are independent of other vendor's implementation. In case there is a functionality (default) is provided, but there is an option for overriding the default implementation, and controlling lifecycle in a separate module, then abstract class is to be considered. For example, HttpServlet, which is an abstract class, but it provides default implementation of service method, doGet, doPost and many more. But developer can provide his/her own functionality by overriding service, doGet and doPost etc methods or not. And HttpServlet lifecycle is handled by web container, not the developer (As developer cannot create instance of HttpServlet class using "new" operator).
Advertisement :
 


	
Are you interested in solving a very interesting Technology Stack while Playing this Game          

Please write your Comment on this Matter
(This will be visible if found suitable):
Name: *
Email (will not be displayed): *
Matter: *
27,24
Enter bigger number from above :*
Home >>> Interview Questions on Java >>> questions and answer >>> Discuss these
Visitor/User referred related external URL:
(Visible upon review and approved by this site Administrator)
Referred By Name *:
Resource URL *: (e.g, URL should be starting with http://www.-----.---)
 
Resource Short Description *:
4,21
Enter bigger number from above : *

Please log in to add or reply to any matter<- requires login
Log in or Register
Copyright © 2008-2009, Interview-Questions-Tips-Forum, All Rights Reserved.
CONTACT    PRIVACY POLICY    DISCLAIMER
Terms of Use and Disclaimer :

This web site provides some of the information about various technologies, example 
code, tips, tutorials etc. Like any printed materials, content of these pages may 
become out of date over a period of time. Therefore all visitor/users of this web 
site are requested/advised to refer to the originating parties/sources for the 
latest changes and happenings for detailed information. This information is not 
intended to be a substitute for the original reference provided by the originating 
parties/sources.

By accessing and using this website in any ways, including, without
limitation, browsing the website pages, using any information, using any content and/or 
downloading any materials, you agree to and are bound by the terms of use 
described in this page and Usage Terms and Conditions. 
If you do not agree to all of 
the terms and conditions contained in the terms of use described in this
page and Usage Terms and Conditions, do not use this 
website in any manner. If you are using the website on behalf of your 
employer, you represent that you are authorized to accept these Terms of Use 
on your employer's behalf.

All Trademarks are property of their respective owner. Appropriate measure is being
taken for providing accurate and up-to-date information but like any printed materials,
these blog(s)/contents may eventually be outdated one day, so if you are using any 
of these information, please refer original content/documentation from respective sources. 
And under no circumstances shall the Author of these contents and/or this web site
be liable for any loss, damage, expense incurred or suffered which is claimed to have
occurred because of usage of the contents of this web site.
If you have any questions/queries/feedback/suggestions then please write to this web
site owner at contact.