Search Interview Questions | ![]() ![]() Click here and help us by providing the answer. ![]() Click Correct / Improve and please let us know. |
|
| ||||
Core Java - Interview Questions and Answers for 'Difference between' - 20 question(s) found - Order By Newest | ||||
![]() | ||||
| ||||
Ans. ArrayList are implemented in memory as arrays and hence allows fast retrieval through indices but are costly if new elements are to be inserted in between other elements. LinkedList allows for constant-time insertions or removals using iterators, but only sequential access of elements 1. Retrieval - If Elements are to be retrieved sequentially only, Linked List is preferred. 2. Insertion - If new Elements are to be inserted in between other elements , Linked List is preferred. 3. Search - Binary Search and other optimized way of searching is not possible on Linked List. 4. Sorting - Initial sorting could be pain but lateral addition of elements in a sorted list is good with linked list. 5. Adding Elements - If sufficiently large elements needs to be added very frequently ,Linked List is preferable as elements don't need consecutive memory location. | ||||
![]() ![]() | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
![]() | ||||
![]() | ||||
| ||||
Ans. Inheritance means a object inheriting reusable properties of the base class. Compositions means that an abject holds other objects. In Inheritance there is only one object in memory ( derived object ) whereas in Composition , parent object holds references of all composed objects. From Design perspective - Inheritance is "is a" relationship among objects whereas Composition is "has a" relationship among objects. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
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++. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Both belong to the class as a whole and not to the individual objects. Static methods are explicitly called for execution whereas Static block gets executed when the Class gets loaded by the JVM. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. servlet is a small, server-resident program that typically runs automatically in response to user input. A network socket is an endpoint of an inter-process communication flow across a computer network. We can think of it as a difference between door and gate. They are similar as they both are entry points but they are different as they are put up at different areas. Sockets are for low-level network communication whereas Servlets are for implementing websites and web services | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. Float can represent up to 7 digits accurately after decimal point, where as double can represent up to 15 digits accurately after decimal point. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. new operator is used to statically create an instance of object. newInstance() is used to create an object dynamically ( like if the class name needs to be picked from configuration file ). If you know what class needs to be initialized , new is the optimized way of instantiating Class. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. LinkedList and ArrayList are two different implementations of the List interface. LinkedList implements it with a doubly-linked list. ArrayList implements it with a dynamically resizing array. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Stack memory areas is used to hold method and local variables while objects are always allocated memory in the heap. The heap memory is shared between multiple threads whereas Stack memory isn't. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. Swing provides both additional components like JTable, JTree etc and added functionality to AWT-replacement components. Swing components can change their appearance based on the current “look and feel†library that’s being used. Swing components follow the MVC paradigm, and thus can provide a much more flexible UI. Swing provides extras for components, such as icons on many components, decorative borders for components, tool tips for components etc. Swing components are lightweight than AWT. Swing provides built-in double buffering ,which means an off-screen buffer is used during drawing and then the resulting bits are copied onto the screen. Swing provides paint debugging support for when you build your own component. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. System.out and System.err both represent the monitor by default and hence can be used to send data or results to the monitor. But System.out is used to display normal messages and results whereas System.err is used to display error messages and System.in represents InputStream object, which by default represents standard input device, i.e., keyboard. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
Ans. throw is used to explicitly throw an exception especially custom exceptions, whereas throws is used to declare that the method can throw an exception. We cannot throw multiple exceptions using throw statement but we can declare that a method can throw multiple exceptions using throws and comma separator. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. Break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. No Difference. Both are the acceptable ways to declare an array. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. WeakHashMap uses weak reference for keys, which means if the key object doesn't have any reference then both key/value mapping will become eligible for garbage collection. | ||||
![]() | ||||
![]() ![]() ![]() | ||||
![]() | ||||
| ||||
Ans. JRE or Java Runtime Environment is the Java Virtual Machine on which class files are executed. It includes borwser plugins that facilitates execution of class files in browsers. JDK or Java Development Kit includes JRE , compiler and development tools. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. = is the assignment operator that assigns the result of the expression on the right to the variable on the left, whereas == is the operator to check object equality to see if the reference on left and right are pointing to the same object. For primitive types, its used to check if both variables holds the same value. | ||||
![]() | ||||
![]() ![]() ![]() ![]() | ||||
| ||||
Ans. List is an interface whereas ArrayList is an implementation of List. | ||||
![]() | ||||
![]() ![]() ![]() ![]() ![]() | ||||
| ||||
Ans. Var scopes the variable to the nearest function whereas Let scopes the variable to nearest block. For example - function printNumbers() { for(var i = 1; i < 3: i++){ console.log(i); } console.log(i); // works fine and will print 3 as i has a function scope and not local loop scope } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
| ||||
![]() | ||||
![]() | ||||
![]() ![]() ![]() | ||||