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. We can overload the main method by specifying different argument types. For example - 2 main methods with different arguments is perfectly legal public static void main(); public static void main(String[] args); The following are not legal as compiler will complain of duplicate methods public static void main(String[] args); public static void main(String[] args); Even The following are not legal as we cannot overload on return types public static String main(String[] args); public static void main(String[] args); | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  main method Asked in 2 Companies | ||||
| ||||
Ans. public class LinkedList { Node start = null; Node head = null; class Node{ Integer body; Node nextNode; Node(Integer value){ body = value; } } private void insertInMiddle(Integer value){ head = start; if(start == null) { start = new Node(value); head = start; head.nextNode = null; return; } while(head.body < value){ if(head.nextNode == null || head.nextNode.body >= value){ Node newNode = new Node(value); newNode.nextNode = head.nextNode; head.nextNode = newNode; break; } head = head.nextNode; } } private void traverse(){ head = start; while(head != null){ System.out.println(head.body); head = head.nextNode; } } public static void main(String[] args){ LinkedList ll = new LinkedList(); ll.insertInMiddle(5); ll.insertInMiddle(10); ll.insertInMiddle(15); ll.insertInMiddle(7); ll.traverse(); } } | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  LinkedList  Data structures  Algorithm | ||||
| ||||
Ans. Interfaces don't have member elements and method definitions that could cause diamond problem. With Java 8, Interfaces have default method definitions. This could have created diamond problem but Java introduced a compile time check for "duplicate default methods" in case same method is derived from multiple interfaces and no definition is overridden by the class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  diamond problem  interfaces  java 8  default methods | ||||
| ||||
Ans. Step 1 - We can create a Registry Class having Map of all created objects as key and References list as value. Step 2 - Whenever we create an object , we should update the Registry in the constructor to add the new object. Step 3 - Whenever we assign a new reference to the object , we need to update the entry in Map. Similarly if the reference get's removed ( end of scope etc ), we need to remove the entry of reference from the list. Step 4 - We can have threaded code to monitor the Map to see if any object looses all it's references and should call the method to destroy object and clean the memory. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  garbage collection | ||||
| ||||
Ans. AMI is an Amazon Machine Image. It contains the configuration to enable to boot up an EC2 instance with said configuration whereas Cloud formation is a templating language that allows to describe how to build a VPC and also allows you to create AWS services AMI is templating specific to instances whereas the scope of CloudFormation templating is much bigger. CloudFormation could use AMI for launching instances along with other services. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  aws cloud formation  aws ami  amazon ami  aws ami  amazon ami vs aws cloud formation | ||||
| ||||
This question was recently asked at 'Barclays'.This question is still unanswered. Can you please provide an answer. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve   Asked in 1 Companies | ||||
| ||||
Ans. boolean - java.lang.Boolean byte - java.lang.Byte char - java.lang.Character double - java.lang.Double float - java.lang.Float int - java.lang.Integer long - java.lang.Long short - java.lang.Short void - java.lang.Void | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java5   data types   wrapper classes   adapter design pattern   rare | ||||
| ||||
Ans. java.lang.StringBuffer. | ||||
Sample Code for StringBuffer | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   object class   stringbuffer expert   rare | ||||
| ||||
Ans. There can be two different elements with the same hashcode. When two elements have the same hashcode then Java uses the equals to further differentation. So there can be one or two objects depending on the content of the objects. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   hashcode   map   hashmap   object reference   advanced Asked in 1 Companies | ||||
Frequently asked to fresh graduates and less experienced developers. | ||||
| ||||
Ans. 1. Multithreading provides better interaction with the user by distribution of task 2. Threads in Java appear to run concurrently, so it provides simulation for simultaneous activities.The processor runs each thread for a short time and switches among the threads to simulate sim-ultaneous execution (context-switching) and it make appears that each thread has its own processor.By using this feature, users can make it appear as if multiple tasks are occurring simultaneously when, in fact, each is running for only a brief time before the context is switched to the next thread. 3. We can do other things while waiting for slow I/O operations.In the java.iopackage, the class InputStreamhas a method, read(), that blocks until a byte is read from the stream or until an IOExceptionis thrown. The thread that executes this method cannot do anything elsewhile awaiting the arrival of another byte on the stream. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   threads   multi threading  concurrency   multithreading Asked in 5 Companies intermediate   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. They are wrappers to primitive data types. They allow us to access primitives as objects. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   data types   wrapper classes Asked in 3 Companies basic   frequent | ||||
| ||||
Ans. Cookie and Session are used to store the user information. Cookie stores user information on client side and Session does it on server side. Primarily, Cookies and Session are used for authentication, user preferences, and carrying information across multiple requests. Session is meant for the same purpose as the cookie does. Session does it on server side and Cookie does it on client side. One more thing that quite differentiates between Cookie and Session. Cookie is used only for storing the textual information. Session can be used to store both textual information and objects. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  session   session management   java   cookies   authentication   web application   ebay intermediate | ||||
Very frequently asked. Usually asked in different variants like Diff between StringBuffer , String Builder ; Difference between StringBuilder and String class; Choice between these classes etc. | ||||
| ||||
Ans. A string buffer implements a mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls. The String class represents character strings. All string literals in Java programs, such as "abc" are constant and implemented as instances of this class; their values cannot be changed after they are created. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   string   stringbuffer   frequently asked Asked in 18 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. The JDBC is a pure Java API used to execute SQL statements. It provides a set of classes and interfaces that can be used by developers to write database applications. The steps needed to execute a SQL query using JDBC: 1. Open a connection to the database. 2. Execute a SQL statement. 3. Process th results. 4. Close the connection to the database. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   jdbc   db connectivity Asked in 2 Companies basic   frequent | ||||
| ||||
Ans. We can make a class immutable by 1. Making all methods and variables as private. 2. Setting variables within constructor. Public Class ImmutableClass{ private int member; ImmutableClass(int var){ member=var; } } and then we can initialize the object of the class as ImmutableClass immutableObject = new ImmutableClass(5); Now all members being private , you cant change the state of the object. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   immutable  immutability   immutable  immutability class   technical lead Asked in 5 Companies intermediate   frequent | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. Yes.we cannot access them directly but we can access them using object reference.Static methods belong to a class and not objects whereas non static members are tied to an instance. Accessing instance variables without the instance handler would mean an ambiguity regarding which instance the method is referring to and hence its prohibited. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   static   static methods   java keywords Asked in 1 Companies | ||||
Frequently asked to fresh graduates. | ||||
| ||||
Ans. When two threads are waiting each other and cant precede the program is said to be deadlock. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   threads   multi threading   operating system   deadlock  concurrency Asked in 23 Companies basic   frequent | ||||
| ||||
Ans. Java does not support pointers. Java does not support multiple inheritances. Java does not support destructors but rather adds a finalize() method. Finalize methods are invoked by the garbage collector prior to reclaiming the memory occupied by the object, which has the finalize() method. Java does not include structures or unions because the traditional data structures are implemented as an object oriented framework. C++ compiles to machine language , when Java compiles to byte code . In C++ the programmer needs to worry about freeing the allocated memory , where in Java the Garbage Collector takes care of the the unneeded / unused variables. Java is platform independent language but c++ is depends upon operating system. Java uses compiler and interpreter both and in c++ their is only compiler. C++ supports operator overloading whereas Java doesn't. Internet support is built-in Java but not in C++. However c++ has support for socket programming which can be used. Java does not support header file, include library files just like C++ .Java use import to include different Classes and methods. There is no goto statement in Java. There is no scope resolution operator :: in Java. It has . using which we can qualify classes with the namespace they came from. Java is pass by value whereas C++ is both pass by value and pass by reference. Java Enums are objects instead of int values in C++ C++ programs runs as native executable machine code for the target and hence more near to hardware whereas Java program runs in a virtual machine. C++ was designed mainly for systems programming, extending the C programming language whereas Java was created initially to support network computing. C++ allows low-level addressing of data. You can manipulate machine addresses to look at anything you want. Java access is controlled. C++ has several addressing operators . * & -> where Java has only one: the . We can create our own package in Java(set of classes) but not in c and c++. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   c++   difference between java and c++   programming concepts   programming languages   architecture   technical architect   technical lead Asked in 1 Companies | ||||
| ||||
Ans. Struts 1 actions are singleton. So all threads operates on the single action object and hence makes it thread unsafe. Struts 2 actions are not singleton and a new action object copy is created each time a new action request is made and hence its thread safe. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   j2ee   mvc frameworks   struts   struts1   struts2   struts 1   struts 2   architecture | ||||
Try 1 Question(s) Test | ||||
Frequently asked to fresh graduates. | ||||
| ||||
Ans. Runnable - waiting for its turn to be picked for execution by the thread schedular based on thread priorities. Running - The processor is actively executing the thread code. It runs until it becomes blocked, or voluntarily gives up its turn. Waiting: A thread is in a blocked state while it waits for some external processing such as file I/O to finish. Sleeping - Java threads are forcibly put to sleep (suspended) with Thread.sleep. they can resume using Thread.resume method. Blocked on I/O - Will move to runnable after I/O condition like reading bytes of data etc changes. Blocked on synchronization - Will move to Runnable when a lock is acquired. Dead - The thread is finished working. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   threads   multi threading   scheduling   thread states   basic interview question Asked in 1 Companies basic   frequent | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. A Stream is an abstraction that either produces or consumes information. There are two types of Streams : Byte Streams: Provide a convenient means for handling input and output of bytes. Character Streams: Provide a convenient means for handling input & output of characters. Byte Streams classes: Are defined by using two abstract classes, namely InputStream and OutputStream. Character Streams classes: Are defined by using two abstract classes, namely Reader and Writer. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   file io   streams   byte stream   character stream  file handling Asked in 3 Companies | ||||
| ||||
Ans. co-variant return type states that return type of overriding method can be subtype of the return type declared in method of superclass. it has been introduced since jdk 1.5 | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   inheritence   overriding   covariant return type   jdk5   advanced Asked in 3 Companies expert | ||||
| ||||
Ans. ConcurrentHashMap is a hashMap that allows concurrent modifications from multiple threads as there can be multiple locks on the same hashmap. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashmap   map   concurrenthashmap   concurrenthashmap  concurrency   general electric   ge Asked in 32 Companies   rare | ||||
| ||||
Ans. HBM Files ( Mapping ) DB Connection ( DB Connection String , User Name , Password , Pool Size ) SQL Dialect ( SQL variant to be generated ) Show SQL ( Show / No show SQL on Console ) Auto Commit ( True / False ) | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate   configuration   barclays Asked in 11 Companies | ||||
| ||||
Ans. Predicate represents an anonymous function that accepts one argument and produces a result. Supplier represents an anonymous function that accepts no argument and produces a result. Consumer represents an anonymous function that accepts an argument and produces no result. | ||||
Sample Code for Predicate Sample Code for Supplier Sample Code for Consumer | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java8   predicate   consumer   supplier   lambda expression   predicate vs consumer vs supplier expert | ||||
| ||||
Ans. 1. Query Optimization ( Query Rewriting , Prepared Statements ) 2. Restructuring Indexes. 3. DB Caching Tuning ( if using ORM ) 4. Identifying the problems ( if any ) with the ORM Strategy ( If using ORM ) | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   db   database   hibernate   orm   at&t   overstock.com   performance improvement   architecture   technical lead   architect intermediate | ||||
| ||||
Ans. Thread class holds the definition of start method ( This is the method that starts execution of new thread and then calls run method within the scope of new thread ). Interfaces don't hold any definition and so does runnable. So it makes it necessary the usage of Thread class , whatever implementation you choose. When your class extends the thread class, it carries the definition of start method from parent Thread class onto itself and hence new yourClass.start() helps starting a new thread and then executing run method in that new thread scope. When you implement runnable interface , you are just making it sure to the JVM that you have implemented the required method ( run() ) which the Thread start method will look for upon executing start method. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   threads   multithreading   runnable interface   thread class | ||||
| ||||
Ans. List | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  collections   java   sorting | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. Encapsulation | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java concepts   java features   oops concepts   oops features   access protection   information hiding | ||||
| ||||
Ans. final | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   enum | ||||