Natraj Interviews.doc

32
1.First Interview: 10-10-2009 1)How many ways are there to create an object? i) Using ‘new’ oerator: Test s=new Test(); ii) Factory metho! : Thread t=Thread.currentThread(); iii) newInstance") : Class c=Class.forName(“Test”); O!ect o!=c.new"nstance(); creates Test class O!ect. Test t=(Test)o!; i#)c#one"): Test t$=new Test($%&'%); Test t'=t$.clone(); #) $eseria#i%ation : ile"n ut*tream fis=new ile"n ut*tream(“Test.t+t”); O!ect"n ut*tream ois=new O!ect"n ut*tream(fis); User,ef*erCls uds= User,ef*erCls) Ois.readO!ect(); Ois.close(); 2) &hat are the !i''erences b(w Hash a an! Hash*et? Hash a Hash*et "t stores the !ata in +ey, va# e format. "t allows ! #icate elements as va# es. "t im lements a "t allows onl- one / e-. "t stores grou ed data. "t does not allow an- ! #icates. "t im lements *et. "t does not allow / . ) &hat is the !i''erence b(w wait"-), s#ee"-) wait"-),yie#!")? &ait"-) *#ee"-) 3 nnin4 to &aitin4( *lee ing/0loc . "t ma es the current thread to s#ee to the 4iven secon!s and it co #! s#ee #ess than the gi#en seconds if it recei#es noti'y")( notifyAll() call. "n this case& the #oc+s wi## be re#ease! efore going into waitin4 state so that the other threa!sthat are waitin4 on that object wi## se it. Causes current thread to wait until either ,o "t ma es the current threa! to s#eefor e5act#y the 4iven secon!s. "n case of slee ()& once the thread is entered into s-nchroni1ed loc /method& no other thread will e ale to enter into that method/loc .

Transcript of Natraj Interviews.doc

1.First Interview: 10-10-2009

1)How many ways are there to create an object?

i) Using new operator: Test s=new Test(); ii) Factory method: Thread t=Thread.currentThread(); iii) newInstance(): Class c=Class.forName(Test);

Object obj=c.newInstance(); (creates Test class Object.

Test t=(Test)obj;

iv) clone():

Test t1=new Test(10,20); Test t2=t1.clone();

v) Deserialization: FileInputStream fis=new FileInputStream(Test.txt);

ObjectInputStream ois=new ObjectInputStream(fis);

UserDefSerCls uds= UserDefSerCls) Ois.readObject();

Ois.close();

2) What are the differences b/w HashMap and HashSet?

HashMap HashSet

It stores the data in key, value format.

It allows duplicate elements as values.

It implements Map

It allows only one NULL key.

It stores grouped data.

It does not allow any duplicates.

It implements Set.

It does not allow NULL .

3) What is the difference b/w wait(-), sleep(-)& wait(-),yield()?

Wait(-) Sleep(-)

Running to Waiting/ Sleeping/Block.

It makes the current thread to sleep upto the given seconds and it could sleep less than the given seconds if it receives notify()/notifyAll() call.In this case, the locks will be released before going into waiting state so that the other threads that are waiting on that object will use it.

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.

DoIt makes the current thread to sleep for exactly the given seconds.

In case of sleep(), once the thread is entered

into synchronized block/method, no other

thread will be able to enter into that

method/block.

Yield()( when a task invokes yield(), it changes from Running state to Runnable state. making currently executing thread to temporarily pause and allow other threads to execute.*4) Can we create a userdefined immutable class?

Yes. i) Make the class as final and ii) make the data members as private and final.

*5) What are the differences b/w String and StringBuffer?

String StringBuffer

It is immutable.

It wont give any additional space.Not Synchronized performance highNot contains append(), insert() It is mutable.

gives 16 additional characters memory space.Synchronized class Low performanceThis class contains append(), insert()

6) Which Collections F/W classes did you use in your project?

List, ArrayList, LinkedListadd() Set, TreeSet, HashSet-- HashMapput(), get(), entrySet(), keyset() Map.Entry

Iterator----hasNext(), next() ListIterator.7) Can you write the simple code for HashMap? HashMap hm=new HashMap();

hm.put(key1,value1);

hm.put(key2,value2);

hm.put(key3,value3);

