Tuesday, July 30, 2013

spring interview questions

spring interview questions,spring interview questions,spring interview questions and answers in java,spring interview questions pdf,spring interview questions for experienced,spring interview questions and answers for experienced pdf,spring interview questions java,spring interview questions advanced,spring interview questions 2012,spring interview questions javarevisited,spring interview questions for 5 years experience

spring interview questions:

1. What is Bean Factory ?                                                          



A BeanFactory is like a factory class that contains a collection of beans. The BeanFactory holds Bean Definitions of multiple beans within itself and then instantiates the bean whenever asked for by clients. BeanFactory is able to create associations between collaborating objects as they are instantiated. This removes the burden of configuration from bean itself and the beans client. BeanFactory also takes part in the life cycle of a bean, making calls to custom initialization and destruction methods.


2. What is Application Context?

A bean factory is fine to simple applications, but to take advantage of the full power of the Spring framework, you may want to move up to Springs more advanced container, the application context. On the surface, an application context is same as a bean factory.Both load bean definitions, wire beans together, and dispense beans upon request. But it also provides: A means for resolving text messages, including support for internationalization. A generic way to load file resources. Events to beans that are registered as listeners.

3. What is the difference between Bean Factory and Application Context ?

On the surface, an application context is same as a bean factory. But application context offers much more.. Application contexts provide a means for resolving text messages, including support for i18n of those messages. Application contexts provide a generic way to load file resources, such as images. Application contexts can publish events to beans that are registered as listeners. Certain operations on the container or beans in the container, which have to be handled in a programmatic fashion with a bean factory, can be handled declaratively in an application context. ResourceLoader support: Spring’s Resource interface us a flexible generic abstraction for handling low-level resources. An application context itself is a ResourceLoader, Hence provides an application with access to deployment-specific Resource instances. MessageSource support: The application context implements MessageSource, an interface used to obtain localized messages, with the actual implementation being pluggable Open source and no vendor lock-in.

4. What are features of Spring ?

Lightweight: spring is lightweight when it comes to size and transparency. The basic version of spring framework is around 1MB. And the processing overhead is also very negligible. Inversion of control (IOC): Loose coupling is achieved in spring using the technique Inversion of Control. The objects give their dependencies instead of creating or looking for dependent objects. Aspect oriented (AOP): Spring supports Aspect oriented programming and enables cohesive development by separating application business logic from system services. Container: Spring contains and manages the life cycle and configuration of application objects. MVC Framework: Spring comes with MVC web application framework, built on core Spring functionality. This framework is highly configurable via strategy interfaces, and accommodates multiple view technologies like JSP, Velocity, Tiles, iText, and POI. But other frameworks can be easily used instead of Spring MVC Framework. Transaction Management: Spring framework provides a generic abstraction layer for transaction management. This allowing the developer to add the pluggable transaction managers, and making it easy to demarcate transactions without dealing with low-level issues. Spring's transaction support is not tied to J2EE environments and it can be also used in container less environments. JDBC Exception Handling: The JDBC abstraction layer of the Spring offers a meaningful exception hierarchy, which simplifies the error handling strategy. Integration with Hibernate, JDO, and iBATIS: Spring provides best Integration services with Hibernate, JDO and iBATIS

5. How many modules are there in Spring? What are they?
the spring contains exactly 6 moduls they are

