Core Java - Interview Questions and Answers for 'Basic' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

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.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Rating

   next 30
 Q61. Give an example of how Object Oriented Programming Concepts can be implemented.Design
Ans. You can implement encapsulation in Java by keeping the fields (class variables) private and providing public getter and setter methods to each of them. Java Beans are examples of fully encapsulated classes. Encapsulation in Java: Restricts direct access to data members (fields) of a class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     oops  oops example  oops concepts  oops features     Asked in 2 Companies      basic        frequent


  Q62. Explain OOPs

or

Explain OOPs Principles

or

Explain OOPs Concepts

or

Explain OOPs features

or

Tell me something about OOPs
Core Java
Ans. OOPs or Object Oriented Programming is a Programming model which is organized around Objects instead of processes. Instead of a process calling series of processes, this model stresses on communication between objects. Objects that all self sustained, provide security by encapsulating it's members and providing abstracted interfaces over the functions it performs. OOP's facilitate the following features

1. Inheritance for Code Reuse
2. Abstraction for modularity, maintenance and agility
3. Encapsulation for security and protection
4. Polymorphism for flexibility and interfacing

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     oops  oops features     Asked in 260 Companies      basic        frequent


Very frequently asked. Usually among very first few questions.
 Q63. Define encapsulation in Java ?Core Java
Ans. Encapsulation is a feature of OOP's that binds the data and it's associated methods together as a single unit and facilitate protection and data hiding by providing minimal interface to outside. For example - member variables are declared private and are accessed through public methods. Moreover we have private methods that can only be used internally and hence providing minimal interface to outside class through use of public methods.

  Sample Code for encapsulation

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     encapsulation  object oriented programming (oops)  oops concepts  oops  oops concepts  oops features     Asked in 4 Companies      Basic        frequent


 Q64. Write a method, that compare two numbers and return the bigger one ?Core Java