Set set=hm.keySet(); // gives keys Set i.e., {key1,key2,key3} Iterator itr=set.iterator(); while(itr.hasNext()){ //true.false String empkeys=itr.next(); //for keys String empvalnames=hm.get(empkeys); //gives values by taking keys. System.out.println(empname+empvalnames+empid+empkeys);

}

8) What are thread states?

i) Start: Thread thread=new Thread();

ii) Runnable: looking for its turn to be picked for execution by the Thread Schedular based on thead priorities. (setPriority())

iii) Running: The Processor is actively executing the thread code. It runs until it becomes blocked, or voluntarily gives up its turn with Thread.yield(). Because of Context Switching overhead, yield() should not be used very

frequently.iv) Waiting: A thread is in a blocked state while it waits for some external processing such

as file I/O to finish.

Sleeping(sleep(): Java threads are forcibly put to sleep (suspended) with this overloaded method.

Thread.sleep(milliseconds); Thread.sleep(milliseconds,nanoseconds);

Blocking on I/O: Will move to runnable after I/O condition like reading bytes of data etc changes.

Blocked on Synchronization: will move to Runnable when a Lock is acquired.v) Dead: The thread is finished working. How to avoid Deadlock: 1) Avoid a thread holding multiple locks---- If no thread attempts to hold more than one lock, then no deadlock occurs.

2) Reordering lock acquisition:--

If we require threads to always acquire locks in a particular order, then no deadlock occurs.

2.Oracle Corporation:- 15-11-2009

9) What are differences b/w concrete,abstract classes and interface & they are given?

Concrete class: A class of only Concrete methods is called Concrete Class. For this, object instantiation is possible directly. A class can extends one class and implements many interfaces. Abstract class: Interface:

*A class of only Concrete or only Abstract or both.

*Any java class can extend only one abstract class.

*It wont force the programmer to implement/override all its methods.

*It takes less execution time than interface.

* It allows constructor.This class cant be instantiated directly. A class must be abstract when it consist at least one abstract method.

It gives less scope than an Interface.

It allows both variable & constants declaration.

It allows methods definitions or declarations whenever we want.

It gives reusability hence it cant be declared as final.

only abstract methods.

A class can implements any no. of interfaces(this gives multiple interface inheritance )It forces the programmer to implement all its methodsInterface takes more execution time due to its complex hierarchy.* It wont allow any constructor.It cant be instantiated but it can refer to its subclass objects.

It gives more scope than an abstract class.By default, methods(public abstract variables(public static final.

It allows methods declarations whenever we want . But it involves complexity.

Since they give reusability hence they must not be declared as final.

10) Can you create a userdefined immutable class like String?

Yes, by making the class as final and its data members as private, final.

11) Name some struts supplied tags?

a) struts_html.tld b) struts_bean.tld

c) struts_logic.tld d) struts_nested.tld

d) struts_template.tld e) struts_tiles.tld.12) How to retieve the objects from an ArrayList?

List list=new ArrayList(); // List list=new ArrayList();

list.add(element1); list.add(element1);list.add(element2); list.add(element2); list.add(element3); list.add(element3);

// Iterator iterator=list.iterator(); for(String str:list) s.o.p(str); } Iterator iterator=list.iterator(); while(iterator.hasNext()){ String str=(String)itr.next(); S.o.p(string); }

}

13) What are versions of your current project technologies?

Java 5.0; Servlets 2.4, Jsp 2.0; struts 1.3.4 ; spring 2.0; Hibernate 3.2, Oracle 9i. weblogic 8.5.14) What is Quality?

It is a Measure of excellence. state of being free from defects, deficiencies, and significant variations. A product or service that bears its ability to satisfy stated or implied needs."

15) Can I take a class as private?

Yes, but it is declare to inner class, not to outer class. If we are declaring "private" to outer class nothing can be accessed from that outer class to inner class.

16) How can you clone an object?

A a1=new ();

B a11=a1.clone();

17) What methods are there in Cloneable interface?

Since Cloneable is a Marker/Tag interface, no methods present.

When a class implements this interface that class obtains some special behavior and that

will be realized by the JVM.

18) What is the struts latest version? Struts 2.019) How are you using Statement like interface methods even without knowing their

implementations classes in JDBC?

20) Which JSP methods can be overridden?

jspInit() & jspDestroy().

21) Explain the JSP life-cycle methods?