(Roll over to view the Image ) Spring Framework Modules Spring comprises of seven modules. They are.. The core container: The core container provides the essential functionality of the Spring framework. A primary component of the core container is the BeanFactory, an implementation of the Factory pattern. The BeanFactory applies the Inversion of Control (IOC) pattern to separate an application's configuration and dependency specification from the actual application code. Spring context: The Spring context is a configuration file that provides context information to the Spring framework. The Spring context includes enterprise services such as JNDI, EJB, e-mail, internalization, validation, and scheduling functionality. Spring AOP: The Spring AOP module integrates aspect-oriented programming functionality directly into the Spring framework, through its configuration management feature. As a result you can easily AOP-enable any object managed by the Spring framework. The Spring AOP module provides transaction management services for objects in any Spring-based application. With Spring AOP you can incorporate declarative transaction management into your applications without relying on EJB components. Spring DAO: The Spring JDBC DAO abstraction layer offers a meaningful exception hierarchy for managing the exception handling and error messages thrown by different database vendors. The exception hierarchy simplifies error handling and greatly reduces the amount of exception code you need to write, such as opening and closing connections. Spring DAO's JDBC-oriented exceptions comply to its generic DAO exception hierarchy. Spring ORM: The Spring framework plugs into several ORM frameworks to provide its Object Relational tool, including JDO, Hibernate, and iBatis SQL Maps. All of these comply to Spring's generic transaction and DAO exception hierarchies. Spring Web module: The Web context module builds on top of the application context module, providing contexts for Web-based applications. As a result, the Spring framework supports integration with Jakarta Struts. The Web module also eases the tasks of handling multi-part requests and binding request parameters to domain objects. Spring MVC framework: The Model-View-Controller (MVC) framework is a full-featured MVC implementation for building Web applications. The MVC framework is highly configurable via strategy interfaces and accommodates numerous view technologies including JSP, Velocity, Tiles, iText, and POI. 8. What are the types of Dependency Injection Spring supports?> Setter Injection: Setter-based DI is realized by calling setter methods on your beans after invoking a no-argument constructor or no-argument static factory method to instantiate your bean. Constructor Injection: Constructor-based DI is realized by invoking a constructor with a number of arguments, each representing a collaborator.


8. What is IOC (or Dependency Injection)?


The basic concept of the Inversion of Control pattern (also known as dependency injection) is that you do not create your objects but describe how they should be created. You don't directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container (in the case of the Spring framework, the IOC container) is then responsible for hooking it all up. i.e., Applying IoC, objects are given their dependencies at creation time by some external entity that coordinates each object in the system. That is, dependencies are injected into objects. So, IoC means an inversion of responsibility with regard to how an object obtains references to collaborating objects.


9. What are the different types of IOC (dependency injection) ?

There are three types of dependency injection: Constructor Injection (e.g. Pico container, Spring etc): Dependencies are provided as constructor parameters. Setter Injection (e.g. Spring): Dependencies are assigned through JavaBeans properties (ex: setter methods). Interface Injection (e.g. Avalon): Injection is done through an interface. Note: Spring supports only Constructor and Setter Injection


10. What are the benefits of IOC (Dependency Injection)?


Benefits of IOC (Dependency Injection) are as follows: Minimizes the amount of code in your application. With IOC containers you do not care about how services are created and how you get references to the ones you need. You can also easily add additional services by adding a new constructor or a setter method with little or no extra configuration. Make your application more testable by not requiring any singletons or JNDI lookup mechanisms in your unit test cases. IOC containers make unit testing and switching implementations very easy by manually allowing you to inject your own objects into the object under test. Loose coupling is promoted with minimal effort and least intrusive mechanism. The factory design pattern is more intrusive because components or services need to be requested explicitly whereas in IOC the dependency is injected into requesting piece of code. Also some containers promote the design to interfaces not to implementations design concept by encouraging managed objects to implement a well-defined service interface of your own. IOC containers support eager instantiation and lazy loading of services. Containers also provide support for instantiation of managed objects, cyclical dependencies, life cycles management, and dependency resolution between managed objects etc.


11 What is IOC (or Dependency Injection)?

The basic concept of the Inversion of Control pattern (also known as dependency injection) is that you do not create your objects but describe how they should be created. You don't directly connect your components and services together in code but describe which services are needed by which components in a configuration file. A container (in the case of the Spring framework, the IOC container) is then responsible for hooking it all up. i.e., Applying IoC, objects are given their dependencies at creation time by some external entity that coordinates each object in the system. That is, dependencies are injected into objects. So, IoC means an inversion of responsibility with regard to how an object obtains references to collaborating objects.


12. What are the common implementations of the Application Context ?