Ans. int compare(int a, int b) {
a>b? return a: return b;
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     code  program  coding     Asked in 1 Companies      basic


 Q65. What problem we could have with ArrayList which aren't possible with Vectors ?Core Java
Ans. ArrayLists aren't synchronized and hence doesn't allow synchronized access. As multiple threads can access an arraylist in parallel, it may result in an inconsistent state.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     vector  arraylist  list  collections      Basic


 Q66. What is the use of final keyword ?Core Java
Ans. final keyword is a modifier that means differently when applied to variables, methods and classes.

1. Final variable cannot be changed once initialized
2. Final method cannot be overridden
3. Final class cannot be sub classed

  Sample Code for final variable

  Sample Code for final method

  Sample Code for final class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     final  final keyword     Asked in 1 Companies      Basic        frequent


 Q67. What are the examples of immutable objects in Java ?Core Java
Ans. Following Classes in Java SE creates immutable objects

String class
Wrapper Classes like Integer, Float etc.
StackTraceElement
Most Enum classes
File Class
Locale Class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     immutable  immutability objects  immutable  immutability     Asked in 1 Companies      Basic        frequent


 Q68. Which of following is / are valid static final declaration ?

public static final String MAX_NUM = "10";
public static final Object NULL = null;
public static final MathContext MATH_CONTEXT = new MathContext(2,RoundingMode.CEILING);
Core Java
Ans. All are valid declarations.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     static final  constants      basic


 Q69. What is the difference between reference and object ?Core Java
Ans. Object is an entity in Java , i.e which has a state ( instance variables ) and methods attached to it ( static or non static , through class definition ). References are the identifiers that are used to point to objects.

For example -

Employee emp = new Employee();
emp = new Employee();

In this code, emp is the reference that gets assigned to the new object created by the new operator. In the second line , we have assigned the same reference to another object. So with these 2 lines of code, we have 2 objects in memory with reference emp now pointing to second object.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     reference  object  reference vs object      Basic        frequent


 Q70. What is the difference between Enumeration and Iterator ?Core Java
Ans. Enumeration can iterate only legacy collections like Vector , HashTable and Stack whereas Iterator can iterate both legacy and non legacy collections.

Enumeration is less safer than Iterator

Enumeration is fail safe whereas Iterator is fail fast

Iterator allows for removal of element while traversal whereas Enumeration doesn't have remove method.

Enumerations were introduced in Java 1 whereas Iterators were introduced with Java 2

Enumerations have methods like hasMoreElements and nextElement whereas Iterators have methods like hasNext, next and remove

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     enumeration vs iterator  collections      Basic        frequent


 Q71. If an Abstract class has only abstract methods, What's the difference between such a class and an interface ?Core Java
Ans. Such a class still can have member elements which can be inherited and hence facilitate code reuse. Moreover Abstract class can have non final static elements whereas interfaces are only allowed to have static final elements.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     abstract class   interfaces     Asked in 2 Companies      Basic


 Q72. Write a Program to convert a binary to number ?Core Java
Ans. int convert(int binaryInt) {
int sumValue=0;
int multiple = 1;
while(binaryInt > 0) {
binaryDigit = binaryInt;
binaryInt = binaryInt /10;
sumValue = sumValue (binaryDigit * multiple);
multiple = multiple * 2;
}

return sumValue;
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     code  coding     Asked in 1 Companies      basic


 Q73. How does java identifies which method to be called in method overriding or runtime polymorphism, when both methods share the same name and signature ? Core Java
Ans. Java identifies the method to be called at runtime by the object that is being referenced.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     polymorphism  object oriented programming (oops)  oops concepts  overloading  overriding      basic


 Q74. Which of the two - compile time and run time polymorphism - requires signature of the method to be different ?Core Java
Ans. runtime polymorphism or method overriding doesn't require method name and signature to be different whereas compile time polymorphism or method overloading requires method name to be same but the signature to be different.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     polymorphism  object oriented programming (oops)  oops concepts  overloading  overriding      basic


 Q75. What is the importance of Abstract Class ?Core Java
Ans. Abstract classes provide a mechanism of interfacing ( using abstract method ) as well as code reuse through inheritance ( extending abstract class )

Comparing to concrete class they have an advantage of providing interface which a concrete class doesn't provide.

Comparing to interfaces they have an advantage of providing code reuse through inheritance which interfaces dont provide.

  Sample Code for abstract class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     abstract class  importance of abstract class      Basic        frequent


 Q76. What will happen if we don't have termination statement in recursion ?Core Java
Ans. It would result in endless function calls and hence eventually would result in stackoverflow exception.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     recursion  stackoverflowexception      Basic        frequent


 Q77. What is recursion in Java ?Core Java
Ans. It's a programming technique wherein the method can call itself. The method call usually involves a different set of parameters as otherwise it would lead to an infinite loop. There is usually a termination check and statement to finally return the control out of all function calls.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 1 Companies      Basic


 Q78. What is JVM ?Core Java
Ans. JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed.JVMs are available for many hardware and software platforms (i.e. JVM is platform dependent).Runtime Instance Whenever you write java command on the command prompt to run the java class, an instance of JVM is createdThe JVM performs following operation:Loads codeVerifies codeExecutes codeProvides runtime environment

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     memory management  jvm     Asked in 3 Companies      basic        frequent


 Q79. What will we get if we try to print local variable that hasn't been initialized ?Core Java
Ans. It will print the garbage value as compiler doesn't provide a default value to local variables.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     local variable  default values      basic


 Q80. What is the precedence of operators in Java ?Core Java
Ans. http://introcs.cs.princeton.edu/java/11precedence/

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     operators  operator precedence      basic


 Q81. Write program to create a linked list and perform different operations on it.Algorithm
Ans. import java.util.*;
class LinkedListSolution{
protected LinkedList list;
public LinkedListSolution(){
list = new LinkedList();
}
public Object pop() throws NoSuchElementException{
if(list.isEmpty())
throw new NoSuchElementException();
else
return list.removeFirst();
}
public void push(Object obj){
list.addFirst(obj);
}
public Object peek() throws NoSuchElementException{
if(list.isEmpty())
throw new NoSuchElementException();
else
return list.getFirst();
}
public boolean isEmpty(){
return list.isEmpty();
}
public String toString(){
return list.toString();
}
}
class TestStack{
public static void main(String args[]){
LinkedListSolution s = new LinkedListSolution();
s.push("First");
s.push("Second");
s.push("Third");
System.out.println("Top: " s.peek());
s.push("Fourth");
while(!(s.isEmpty()))
System.out.println(s.pop());
}
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Linkedlist  data structures  algorithm     Asked in 2 Companies      basic


 Q82. What are some of the Java Naming conventions ?Core Java
Ans. 1. Class name should be a noun and should start with capital case character.

2. Interface Name should be an adjective and should start with capital case character.

3. Method and Variable names should follow lower camel case notation.

4. package name should be all lower case.

5. constant variables (static final) should be all capital case.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     naming conventions      basic


 Q83. What access the variable gets if we don't provide any access specifier ?Core Java
Ans. It gets the default access i.e package protected.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     access specifiers  default Access specifier      Basic


  Q84. What are the core OOPs concepts ?Core Java
Ans. Abstraction, Encapsulation, Polymorphism , Composition and Inheritance

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     core oops concepts     Asked in 65 Companies      basic        frequent


 Q85. Write a Program to remove duplicate words from the StringCore Java
Ans.
public class BuggyBread {
public static void main(String args[]) {
String str = "we are what we repeatedly Do excellence, then, is not an act but a haBit";
Set<String> wordSet = new LinkedHashSet(); // Using Linked Hash Set as we would like to retrieve words in the insertion order

for(String word: str.split(" ")){
wordSet.add(word);
}

for(String word: wordSet){
System.out.print(word);
System.out.print(" ");
}
}
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     String  coding  code     Asked in 1 Companies      basic


 Q86. What are the different operators in Java ?Core Java
Ans. && - AND
|| - OR
! - LOGICAL NOT

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     operators      Basic


 Q87. What are the different primitive data types in Java ?Core Java
Ans. boolean
byte
char
double
float
int
long
short
void

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     data types  primitive data types     Asked in 1 Companies      Basic


 Q88. Write any sorting algorithm.Algorithm
Ans. https://javasearch.buggybread.com/InterviewQuestions/questionSearch.php?searchOption=label'

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Algorithm  Sorting Algorithm     Asked in 4 Companies      basic        frequent


  Q89. What is the difference between authentication and authorization ?Authentication
Ans. Authentication is the process of verifying the identity and credentials of the user to authenticate him into the system.

whereas

Authorization is the process by which access to a segment , method or resource is determined.

Authorization is usually a step next to authentication.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     authentication  authorization  authentication vs authorization     Asked in 9 Companies      basic        frequent


 Q90. What is archiving ?Process
Ans. It's the process of preserving the state of an object and then restoring it.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve           basic


previous 30   next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: