Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Interview Questions and Answers - Order By Newest | ||||
| ||||
Ans. Open ended Questions. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   open questions   code review   documentation   clean code | ||||
| ||||
Ans. Java is a portable-language because without any modification we can use Java byte-code in any platform(which supports Java). So this byte-code is portable and we can use in any other major platforms. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   bytecode   jvm   compiler   portable   features of java   basic interview question | ||||
| ||||
Ans. public class BuggyBread1{ public static void main (String args[]) { String str = "hheello world"; char[] charArray = str.toCharArray(); char selectedChar = 'a'; for(char char1: charArray){ if(!str.contains(Character.toString(char1).concat(Character.toString(char1)))){ selectedChar = char1; break; } } System.out.println(str.indexOf(Character.toString(selectedChar))); } } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  string  code  coding Asked in 9 Companies | ||||
| ||||
Ans. S3 and S4 are pointing to different memory location and hence Output 1 will be false. Hash code is generated to be used as hash key in some of the collections in Java and is calculated using string characters and its length. As they both are same string literals, and hence their hashcode is same.Output 2 will be true. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   string   hashcode   hash code   string comparison   string pool | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. Hashcode is used for bucketing in Hash implementations like HashMap, HashTable, HashSet etc. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   string   hashcode   hash code   string comparison  hashtable Asked in 17 Companies basic   frequent | ||||
| ||||
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; } } } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  coding  code  threads  multithreading Asked in 1 Companies | ||||
| ||||
Ans. equal 1 | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   string class   string   string pool   code   coding basic   frequent | ||||
| ||||
Ans. Bytecode is a highly optimized set of instructions designed to be executed by the Java run-time system. Its called Byte Code because each instruction is of 1-2 bytes. Sample instructions in Byte Code - 1: istore_1 2: iload_1 3: sipush 1000 6: if_icmpge 44 9: iconst_2 10: istore_2 | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   jvm   interpreter   platform independent   byte code | ||||
| ||||
Ans. PATH is the variable that holds the directories for the OS to look for executables. CLASSPATH is the variable that holds the directories for JVM to look for .class files ( Byte Code ). | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   path   classpath   byte code   jvm   basic interview question Asked in 3 Companies intermediate   rare | ||||
Ans. The code will not compile raising an error that the local variable y might not have been initialized. Unlike member variables, local variables are not automatically initialized to the default values for their declared type. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   code   default value | ||||
| ||||
Ans. BuggyBread | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   code   coding   stringbuffer   string   method calling   pass by reference | ||||
| ||||
Ans. Buggy | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   code   coding   stringbuffer   string   method calling   pass by reference | ||||
| ||||
Ans. Buggy | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   code   coding   stringbuffer   string   method calling   pass by reference | ||||
| ||||
Ans. Compile Time Error: Unhandled exception type Exception | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   code   coding   overridding   late binding   exception handling   abstract class   abstract methods | ||||
| ||||
Ans. file.txtC:file.txtC:file.txt | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   file handling | ||||
| ||||
Ans. NullPointerException at line:File file = new File("/folder", child); | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   file handling | ||||
| ||||
Ans. ..file.txt C:WorkspaceProject..file.txt C:Workspacefile.txt | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   file handling | ||||
| ||||
Ans. c. File file = new File("../file.txt"); FileWriter fileWriter = new FileWriter(file); BufferedWriter bufferedOutputWriter = new BufferedWriter(fileWriter); | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   filewriter   bufferedwriter   scjp   ocjp  file handling | ||||
| ||||
Ans. IOException | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   exception   ioexception  file handling | ||||
| ||||
Ans. FileNotFoundException | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   scjp   ocjp   filenotfoundexception   fileoutputstream  file handling | ||||
| ||||
Ans. Though we are trying to serialize BuggyBread1 object but we haven't declared the class to implement Serializable. This will throw java.io.NotSerializableException upon execution. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   serialization   notserializableexception   exception   file handling | ||||
| ||||
Ans. No, It will throw java.io.NotSerializableException. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   serialization   notserializableexception   exception   file handling | ||||
| ||||
Ans. Yes. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   io   file   fileio   coding   code   serialization   yesno  file handling | ||||
| ||||
Ans. Date and Time after 5 months from now. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   date   calendar   scjp   ocjp   coding   code | ||||
Very Frequently asked. Favorite question in walkins and telephonic interviews. Usually among first few questions. Asked in different variants. Must know for intermediate and expert professionals.Among Top 10 frequently asked questions. | ||||
| ||||
Ans. A Class must override the hashCode method if its overriding the equals method. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashcode  hash code   equals   collections Asked in 44 Companies intermediate   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. 4567 5678 6789 | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   set   treeset   coding   code | ||||
Ans. SUNDAY MONDAY SATURDAY | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  enum   set   collections   hashset   coding   code | ||||
Try 3 Question(s) Test | ||||
Ans. FRIDAY , SATURDAY and WEDNESDAY will be printed but the order cannot be determined. Only one FRIDAY will be printed as Set doesn't allow duplicates. Order cannot be determined as HashSet doesn't maintain elements in a particular order. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   code   coding   enum   set   hashset | ||||
Try 3 Question(s) Test | ||||
| ||||
Ans. 1 111 2 TreeSet maintains the elements in the ascending order which is identified by the compareTo method. compareTo method in String has been defined such that it results in the natural alphabetic Order. Here the elements in the TreeSet are of String and not of Integer. In String Natural Order, 111 comes before 2 as ascii of 1st character first determines the order. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   code   coding   set   treeset   string   integer | ||||
| ||||
Ans. 1 2 111 TreeSet maintains the elements in the ascending order which is identified by the compareTo method. compareTo method in Integer has been defined such that it results in the natural numerical Order. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   code   coding   set   treeset | ||||