1. Page translation: The page is parsed & a Java file containing the corresponding servlet is

created. 2. Page compilation: The Java file is compiled. 3. Load class: The compiled class is loaded. 4 .Create instance: An instance of the servlet is created. 5. Call jspInit(): This method is called before any other method to allow initialization. 6. Call _jspService(): This method is called for each request. (cant be overridden)7. Call jspDestroy(): The container calls this when it decides take the instance out of service.

It is the last method called the servlet instance. 3.Date:17-11-2009- Telephonic22) What Design Patterns are you using in your project?

i) MVC(separates roles using different technologies, ii) Singleton Java class(To satisfy the Servlet Specification, a servlet must be a Single

Instance multiple thread component.

iii) Front Controller( A Servlet developed as FrontController can traps only the requests.

iv) D.T.O/ V.O(Data Transfer Object/Value object is there to send huge amount of data

from one lalyer to another layer.

It avoids Network Round trips. v) IOC/Dependency Injection( F/w s/w or container can automatically instantiates the

objects implicitly and injects the dependent data to that object.

vi) Factory method( It wont allows object instantiation from out-side of the calss. vii) View Helper( It is there to develop a JSP without Java code so that readability,

re-usability will become easy.

23) What is Singleton Java class & its importance?

A Java class that allows to create only one object per JVM is called Singleton Java class.

Ex: In Struts f/w, the ActionServlet is a Singleton Java class.

Use: Instead of creating multiple objects for a Java class having same data, it is recommended

to create only one object & use it for multiple no. of times.

24) What are the differences b/w perform() & execute()?

perform() is an deprecated method.

25) What are the drawbacks of Struts? Is it MVC-I or II? Struts is MVC-II 1) Struts 1.x components are API dependent. Because Action & FormBean classes must

extend from the Struts 1.x APIs pre-defined classes.

2) Since applications are API dependent hence their Unit testing becomes complex. 3) Struts allows only JSP technology in developing View-layer components.

4) Struts application Debugging is quite complex. 5) Struts gives no built-in AJAX support. (for asynchronous communication)

Note: In Struts 1.x, the form that comes on the Browser-Window can be displayed

under no control of F/W s/w & Action class.

26) What are the differences b/w struts, spring and hibernate?

Struts: allows to develop only webapplications and

it cant support POJO/POJI model programming.

Spring: is useful in developing all types of Java applications and

support POJO/POJI model programming. Hibernate: is used to develop DB independent persistence logic

It also supports POJO/POJI model programming.

27) What are differences b/w Servlets & Jsp?

Servlets:

i) It requires Recompilation and Reloading when we do modifications in a Servlet.(some servers) ii) Every Servlet must be configured in web.xml.

iii) It is providing less amount of implicit objects support.

iv) Since it consists both HTML & B.logic hence modification in one logic may disturbs

the other logic.

v) No implicit Exception Handling support.

vi) Since it requires strong Java knowledge hence non-java programmers shows no interest.

vii) Keeping HTML code in Servlets is quite complex.

JSP:

i) No need of Recompilation & Reloading when we do modifications in a JSP page.

ii) We need not to Configure a JSP in a web.xml.

iii) It is providing huge amount of Implicit Objects support.

iv) Since Html & Java code are separated hence no disturbance while changing logic.

v) It is providing implicit XML Exception Handling support.

vi) It is easy to learn & implement since it is tags based.

vii) It allows to develop custom tags.

viii) It gives JSTL support. (JSP Standard Tag Library(It provides more tags that will help to develop a JSP without using Java code).

ix) It gives all benefits of Servlets.

28) What is the difference b/w ActionServlet & Servlet?

ActionServlet: It is a predefined Singleton Java class and it traps all the requests

coming to Server. It acts as a Front-Controller in Struts 1.x.

Servlet: a Java class that extends HttpServlet/GenericServlet or implements Servlet interface and is a Server side technology to develop dynamic web pages. It is a Single instance multiple thread component. It need not be a Singleton Java class.29) What are Access Specifiers & modifiers?

i) public- ( Universal access specifier. --can be used along with: class, innerclass, Interface, variable, constructor, method.

ii) protectd ( Inherited access specifier. --can be used along with: innerclass, variable, method, constructor. iii) default ( Package access specifier(with in the package).

--can be used along with: class, innerclass, interface, variable, constructor, method. iv) private ( Native access specifier.

-- can be used along with: innerclass, variable, constructor, method.

( Some other access modifiers:

i) static------------innerclass,variable,block,method.

ii) abstract----- class,method.

