Interview Questions and Answers - Order By Newest Q211. Which method of String class is used to convert Boolean to String ? Core Java
Ans. toString() is an overloaded method of String class that is used to convert many data types to String, Boolean being one of them.
toString(Boolean bool) Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  String  String class  Boolean Asked in 1 Companies Basic Ans. Collections in java is a framework of classes that provides an abstracted data structure to store and manipulate the group of objects. Each class is unique in the way it stores , search , sort and modify the elements. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  collections  collection classes Asked in 1 Companies Basic   frequent Q213. What is Maven ? Maven
Ans. Maven is a build automation tool used primarily for Java projects. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  maven  build Asked in 6 Companies basic   frequent Q214. Which class is the root class of all Exceptions in Java ?
Ans. Throwable Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies basic   frequent Ans. A media access control address is a unique identifier assigned to network interfaces for communications at the data link layer of a network segment. MAC addresses are used as a network address for most IEEE 802 network technologies, including Ethernet and Wi-Fi. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies basic Q216. What is an exception and exception handling in Java ? Core Java
Ans. An Exception in java is the occurrence during computation that is anomalous and is not expected.
Exception handling is the mechanism which is used to handle such situations.
Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  exception handling Asked in 18 Companies basic   frequent Q217. Why main method is declared static ? Core Java
Ans. static is the keyword that makes it accessible even without creating any object and using class name only. Making it non static would like creation of object upfront before calling the method. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  main method  static Asked in 4 Companies Basic Q218. Create a Class Bank with the methods to deposit and Withdraw ? Core Java
Ans. class Bank {
int balance;
Bank(){
balance = 0;
}
void deposit(int amount){
balance = balance amount;
}
int withdraw(int amount){
balance = balance - amount;
return balance;
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Basic Q219. Which environment variables do we need to set in order to run Java programs? Core Java
Ans. PATH, CLASSPATH and JAVA_HOME Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  environment variables  path  classpath  java_home Asked in 3 Companies basic   frequent Q220. Does importing a package imports all its sub packages too ? Core Java
Ans. No, but we can use wild card (*) to do so
For example -
import java.util.*
will import all packages with name starting with java.util Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  package   import packages Asked in 1 Companies basic Q221. What is the default value of a declared object reference ? Core Java
Ans. Null Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  object reference  null Asked in 1 Companies basic Q222. Difference between shallow copy and object cloning ? Core Java
Ans. Shallow copy is one of the way for object cloning, other being deep copy. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  cloning  shallow copy  object cloning basic Q223. Which Web and Application server is being used by your application ? Server
Ans. We are using Apache 2.3 and Tomcat 5.6 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  web server  application server  server Basic   frequent Q224. What is a class and object ?
or
How would you explain a fresher the concept of class and object in simple terms ? Core Java
Ans. Class is a template using which objects are created in memory. It's kind of a mold using which objects with body / state are made.
Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  class  object  class vs object Asked in 4 Companies basic   frequent 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 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 Q227. 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 Q228. 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 Q229. Write a Program to remove duplicate words from the String Core 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 Q230. 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 Q231. 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 Q232. 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 Q233. 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 Q234. 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 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 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 Q237. 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 Q238. 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 Q239. 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 Q240. 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