Search Interview Questions | Click here and help us by providing the answer. Click Correct / Improve and please let us know. |
|
|||
|
| ||||
| Interview Questions and Answers - Order By Rating | ||||
| ||||
| Ans. string and wrapper class objects | ||||
| ||||
| Ans. Prototype scope - A new object is created each time it is injected/looked up. It will use new SomeClass() each time. Singleton scope - It is the default scope. The same object is returned each time it is injected/looked up. Here it will instantiate one instance of SomeClass and then return it each time. | ||||
| ||||
| Ans. Generics are a facility of generic programming that were added to the Java programming language in 2004 within J2SE5.0. They allow "a type or method to operate on objects of various types while providing compile-time type safety. | ||||
| ||||
| Ans. int arr[]={1,3,5,6,4,8,9,2,10}; Arrays.sort(); System.out.println(arr[arr.length-1]); | ||||
| ||||
| Ans. LocalDate today = LocalDate.now(); LocalDate birthday = LocalDate.of(1960, Month.JANUARY, 1); Period p = Period.between(birthday, today); //Now access the values as below System.out.println(period.getDays()); System.out.println(period.getMonths()); System.out.println(period.getYears()); | ||||
| ||||
| Ans. 1. In Setter Injection, partial injection of dependencies can possible, means if we have 3 dependencies like int, string, long, then its not necessary to inject all values if we use setter injection. If you are not inject it will takes default values for those primitives1. In constructor injection, partial injection of dependencies cannot possible, because for calling constructor we must pass all the arguments right, if not so we may get error 2. Setter Injection will overrides the constructor injection value, provided if we write setter and constructor injection for the same property [i already told regarding this, hope you remember ] But, constructor injection cannot overrides the setter injected values 3. If we have more dependencies for example 15 to 20 are there in our bean class then, in this case setter injection is not recommended as we need to write almost 20 setters right, bean length will increase. In this case, Constructor injection is highly recommended, as we can inject all the dependencies with in 3 to 4 lines [i mean, by calling one constructor] 4. Setter injection makes bean class object as mutable [We can change ] .Constructor injection makes bean class object as immutable [We cannot change ] | ||||
| ||||
| Ans. OOPs or Object Oriented Programming is a Programming model which is organized around Objects instead of processes. Instead of a process calling series of processes, this model stresses on communication between objects. Objects that all self sustained, provide security by encapsulating it's members and providing abstracted interfaces over the functions it performs. OOP's facilitate the following features 1. Inheritance for Code Reuse 2. Abstraction for modularity, maintenance and agility 3. Encapsulation for security and protection 4. Polymorphism for flexibility and interfacing | ||||
| ||||
| Ans. Amazon Elastic Compute Cloud or EC2 provides scalable computing capacity in the AWS cloud. It can be used to create Virtual Environments , storage and configure. EC2 enables to upgrade or downgrade infrastructure according to the rules defined ( with fluctuation in latency, traffic etc ) | ||||
| ||||
| ||||
| Ans. synchronized is a keyword and a modifier. The synchronized keyword is used to indicate that a method can be accessed exclusively by one thread at a time. | ||||
| ||||
| Ans. Constructors are used to initialize the state of an object. If there are no constructor , objects won't have any initialized state and hence it's elements may contain garbage values. If the memory were used as is, the behavior of the object would also be unpredictable. | ||||
| ||||
| Ans. First Find the number of nodes in the linked list and take it as n.then find the data at n-3 element. | ||||
| ||||
| ||||
| Ans. We can merge two sorted array by using quick sort algorithm | ||||
| ||||
| Ans. Garbage collection mechanism frees up the memory that is no longer needed. In languages like C / C++ the deallocation needs to be done explicitly by the programmer and hence any leniency may result in memory leak. Garbage collection in java ensures that all unused memory is reclaimed and hence there are no memory leaks.Moreover it relieves the programmer from the hassle of carefully releasing all memory. | ||||
| ||||
| Ans. Number 1 - Fill the 5 litre can from the tap Empty the 5 litre can into the 3 litre can leaving 2 litres in the 5 litre can. Pour away the contents of the 3 litre can.Fill the 3 litre can with the 2 litres from the 5 litre can leaving 2 litres in the 3 litre can. Fill the 5 litre can from the tap.Fill the remaining 1 litre space in the 3 litre can from the 5 litre can.Leaving 4 litres in the 5 litre can. Number 2 - Fill the 3 litre can from the tap.Empty the contents of the 3 litre can into the 5 litre can. Fill the 3 litre can from the tap.Empty the contents of the 3 litre can into the 5 litre can leaving the 5 litre can full and 1 litre in the 3 litre can. Pour away the contents of the 5 litre can. Pour the 1 litre from the 3 litre can into the 5 litre can. Fill the 3 litre can from the tap. Empty the contents of the 3 litre can into the 5 litre can leaving 4 litres in the 5 litre can. | ||||
| ||||
| Ans. Through common memory area. | ||||
| ||||
| Ans. import java.util.*; class LinkedListSolution{ protected LinkedList list; public LinkedListSolution(){ list = new LinkedList(); } public Object pop() throws NoSuchElementException{ if(list.isEmpty()) throw new NoSuchElementException(); else return list.removeFirst(); } public void push(Object obj){ list.addFirst(obj); } public Object peek() throws NoSuchElementException{ if(list.isEmpty()) throw new NoSuchElementException(); else return list.getFirst(); } public boolean isEmpty(){ return list.isEmpty(); } public String toString(){ return list.toString(); } } class TestStack{ public static void main(String args[]){ LinkedListSolution s = new LinkedListSolution(); s.push("First"); s.push("Second"); s.push("Third"); System.out.println("Top: " s.peek()); s.push("Fourth"); while(!(s.isEmpty())) System.out.println(s.pop()); } } | ||||
| ||||
| ||||
| Ans. Execution engine contains interpreter and JIT compiler, which covert byte code into machine code. | ||||
| ||||
| Ans. Amazon Simple Storage Service or S3 is object storage with a simple web service interface to store and retrieve any amount of data from anywhere on the web. | ||||
| ||||
| Ans. Abstraction, Encapsulation, Polymorphism , Composition and Inheritance | ||||
| ||||
| Ans. Core: [Core, Bean, Context, Expression Language] Web: [Web, Portlet, Servlet, etc] Data Access [JMS, JDBC, etc] AOP, Aspect | ||||
| ||||
| Ans. Selenium WebDriver is a tool for automating web application testing.It helps in replicating the manual tester behavior like keyboard entry, mouse events etc and then matching the output against the expected. | ||||
| ||||
| Ans. public class BuggyBread { public static void main(String args[]) { System.out.println(factorial(5)); } private static int factorial(int number){ if(number == 1){ return 1; } else { return number * factorial(number - 1); } } } | ||||
| ||||
| Ans. public class BuggyBread { public static void main(String args[]) { String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit"; Set<String> words = new HashSet(); for(String word:str.split(" ")){ if(words.contains(word)){ System.out.println(word); } else { words.add(word); } } } } | ||||
| ||||
| Ans. boolean byte char double float int long short void | ||||
| ||||
| Ans. class A { public void test() { System.out.println("Class A Test"); } } class B extends A { public void test() { System.out.println("Class B Test"); } public static void main(String[] args){ A a = new B(); a.test(); // will print Class B Test } } | ||||
| ||||
| Ans. class A { public void test() { System.out.println("Class A Test"); } } class B extends A { public void test() { System.out.println("Class B Test"); } } | ||||
| ||||
| Ans. public class BuggyBread { public static void main(String args[]) { Map<Character, Integer> countMap = new HashMap(); String str = "hello world"; for (char character : str.toCharArray()) { if (countMap.containsKey(character)) { countMap.put(character, countMap.get(character) + 1); } else { countMap.put(character, 1); } } System.out.println(countMap); } } | ||||