iii) final--------------class,variable,method.

iv) synchronized---block,method.

v) transient---------variable.

vi) native-------------method.

vii) volatile-----------variableviii) strict fp-----------variable

30) Which JSP tag is used to display error validation? In Source page:

In Error page:

31) What are the roles of EJBContainer ?

An EJB container is the world in which an EJB bean lives. The container services requests from the EJB, forwards requests from the client to the EJB, and interacts with the EJB server.

The container provider must provide transaction support, security and persistence to beans.

It is also responsible for running the beans and for ensuring that the beans are protected from the outside world.

32) If double is added to String then what is the result? Double + String=String4.CrimsonLogic-Murugeshpalya-kemfort- 18-11-200933) What is Ant? What is its use

Ant is a tool that is used to build war, compilation, deploy.34) What is log4j? What is its functionality?

Log4j is a tool used to display logger messages on a file/console.

< appender name="FILE" class="org.apache.log4j.FileAppender">

logger.debug("Hi"); logger.info("Test Log");

logger.error()

Logger logger = Logger.getLogger(SampleLogtest.class);35) What are the functions of service()?

protected void service(HttpServletRequestreq,HttpServletResponseresp)

throws ServletException, java.io.IOExceptionReceives standard HTTP requests from the public service method and dispatches them to the doXXX methods defined in this class. This method is an HTTP-specific version of the

public void service(ServletRequestreq, ServletResponseres)

throws ServletException, java.io.IOException

Dispatches client requests to the protected service method. There's no need to override this method.36) How do we get the container related information?

By using ServletContext object.37) What is a Singleton Pattern?

is a design pattern that is used to restrict instantiation of a class to one object. class Single{

private static Single s=null;

private Single(){

------}

public static Single Factory(){

if(s==null)

return( new Single());

}

}

38) What are the functions of a Filter Servlet?

It traps all the requests & responses.

Container creates the Filter object when the web application is deployed.

39) How to compile a JSP page? Jasper tool-tomcat; Jspc tool--weblogic40) What is Hidden variable and give its snipplet HTML code?

41) How do you forward Servlet1 request to Servlet2?

ServletContext sc=getServletContext();

RequestDispatcher rd =sc.getRequestDispatcher(/s2url); // or html file name rd.forward(req,resp); (or) rd.include(req,resp);

5. Telephonic Interview: 23-11-2009.. MindTree42) differences b/w a Vector & a ArrayList?

ArrayListVector

1. One dimensional data structure

2. New Collections F/w class

3. Non-synchronized

4. SerializedDo

Legacy Collection F/W class

Synchronized

Non-serialized

43) try{ ----code for calling a not existed file---}

catch(Exception){--------}

catch(FileNotFoundException){-------}// for catch blocks no order significance. Which catch block will be executed?

Compile time Error comes.

44) types of Action classes?

Action(consists b.logic or logic that is there to communicate with other Model like EJB,

Spring..DispatchAction(an Action class used to group similar action classes having different methods. The name of the method will be coming in the request.

45) How do you print the missed salaries of employees? User table Salary table

user_id user_id;

user_name user-salary;

print user-id,user-name,user-sal; select user-id, user-name, user-sal from User us, Salary sal where us.user-id=sal.user-id.

46) What is IN, OUT, INOUT parameters? in, out, inout are the modes of the variables in PL/SQl. in is input variable mode.

out is output variable mode.

inout is in-out variable mode.

6. Date: 12-12-2009 Venue: NIIT technology, Silk Board, Begur Hobli, Hosur Main Road.

Bus:from RRNagar to BanShankari---225c. Banshankari to SilkBoard5001c

TECHNICAL ROUND: time: 1.30 pm to 2.45 pm47) How can you achieve Concurrence in Java? Using Multithreading48) How to implement Synchronization? Can we use synchronized with variables?

using the synchronized modifier along with the method or block. We cant synchronized a variable.

49) What classes are there in Spring Environment? Spring config.xml. spring bean class, spring bean interface.

50) What are the common files when 5 or more projects are developed using Hibernate ?

Configuration file