The three commonly used implementation of 'Application Context' are ClassPathXmlApplicationContext : It Loads context definition from an XML file located in the classpath, treating context definitions as classpath resources. The application context is loaded from the application's classpath by using the code . ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml"); FileSystemXmlApplicationContext : It loads context definition from an XML file in the filesystem. The application context is loaded from the file system by using the code . ApplicationContext context = new FileSystemXmlApplicationContext("bean.xml"); XmlWebApplicationContext : It loads context definition from an XML file contained within a web application.


13. How is a typical spring implementation look like ?


For a typical Spring Application we need the following files: An interface that defines the functions. An Implementation that contains properties, its setter and getter methods, functions etc., Spring AOP (Aspect Oriented Programming) A XML file called Spring configuration file. Client program that uses the function.


14. What is the typical Bean life cycle in Spring Bean Factory Container ?

Bean life cycle in Spring Bean Factory Container is as follows: The spring container finds the bean’s definition from the XML file and instantiates the bean. Using the dependency injection, spring populates all of the properties as specified in the bean definition If the bean implements the BeanNameAware interface, the factory calls setBeanName() passing the bean’s ID. If the bean implements the BeanFactoryAware interface, the factory calls setBeanFactory(), passing an instance of itself. If there are any BeanPostProcessors associated with the bean, their post- ProcessBeforeInitialization() methods will be called. If an init-method is specified for the bean, it will be called. Finally, if there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() methods will be called.


15. What do you mean by Bean wiring ?

The act of creating associations between application components (beans) within the Spring container is reffered to as Bean wiring. 16. What do you mean by Auto Wiring? The Spring container is able to autowire relationships between collaborating beans. This means that it is possible to automatically let Spring resolve collaborators (other beans) for your bean by inspecting the contents of the BeanFactory. The autowiring functionality has five modes. no byName byType constructor autodirect

16. What is DelegatingVariableResolver?

Spring provides a custom JavaServer Faces VariableResolver implementation that extends the standard Java Server Faces managed beans mechanism which lets you use JSF and Spring together. This variable resolver is called as DelegatingVariableResolver

17. How to integrate Java Server Faces (JSF) with Spring?

JSF and Spring do share some of the same features, most noticeably in the area of IOC services. By declaring JSF managed-beans in the faces-config.xml configuration file, you allow the FacesServlet to instantiate that bean at startup. Your JSF pages have access to these beans and all of their properties.We can integrate JSF and Spring in two ways: DelegatingVariableResolver: Spring comes with a JSF variable resolver that lets you use JSF and Spring together. org.springframework.web.jsf.DelegatingVariableResolver The DelegatingVariableResolver will first delegate value lookups to the default resolver of the underlying JSF implementation, and then to Spring's 'business context' WebApplicationContext. This allows one to easily inject dependencies into one's JSF-managed beans. FacesContextUtils:custom VariableResolver works well when mapping one's properties to beans in faces-config.xml, but at times one may need to grab a bean explicitly. The FacesContextUtils class makes this easy. It is similar to WebApplicationContextUtils, except that it takes a FacesContext parameter rather than a ServletContext parameter. ApplicationContext ctx = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance())

18. What is Significance of JSF- Spring integration ?

Spring - JSF integration is useful when an event handler wishes to explicitly invoke the bean factory to create beans on demand, such as a bean that encapsulates the business logic to be performed when a submit button is pressed.

19. How to integrate your Struts application with Spring?

To integrate your Struts application with Spring, we have two options: Configure Spring to manage your Actions as beans, using the ContextLoaderPlugin, and set their dependencies in a Spring context file. Subclass Spring's ActionSupport classes and grab your Spring-managed beans explicitly using a getWebApplicationContext() method.

 

Tuesday, July 16, 2013

core java basic interview questions and answers

CORE JAVA BASIC INTERVIEW QUESTIONS AND ANSWERS,core java basic interview questions and answers pdf,core java basic interview questions and answers,basic core java interview questions and answers for freshers,basic core java interview questions and answers for freshers pdf,core java interview questions and answers,core java interview questions and answers for experienced,core java interview questions and answers pdf,core java interview questions and answers for freshers,core java interview questions and answers for experienced pdf,core java interview questions and answers for freshers pdf.
core java basic interview questions and answers:

