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 Newest | ||||
![]() ![]() | ||||
| ||||
Ans. String s1 = "akhilesh"; char[] ch = s1.toCharArray(); for (int i = ch.length-1 ; i >=0 ; i--) { System.out.print(ch[i]); } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. LinkedList maintains the insertion order in collection. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. private void permutation(String prefix, String sufix) { int ln = sufix.length(); if(ln == 0) { System.out.println(prefix); } else { IntStream.range(0, ln).forEach(i->permutation(prefix sufix.charAt(i), sufix.substring(0,i) sufix.substring(i 1, ln))); } } call:permutation("", "abcdef"); | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Java could design it in such a manner but would result in ambiguity if there are multiple files with the same name. The only way to get over it to show the message when you use any such class to provide explicit import with the package prefix. The other problem could be that Java might have to change the early import to Late import and check what's being used to decide what needs to be imported as otherwise you will see errors regarding the ambiguous imports with duplicate file name. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Encapsulation facilitate hiding and restricted access and hence more of a security feature. Encapsulation is definitely a great feature as when applications expand criss cross communication between objects / modules could lead to blunders. Inheritance facilitates code reuse. Polymorphism comprise of method overloaded ( which to me is negligible usage ) and method overriding. Method overriding is of great usage as it facilitates concept of interfaces and plugin development. So it’s Security / Organization vs Code Reuse / Support for other features like overriding vs Contracts / Plugin Development facilitating the creation of frameworks / libraries. Which is more important may vary from application to application , its scale , its use , its sensitivity etc. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. No. The whole idea of default method is to provide a default definition in case the implementing class intend to provide definition for only some of the methods. Making any of the interface method private would restrict it from being implemented by the implementing class. So default method is an option to provide implementation and not restricting a new definition. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. There are different types of relationship between classes Inheritance - Also called is-a relationship, Child class object carries the body of the Parent class when initiated. Moreover there are certain privileges attach to method overriding to the classes related this way. This relationship exist for code reuse, method overriding and interfacing ( through abstract class ). Composition - Also called has-a relationship. Class objects carries a reference to other class objects when instantiated. This relationship exist for work flow / work delegation. Inner / Nested class - It’s a relationship that encapsulates the inner class or it’s object within the outer class. This relationship exist for encapsulation / security. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. public int fibonacci(int n) { if(n == 0) return 0; else if(n == 1) return 1; else return fibonacci(n - 1) fibonacci(n - 2); } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. 1. The problem with double (x*100)/100 doesn't return exact x but few fractions lesser than x and then if you are using floor rounding , it makes a big difference 2. Rounding only after getting a result vs rounding each outcome of 2 operand make difference 3. Usage of inappropriate Rounding mode and Rounding scale. 4. Results with double and BigDecimal | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. No | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Yes, to a certain extent. But the objective for Final class could be beyond just enforcing composition as certain classes might have been created without inheritance or composition in mind. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. 1. Enforcing composition over inheritance 2. Restricting overriding of certain methods 3. Final methods are faster than regular instance methods 4. Enforcing Immutability | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. File folder = new File(path); if(!folder.exists()){ try { folder.mkdir(); } catch (Exception e) {} } | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Both Arrays and ArrayLists are used to store elements. Elements can be either primitives or objects in case of Arrays, but only objects can be stored in Arraylist. Array is a fixed length data structure while arraylist is variable length collection class. Once created, you cannot change the size of the arrays, but arraylists can dynamically resize itself when needed.Another notable difference between Arrays and Arrayslist is that arary is part of core java programming and array list is part of collection classes | ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. No, It will throw compile time error saying "must provide either dimension expressions or an array initializer" Alternatively we can provide array initializer like String[] strArray = new String[]{"Buggy","Bread"}; which will initialize it to size 2 with values as "Buggy" and "Bread" | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Unreachable code is a code segment that can never be executed in any case. For example - int x = 5; return; System.out.println(x); In this code , 2nd line will return the control out of the method and hence 3rd line will never get executed and hence is unreachable code. This will be caught at compile time only. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Because the reference is of Object Array and the resolution of what it holds is identified at the runtime. String[] strArray = new String[2]; strArray[0] = 5; would have given the compile time array as the reference is of String array. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Abstract classes can take care of that to a certain extent. Though they are little heavier than Interfaces but An abstract class with all abstract methods and no instance variables will be able to help with everything that currently an interface does. The only problem is that a class can only extend one class whereas it can implements multiple interfaces and that is the reason Interfaces were introduced in Java, i.e to get over the problem of multiple inheritance. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. JVM - With Cloud and Serverless, this could be a hurdle for it to be preferred technology. Confusion between OOP and Functional Programming. Slower speed of innovation due to wider adoption. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Base Class is a relative term used to signify the Parent class in Parent - Child or Base - derived relationship. Derived Class is a relative term used to signify the Child class in Parent - Child or Base - derived relationship. Abstract Class is a class that is not allowed to be instantiated and hence can serve only a base class for it's usage. Concrete Class is the class which is supposed to be instantiated and hence provide definition for all implementing interface methods and extending abstract methods. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. As String is immutable so by maintaining pool area we can refer the object to same area if they are with same content. But when it comes to string buffer or builder then due to mutable property if we do so then all the objects referring to that area will from now has new content.. So as to avoid this pool is present only in string. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. A List is an child interface of collection interface in java where as Linked list is and implementation class of List interface which has doubly linked as a underlying data structure | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. ConcurrentMap is an interface and it is a member of the Java Collections Framework. It represents a Map that is capable of handling concurrent access to it without affecting the consistency of entries in a map. ConcurrentMap interface present in java.util.concurrent package. HashMap operations are not synchronized, while Hashtable provides synchronization. Though Hashtable is thread-safe, it is not very efficient. To solve this issue, the Java Collections Framework introduced ConcurrentMap in Java 1.5. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. What if the initialization throws an exception. In that case , it will let it move forward without initializing the final field. So it's a way to enforce that either the field is initialized or it fails completely. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. No | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Though Static methods cannot access the instance variables directly, They can access them using instance handler. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. Abstract class is the class that is not supposed to be instantiated. The purpose of the class to only have extension to the derived class. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Java.util.Map | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
![]() ![]() | ||||