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. JDBC is a standard Java Api for Database communication whereas Hibernate is an ORM framework that uses JDBC to connect with Database. Hibernate is another layer of object table mapping over JDBC that provide a database independent, object oriented and an efficient way of database communication. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. https://medium.com/javarevisited/internal-working-of-hashmap-in-java-97aeac3c7beb#:~:text=HashMap%20internally%20uses%20HashTable%20implementation,the%20entries%20into%20the%20map. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Yes, we can do that. Compiler wont complain. But using object reference we can only access methods which have been defined for object class i.e clone(), equals(), hashCode(), toString() etc. We cannot access methods defined in String class or in any class in hierarchy between String and Object. For example - we cannot do obj.append("abc") as it will now give compile time error. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. [Open Ended Answer] | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. int findMax(int[] items){ int maxNumber = 0; for(int x:items){ if(x > maxNumber){ maxNumber = x; } } return maxNumber; } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. [Open Ended Answer] Usually answered stating your keen interest in the role offered and challenges and opportunities the role offers. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. 1. Static class is a class which cannot be instantiated and all its members are static whereas Singleton is the class that only permit creation of single object and then the object is reused. 2. As there is no object in Static class, it cannot participate in runtime Polymorphism. 3. As Static class doesnt allow creating objects and hence it cannot be serialized. 4. Static class body is initialized eagerly at application load time whereas Singleton object can be initiated eagerly using static blocks or lazily on first need. 5. Its not recommended to use pure static class as it fails to use many OOPs concepts. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. public void checkIfAnagram(String str1,String str2){ boolean anagram = true; for(char c:str1.toCharArray()){ if(!str2.contains(String.valueOf(c))){ System.out.println("Strings are Anagrams"); anagram = false; } if(anagram == true){ System.out.println("Strings are not Anagrams"); } } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. public class TotalUsingThreads extends Thread{ private static List<TotalUsingThreads> collector = new ArrayList<TotalUsingThreads>(); private int startFrom = 0; private Integer threadTotal = null; Test(int startFrom){ this.startFrom = startFrom; } public static void main(String[] args) throws InterruptedException{ int totalSum = 0; // Create all the threads and set the count starting point for all of them for(int count=0;count<10;count++){ TotalUsingThreads newThread = new TotalUsingThreads(count*100); newThread.start(); collector.add(newThread); } boolean allCollected = false; // Make sure that all thread totals are collected and all threads have completed their tasks while(!allCollected){ for(int count=0;count<10;count++){ if(collector.get(count).threadTotal == null){ Thread.sleep(100); break; } } allCollected = true; } // sum totals of all threads for(int count=0;count<10;count++){ totalSum += collector.get(count).threadTotal; } System.out.println(totalSum); } public void run(){ threadTotal = 0; for(int count=startFrom;count<startFrom+100;count++){ threadTotal += count; } } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. No. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Reliability and Continuity if some of the sites goes down.Easy Scaling up and Down as sites can be added or removed without impacting business continuity. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. https://en.wikipedia.org/wiki/Agile_software_development | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. [Open Ended Answer] This is a very sensitive question and should be dealt with caution. Just simply saying that you never had any disagreement will present you as dumb team member. Showing your self as too aggressive in such decisions will present you as a trouble maker. You should present a situation where you had an argument / disagreement but eventually you and your team mates mutually found a way out of it. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. String class is immutable as well as final. Because of these properties , String objects offer many benefits 1. String Pool - When a string is created and if it exists in the pool, the reference of the existing string will be returned instead of creating a new object. If string is not immutable, changing the string with one reference will lead to the wrong value for the other references. Example - String str1 = "String1"; String str2 = "String1"; // It doesnt create a new String and rather reuses the string literal from pool // Now both str1 and str2 pointing to same string object in pool, changing str1 will change it for str2 too 2. To Cache its Hashcode - If string is not immutable, One can change its hashcode and hence its not fit to be cached. 3. Security - String is widely used as parameter for many java classes, e.g. network connection, opening files, etc. Making it mutable might possess threats due to interception by the other code segment. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Please not that all such questions can be easily answered through recursion. Simple recursive implementation could be traverse(root); void traverse(Element element){ if(element.hasNext()){ traverse(element.next()); } else { System.out.println(element); } } but this algo / code lead to endless loop if there is a loop in graph traversal. So you can keep a collection to keep track of which elements have laready been traversed static List<Elements> listOfAlreadyTraversedElements = new ArrayList<Elements>(); main(){ traverse(root); } void traverse(Element element){ if(element.hasNext()){ traverse(element.next()); } else { listOfAlreadyTraversedElements.add(element); System.out.println(element); } } | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. No we cannot start the same thread twice. Each thread has a lifecycle. But Yes, we can run the same code in parallel using different threads. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Shutdown hook is a thread that is invoked implicitly by JVM just before the shut down. It is used to clean up unused resources. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. .classpath specifies the source java and resource folders that are used by Builders to build. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. .project is a project description file that helps plugins and eclipse understand about the project - organization of projects , their names, builders used by them etc. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. It means that the respective folder is not looked upon by Java to look for java or resource files and hence not being included as part of build.It needs to be added to Java Build Path. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Maven Module has a Parent whereas Project doesnt. when we add the parent section to the pom file, it adds the module section to the parent project pom file. When we execute mvn compile / install, it basically checks that module section of the parent to identify all the modules that needs to be compiled first. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. session.createCriteria(Employee.class).add( Restrictions.or(Restrictions.like("name", "A%"),Restrictions.like("name", "B%"))).list(); | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. 1. HashSet doesnt maintain its elements in any specific order and is all random whereas TreeSet maintains elements in natural order 9 order defined by the equals method of TreeSet element type ) 2. TreeSet doesnt allow null elements whereas HashMap does. 3. As TreeSet orders elements and is hence insertion is comparatively slower. 4. HashSet performs basic operations like add(), remove(), contains(), size() etc. in a constant size time. A TreeSet performs these operations at the order of log(n) time. 5. HashMap in Java internally backs a HashSet. A NavigableMap backs a TreeSet internally. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. It make sense if its returning something. It doesnt make sense for void methods where return statement is not preceded by anything. In case of void methods , return as last statement has no impact and is actually a overhead. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Such return is only expected in methods that returns void. the purpose of having return in such a method is to return the flow out of method and return to the place where it was called. Its actually used to prematurely return the control from the method. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. println prints an additional end of line whereas printf doesnt. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. System is a class within java.lang package that contains several useful class fields and methods. It cannot be instantiated and hence can use only statically.even in this case this has been used statically i.e with class name itself and without creating an instance. out is the static reference of Printstream declared as following in the System Class - public final static PrintStream out = null; println is the method of PrintStream class. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Spliterator has better performance potential than iterators but only if the potential is used. Spliterator can iterate streams in parallel as well as in sequence whereas iterator can only iterate in sequence. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Though there are many differences the way internally they both iterates the collections and streams respectively, but the main difference in performance that is achieved by spliterator as it can iterate Streams in Parallel whereas iterator only iterates collections sequentially. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. http://www.programmingsimplified.com/java/source-code/java-program-armstrong-number | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
![]() ![]() | ||||