1. What do you mean by platform independence?
Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (Linux,Solaris,etc).This is basic core java interview questions.
3. What is a JVM?
JVM is an acronym for Java Virtual Machine ,Its is an abstract machine which provides the runtime environment in which java bytecode can be executed.JVMs(Java Virtual Machine) are available for many hardware and software platforms(so JVM is platform dependent)
4. Are JVM's platform independent?
JVM's are not platform independent. JVM's are platform specific run time implementation provided by the vendor.
5. What is the difference between a JDK and a JVM?
JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.
6. What is a pointer and does Java support pointers?
Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn't support the usage of pointers.
7. What is the base class of all classes?
java.lang.Object
8. Does Java support multiple inheritance?
Java doesn't support multiple inheritance.
9. Is Java a pure object oriented language?
Java uses primitive data types and hence is not a pure object oriented language. 10. Are arrays primitive data types? In Java, Arrays are objects.
11. What is difference between Path and Classpath?
Path and Classpath are operating system level environment variales. Path is used define where the system can find the executables(.exe) files and classpath is used to specify the location .class files.
12. What are local variables?
Local varaiables are those which are declared within a block of code like methods. Local variables should be initialised before accessing them.
13. What are instance variables?
Instance variables are those which are defined at the class level. Instance variables need not be initialized before using them as they are automatically initialized to their default values.
14. How to define a constant variable in Java?
The variable should be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed also. static final int PI = 2.14; is an example for constant.
15. Should a main() method be compulsorily declared in all java classes?
No not required. main() method should be defined only if the source class is a java application.
16. What is the return type of the main() method?
Main() method doesn't return anything hence declared void.
17. Why is the main() method declared static?
main() method is called by the JVM even before the instantiation of the class hence it is declared as static.
18. What is the arguement of main() method?
main() method accepts an array of String object as arguement.
19. Can a main() method be overloaded?
Yes. You can have any number of main() methods with different method signature and implementation in the class.
20. Can a main() method be declared final?
Yes. Any inheriting class will not be able to have it's own default main() method.
21. Does the order of public and static declaration matter in main() method?
No. It doesn't matter but void should always come before main().
22. Can a source file contain more than one class declaration?
Yes a single source file can contain any number of Class declarations but only one of the class can be declared as public.
23. What is a package?
Package is a collection of related classes and interfaces. package declaration should be first statement in a java class.
24. Which package is imported by default?
java.lang package is imported by default even without a package declaration.
25. Can a class declared as private be accessed outside it's package?
Not possible.
26. Can a class be declared as protected?
A class can't be declared as protected. only methods can be declared as protected.

