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. We can use System.getenv for getting the environment variables. For ex - System.getenv("JAVA_HOME") | ||||
| ||||
| Ans. Because the way float values are stored its not precise. For example - 0.1 is actually stored as 0.1000000000000000055511151231257827021181583404541015625 | ||||
| ||||
| Ans. It will throw Parse Exception. | ||||
| ||||
| Ans. No, member variables of a interface are final by default. The final ensures the value assigned to the interface variable is a true constant that cannot be re assigned by program code. | ||||
| ||||
| Ans. No, only methods can be declared abstract. | ||||
| ||||
| Ans. Responsive web design is a approach to web design that allow desktop webpages to be viewed perfectly in different devices and sizes. | ||||
| ||||
| Ans. https://en.wikipedia.org/wiki/Travelling_salesman_problem | ||||
| ||||
| Ans. boolean byte char double float int long short void | ||||
| ||||
| Ans. This exception usually occur if we try to register the bean with name already present in the registry or repository. Usually this happens when multiple tests are executed at once in single container. | ||||
| ||||
| Ans. NumberFormatException is the exception that Java throws when we try to convert one data type to the Number data type but the value is not parsable to be a Number. For example , the following code will result in the NumberFormatException String string = "Buggy"; int strtoInt = Integer.parseInt(string); | ||||
| ||||
| Ans. http://www.programmingsimplified.com/java/source-code/java-program-armstrong-number | ||||
| ||||
| 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. 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. println prints an additional end of line whereas printf doesnt. | ||||
| ||||
| 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. 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. session.createCriteria(Employee.class).add( Restrictions.or(Restrictions.like("name", "A%"),Restrictions.like("name", "B%"))).list(); | ||||
| ||||
| Ans. pom packaging is simply a specification that states the primary artifact is not a war or jar, but the pom.xml itself. | ||||
| ||||
| 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. 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. Java provides a faster allocation mechanism but at the cost of expensive deallocation. Deallocation in java is done by mechanism called garbage collection that runs periodically to free up unclaimed memory space , which actually slows down the application. Hence Java is usually faster if memory is not of concern and sufficiently large memory can be allocated to an application. C/C++ on other hand have equal cost of allocation and de-allocation. | ||||
| ||||
| 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. 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. 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. 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. https://en.wikipedia.org/wiki/Agile_software_development | ||||
| ||||
| Ans. Object class as its the parent class of all Java classes. | ||||
| ||||
| Ans. package com.string; import java.util.Scanner; public class String13 { public static void main(String[] args) { System.out.println("Enter Sentence"); Scanner sc=new Scanner(System.in); String sentence=sc.nextLine(); String[] words=sentence.split(" "); int count=0; for (String string : words) { string.trim(); if(!string.equals("")){ count++; System.out.println(string " " count); } } } } | ||||
| ||||
| 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. Promotions are created either using Management Center or Accelerator. PX_PROMOTION table is used to store Promotions. Complete Promotion is stored as an XML string within XMLPARAM column. Other tables which are used to store promotion related information are - CATENTCALCD CALCODE CLCDPROMO | ||||