Java Questions

Q:

Difference between Arraylist and Linked list?

Answer

ArrayList and LinkedList both implements List interface and maintains insertion order. Both are non synchronized classes.


 


But there are many differences between ArrayList and LinkedList classes that are given below.


 

ArrayList    V/s     LinkedList ::


 

1) ArrayList internally uses dynamic array to store the elements.


                   Whereas


LinkedList internally uses doubly linked list to store the elements.


 

2) Manipulation with ArrayList is slow because it internally uses array. If any element is removed from the array, all the bits are shifted in memory.


                   Whereas


Manipulation with LinkedList is faster than ArrayList because it uses doubly linked list so no bit shifting is required in memory.


 

3) ArrayList class can act as a list only because it implements List only.


                   Whereas


LinkedList class can act as a list and queue both because it implements List and Deque interfaces.


 

4) ArrayList is better for storing and accessing data.


                   Whereas


LinkedList is better for manipulating data.

Report Error

View answer Workspace Report Error Discuss

3 2323
Q:

Is Java a pure object oriented language?

Answer

Java uses primitive data types and hence is not a pure object oriented language.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 2270
Q:

If a method is declared as protected, where may the method be accessed?

Answer

A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2263
Q:

Difference between Java Beans & Servlets?

Answer

java bean is a reusable component, where as the servlet is the java program which extends the server capability. 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

2 2263
Q:

Why interface method is always public?

Answer

To make this method available to every implementation class

Report Error

View answer Workspace Report Error Discuss

Subject: Java
Job Role: IT Trainer

0 2258
Q:

What is MultiThreading?

Answer

Executing two or more blocks (threads) of a program at a time is called MultiThreading.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2242
Q:

What is the difference between creating String as new() and literal ?

Answer

When we create string with new() Operator, it’s created in heap and not added into string pool while String created using literal are created in String pool itself which exists in PermGen area of heap.



String s = new String("Test");

does not put the object in String pool , we need to call String.intern() method which is used to put them into String pool explicitly. its only when you create String object as String literal e.g. String s = "Test" Java automatically put that into String pool.

Report Error

View answer Workspace Report Error Discuss

1 2229
Q:

Which of the following is not the other name of attriibute?

A) Data member B) Instance variable
C) instance D) Data filed
 
Answer & Explanation Answer: C) instance

Explanation:

Instance is an object not an attribute

Report Error

View Answer Report Error Discuss

Filed Under: Java

0 2214