27. What is the access scope of a protected method?
A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package.
28. What is the purpose of declaring a variable as final?
A final variable's value can't be changed. final variables should be initialized before using them.
29. What is the impact of declaring a method as final?
A method declared as final can't be overridden. A sub-class can't have the same method signature with a different implementation.
30. I don't want my class to be inherited by any other class. What should i do?
You should declared your class as final. But you can't define your class as final, if it is an abstract class. A class declared as final can't be extended by any other class.
31.Why wait and notify is declared in Object class instead of Thread ?
Another tough java question, how can you answer this question if you are not designed Java programming language. anyway some common sense and deep knowledge of Java programming helps to answer such tough core java interview question. See this blog post to learn Why wait and notify is declared in Object class and not in Thread.
32.Why multiple inheritance is not supported in Java ?
I found this core Java question really tough to answer because your answer may not satisfy Interviewer, in most cases Interviewer is looking for specific points and if you can bring them, they would be happy. Key to answer this kind of tough question in Java is to prepare topic well to accommodate any follow-ups.
33.Why Java does not support operator overloading ?
One more similar category of tough Java question. C++ supports operator overloading than why not Java? this is the argument Interviewer will give to you and some time even say that + operator is overloaded in Java for String concatenation, Don't be fooled with such arguments.
34.Why String is immutable in Java?
My favorite Java interview question, this is tough, tricky but same time very useful as well. Some interviewer also ask this question as Why String is final in Java. look at this post for some points which make sense on Why String is final or immutable in Java
35.Why char array is preferred to store password than String in Java?
Another tricky Java question which is based on String and believe me there are only few Java programmer which can answer this question correctly. This is a real tough core Java interview question and again solid knowledge of String is required to answer this.
36.How to create thread-safe singleton in Java using double checked locking?
This Java question is also asked as What is thread-safe singleton and how to do you write it. Well Singleton created with double checked locking before Java 5 was broker and its possible to have multiple instance of Singleton if multiple thread try to create instance of Singleton at same time. from Java 5 its easy to create thread safe Singleton using Enum. but if interviewer persist with double checked locking then you have to write that code for them. remember to use volatile variable. See 10 Java singleton interview question for more details on this topic.
37.Write Java program to create deadlock in Java and fix it ?
One of the classical but tough core Java interview question and you are likely to fail if you have not involved in coding of multi-threaded concurrent Java application.
38.What happens if your Serializable class contains a member which is not serializable?
How do you fix it? Any attempt to Serialize that class will fail with NotSerializableException, but this can be easily solved by making that variable transient for static in Java. See Top 10 Serialization interview question answers in Java for more details.
39.Why wait and notify called from synchronized method in Java?
Another tough core Java question for wait and notify. They are called from synchronized method or synchronized blockbecause wait and modify need monitor on Object on which wait or notify get called.
40.Can you override static method in Java?
if I create same method in subclass is it compile time error? No you can not override static method in Java but its not a compile time error to declare exactly same method in sub class, That is called method hiding in Java.
41. How could Java classes direct program messages to the system console, but error messages, say to a file?
The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed: Stream st = new Stream (new FileOutputStream (“techinterviews_com.txt”)); System.setErr(st); System.setOut(st);
42. What’s the difference between an interface and an abstract class?
An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.
43. Why would you use a synchronized block vs. synchronized method?
Synchronized blocks place locks for shorter periods than synchronized methods.
44. Explain the usage of the keyword transient?
This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).
45. How can you force garbage collection?
You can’t force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.
46. How do you know if an explicit object casting is needed?
If you assign a superclass object to a variable of a subclass’s data type, you need to do explicit casting. For example: Object a;Customer b; b = (Customer) a; When you assign a subclass to a variable having a supeclass type, the casting is performed automatically.
47. What’s the difference between the methods sleep() and wait()?
The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.
48. Can you write a Java class that could be used both as an applet as well as an application?
Yes. Add a main() method to the applet.
49. What’s the difference between constructors and other methods?
Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.
50. Can you call one constructor from another if a class has multiple constructors?
Yes. Use this() syntax.
51. Explain the usage of Java packages?
This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes.
52. If a class is located in a package, what do you need to change in the OS environment to be able to use it?
You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let’s say a class Employee belongs to a package com.xyz.hr; and is located in the file c:/dev/com.xyz.hr.Employee.java. In this case, you’d need to add c:/dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows: c:>java com.xyz.hr.Employee.
53. What’s the difference between J2SDK 1.5 and J2SDK 5.0?
There’s no difference, Sun Microsystems just re-branded this version.
54. What would you use to compare two String variables – the operator == or the method equals()?
I’d use the method equals() to compare the values of the Strings and the = = to check if two variables point at the same instance of a String object
55. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?
Yes, it does. The FileNoFoundException is inherited from the IOException. Exception’s subclasses have to be caught first.
56. Can an inner class declared inside of a method access local variables of this method?
It’s possible if these variables are final.
57. What can go wrong if you replace && with & in the following code: String a=null; if (a!=null && a.length()>10) {…} A single ampersand here would lead to a NullPointerException.
58. What’s the main difference between a Vector and an ArrayList?
Java Vector class is internally synchronized and ArrayList is not.
59. When should the method invokeLater()be used?
This method is used to ensure that Swing components are updated through the event-dispatching thread.
60. How can a subclass call a method or a constructor defined in a superclass?
Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass’s constructor.
61. What’s the difference between a queue and a stack?
Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule.
62. You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces?
Sometimes. But your class may be a descendant of another class and in this case the interface is your only option.
63. What comes to mind when you hear about a young generation in Java?
Garbage collection.
64. What comes to mind when someone mentions a shallow copy in Java?
Object cloning.
65. If you’re overriding the method equals() of an object, which other method you might also consider?
hashCode()
66. You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use: ArrayList or LinkedList?
ArrayList
67. How would you make a copy of an entire Java object with its state?
Have this class implement Cloneable interface and call its method clone().
68. How can you minimize the need of garbage collection and make the memory use more effective?
Use object pooling and weak object references.
69. There are two classes: A and B. The class B need to inform a class A when some important event has happened. What Java technique would you use to implement it?
If these classes are threads I’d consider notify() or notifyAll(). For regular classes you can use the Observer interface.
70. What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it?
You do not need to specify any access level, and Java will use a default package access level.