51) What are the differences b/w Struts 1.x & Struts 2.x?

7. Date: 18-12-2009. Time: 12.40 pm to 1.40 pm Consultancy: ABC Consultancy Bus: from majestic to Richmond Circle335e) Landmark: Near Cash Pharmacy 52) What are oop principles? Abstraction, polymorphism, inheritance, encapsulation 53) While overriding a exception throwing method, does it mandatory that subclass must

also throw the same exception? No 54) In an application, one task has to be done for every 15 minutes. How can you do it?

55) How do you sort on one property(field) of a class? Using Comparable Interface by overriding compareTo() method.

8. Date:19-12-2009 Company: HCL Technologies Ltd

56) If my class is having 5 abstract methods then can I make it as an interface?

Yes57) What is Log4j? Can I override the logger class?

58) Can I display logging messages on the console? Yes59) Which cvs tool are you using? What are the methods that are there?

Commit(). Update()

60) When I dont want to commit the ResultSet obj content, what to do? Con.setAutoCommit(false);

61) Can I call a procedure from a HB? How? Yes62) Can I use a big query in HB?63) Difference b/w Checked & Unchecked Exception? Checked Exceptions deal compile time exception regarding the existence of classes/interfaces

But not syntax errors.

Ex: ClassNotFoundException---when use a NULL referenced variable to call any

method/variable.

InterruptedException,---when two or more threads try to share same Resource(wait() and join())

NoSuchFieldException ---when we access the undeclared variable

NoSuchMethodException---when we invoke the undeclared method.

InstantiationException---when we try to create object for a abstract/interface

Unchecked Exceptions deal runtime errors.

Ex: ArithmeticException, ArrayOutOfBoundsException, NullPointerException64) Differenc b/w Exception & Error?

Date: 08-01-2010. Magna consultancy. 65) What is polymorphism? Poymorphism is the capability of an action/method to do different things based on an object that it is acting upon. One form, many implementations.

66) What is overloading and overriding? Give one example?

Overloading is the process of re-defining a method for multiple times with different Signature.

Overriding is a process of re-defining a super class original version

in its various derived classes through inheritance.67) What is encapsulation & abstraction?

Encapsulation is, a technique, used to encapsulate the properties & behaviors of an object.

It focuses on inside-view and solves problems at implementation side.

Abstraction refers to the act of representing essential features

without including the background details68) What is final ? class, method, variable.69) How can you invoke a current class constructor from a method ?

Using this.

70) How can you invoke a super class constructor from derived class?

Using super()

71) What is static? method, variable, block, static nested class72) What is instanceOf? The operator that checks whether given instance is belongs to the given class or not.

73) There are class A & class B. How can I get the members of class A & B?

74) Can I create an interface without methods, constants declarations?

Yes75) Can I place try & catch blocks in finally block? Yes76) What are the clone types?

77) How can you make an ArrayList as Synchronized list?

List lobj=Collections.synchronizedArrayList(new ArrayLsit());

Map m=Collections.synchronizedMap(new HashMap());

78) What is Serialization? Writing the state of an object in to Streams.

79) How can you made the fields of a class to not serialized?

Using the modifier called transient

80) What is the use with Generics? It avoids explicit type casting.

81) What is Reflection?

It allows to do Mirror image operations on classes/interfaces to get the internal details.82) How do you maintain versions in your project? Using SVN.83) What is Junit?

A tool for unit testing.

84) What is logging messages?

SQL

85) What is the difference b/w order by and group by? order by( used to arrange the data either in ascending or descending order.

group by( allows aggregation operations on a column .(having condition also).86) What are the relations? One to one

One to many

Many to one

Many to many.

87) What are the joins? Cursors, views, stored procedures.

Hibernate

88) Tell me few Hibernate interfaces? i) Configuration(c), ii) SessionFactory, iii) Session, iv) Transaction, v) Query89) How do you create Criteria?(to do select operations.) Criteria criteria=session.createCriteria(EmpBean.class);

// select * from Employee where eid between 100 and 200 and firstname in (raja,ramana));

Condition: 1

criteria=criteria.add(Expression.between(no,new Integer(100)),new Integer(200));

Condition: 2

criteria=criteria.add(Expression.in(fname,new String []{raja,ramana} )));

List l=ct.list(); // retrieves more selected records for(int x=0;x