Sunday, July 14, 2013

Java Language Interview Question and Answers

Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,
Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,
Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers,Java Language Interview Question and Answers

Java Language Interview Question and Answers:


1. What is an abstract class?

  Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. An abstract class can contain no abstract methods also i.e. abstract class may contain concrete methods.
2. what are class variables?

  Class variables are global to a class and belong to the entire set of objects that class creates. Only one memory location is created for each variable.3.
3. What is the Collection interface?

  The Collection interface provides support for the implementation of a mathematical bag - an unordered collection of objects that may contain duplicates.
4. What must a class do to implement an interface?

  The class must provide all of the methods in the interface and identify the interface in its implements clause.
5. What is the Collections API?

  The Collections API is a set of classes and interfaces that support operations on collections of objects.
6. What is an array?

  Array is a group of related data items that share a common name.For instance, we can define an array name salary to represent a set of salaries of a group of employees.
Examples : salary[10]
7. What is a list iterator?

  The List and Set collections provide iterators, which are objects that allow going over all the elements of a collection in sequence. The java.util.Iterator interface provides for one-way traversal and java.util.ListIterator is an iterator for lists that allows the programmer to traverse the list in either direction (i.e. forward and or backward) and modify the list during iteration.

8 What is the main difference between a String and a StringBuffer class?

  String is immutable : you can’t modify a string object but can replace it by creating a new instance. Creating a new instance is rather expensive.

StringBuffer is mutable : use StringBuffer or StringBuilder when you want to modify the contents. StringBuilder was added in Java 5 and it is identical in all respects to StringBuffer except that it is not synchronized,which makes it slightly faster at the cost of not being thread-safe.

9. When to use serialization?

  A common use of serialization is to use it to send an object over the network or if the state of an object needs to be persisted to a flat file or a database.

10. What is the main difference between shallow cloning and deep cloning of objects?

  Java supports shallow cloning of objects by default when a class implements the java.lang.Cloneable interface.
Deep cloning through serialization is faster to develop and easier to maintain but carries a performance overhead.

21. What are wrapper classes?

  primitive data types may be converted into object types by using the wrapper classes contained in the java.lang package.
Exampes : int, float, long, char, double

11. What is the difference between an instance variable and a static variable?

  Class variables are called static variables. There is only one occurrence of a class variable per JVM per class loader.When a class is loaded the class variables are initialized.
Instance variables are non-static and there is one occurrence of an instance variable in each class instance.Also known as a member variable or a field.

12 Where and how can you use a private constructor?

  Private constructor is used if you do not want other classes to instantiate the object and to prevent subclassing.The instantiation is done by a public static method (i.e. a static factory method) within the same class.

13. What is type casting?

  Type casting means treating a variable of one type as though it is another type.
Examples :
int m = 5;
byte n =i;

14. What is a user defined exception?

  User defined exceptions may be implemented by defining a new exception class by extending the Exception class.


15. What is an instanceof operator?

  Instanceof is an object reference operator and returns true if the object on the left-hand side is an instance of the glass given to the right hand side.This operator allows to determine whether the object belongs to a particular class or not.

16. What are runtime exceptions?

  Runtime exceptions are those exceptions that are thrown at runtime because of either wrong input data or because of wrong business logic etc. These are not checked by the compiler at compile time.


17 What is the difference between an interface and an abstract class?

  An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.

18. what is a package?

  A package is a namespace that organizes a set of related classes and interfaces.The classes contained in the packages of other programs can be easily reused.Packages, classes can be unique compared with classes in other packages.That is, two classes in two different packages can have the same name.


20. Why do threads block on I/O?

  Threads block on i/o (that is enters the waiting state) so that other threads may execute while the i/o Operation is performed.


21. What is the List interface?

  The List interface provides support for ordered collections of objects.


22. What is the Vector class?

  The Vector class provides the capability to implement a growable array of objects.

23 What is the base class of all classes?

  java.lang.Object

24 What is the importance of static variable?

  static variables are class level variables where all objects of the class refer to the same variable. If one object changes the value then the change gets reflected in all the objects.

25. What is the difference between a while statement and a do while statement?

  A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do while statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do whilestatement will always execute the body of a loop at least once.

Saturday, July 6, 2013

java interview questions and answers for experienced

java interview questions  for experienced and answers,java interview questions for 4 years experience and answers,java interview questions for 5 years experience and answers,java interview questions for 3 years experience and answer,java experienced interview questions and answers,java experience interview questions and answers,java experience interview questions and answers pdf,java interview questions and answers for experienced j2ee,java interview questions and answers for experienced pdf,java interview questions and answers for experienced pdf core,java interview questions and answers for experienced free download

java interview questions  for experienced and answers:                         


Java Language Interview Question and Answers

1. What is an abstract class?
  Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. An abstract class can contain no abstract methods also i.e. abstract class may contain concrete methods.
2. what are class variables?
  Class variables are global to a class and belong to the entire set of objects that class creates. Only one memory location is created for each variable.
3. What is the Collection interface?
  The Collection interface provides support for the implementation of a mathematical bag - an unordered collection of objects that may contain duplicates.
4. What must a class do to implement an interface?
  The class must provide all of the methods in the interface and identify the interface in its implements clause.
5. What is the Collections API?
  The Collections API is a set of classes and interfaces that support operations on collections of objects.

Friday, July 5, 2013

java interview questions and answers for experienced

java interview questions and answers for experienced,java interview questions and answers for experienced,java interview questions and answers for experienced candidates,java interview questions and answers for experienced pdf,java interview questions and answers for experienced j2ee,java interview questions and answers for experienced pdf core,java interview questions and answers for experienced free download,java interview questions and answers for experienced people,java interview questions and answers for experience,java swing interview questions and answers for experienced,java collections interview questions and answers for experienced

java interview questions and answers for experienced:


1. What is Java?
A.high-level programming language developed by Sun Microsystems. Java was originally called OAK, and was designed for handheld devices and set-top boxes. Oak was unsuccessful so in 1995 Sun changed the name to Java and modified the language to take advantage of the burgeoning World Wide Web.

2. what are the main features of java?
The main features of java are
Compiled and Interpreted
Object oriented
Robust and secure
Type safe
High Performance.

3. What are pass by reference and passby value?
Pass By Reference means the passing the address itself rather than passing the value. Passby Value means passing a copy of the value to be passed.

 4. What is the Java API? 
 The Java API is a large collection of ready-made software components that provide many useful capabilities, such as graphical user interface (GUI) widgets.

5. What is the Java Virtual Machine (JVM)? 
The Java Virtual Machine is software that can be ported onto various hardware-based platforms.

6. What is variables and then types?
Variables is an identifier that denotes a storage location used to store a data values.unlike constants that remain unchanged during the execution of a program, a variable may takes different values at different times during the execution of the program. Instance variables Class variables Local variable Parameters

7. what is dot operator?
The dot operator(.) is used to access the instance variables and methods of class objects.It is also used to access classes and sub-packages from a package. Examples : Person1.age ---------> Reference to the variable age

8. Define strings?
Strings represent a sequence of characters.The easiest way to represent a sequence of characters in java is by using a character array.

9. What is serialization?
Serialization is the process of converting a objects into a stream of bytes.


10. What are different types of access modifiers?
Access specifiers are keywords that determine the type of access to the member a class. Public Protected Private Default