Interview Questions and Answers - Order By Newest Q181. Should a DB Insert Request be a POST or PUT request in Rest Rest
Ans. It depends on whether the request object is persisted as it is
or
its first dismantled, modified or refactored and then inserted into DB.
In first case, it should be a PUT request whereas in second case it should be a POST Request. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Put vs Post   Rest Asked in 2 Companies intermediate   frequent Q182. What are the benefits of Enums ? Core Java
Ans. Enums in Java are used to declare predefined objects and then reuse them. they offer many benefits
1. Enum instance are type safe and thread safe.
2. Enum instances are singleton and hence reused.
3. If we use Enums with Switch , It makes sure that the passed argument is either of its instance and hence provides a safeguard.
4. If we use Enum with Sorted Collections we can sort the elements with a predefined priorities ( as per constant declaration in enum )
5. We can use Enum as a Factory by defining its constructor.
6. We can store related constant data within enum. For example - If we know the values for the map upfront, we can alternatively use an enum. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 6 Companies Q183. How to Bulk upload the data into Oracle database? Database
Ans. We can use external table feature of Oracle. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Intermediate Frequently asked Design Pattern interview question. Q184. What is a prototype design pattern ? Design
Ans. The prototype pattern is a creational design pattern. It is used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects. Prototype is used when we need duplicate copies of objects. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  design pattern  prototype design pattern  cloning Asked in 11 Companies intermediate Q185. Difference between Array and ArrayList ? Core Java
Ans. <a href="http://javahungry.blogspot.com/2015/03/difference-between-array-and-arraylist-in-java-example.html" rel="nofollow">http://javahungry.blogspot.com/2015/03/difference-between-array-and-arraylist-in-java-example.html</a> Sample Code for ArrayList Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  array  arraylist Asked in 11 Companies basic   frequent Q186. What will be the crontab to run a job every last day of month ? Unix
Ans. 59 23 28-31 * * [ "$(date +%d -d tomorrow)" = "01" ] && job_name Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  unix  crontab Asked in 1 Companies Q187. Write a unix command to find top 10 files by size ? Unix
Ans. du -a /var | sort -n -r | head -n 10 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  unix command Asked in 1 Companies Q188. What are fields that gets displayed when you execute "Top" command and briefly explain each field ? Unix
Ans. PID - process identification number is an identification number that is automatically assigned to each process when it is created
USER - User Name
PR - PR is the process actual priority
NI is the nice value, which is a user-space concept.
VIRT -Virtual Image (kb). The total amount of virtual memory used by the task.
RES - Resident size (kb). The non-swapped physical memory a task has used.
SHR - Shared Mem size (kb). The amount of shared memory used by a task.
S - Process Status. The status of the task which can be one of:
D = uninterruptible sleep
R = running
S = sleeping
T = traced or stopped
Z = zombie
%CPU - % CPU usage
%MEM - % MEM Usage
TIME - Total CPU time the task has used since it started.
COMMAND - Command which was used to execute the process Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  top command  unix command Asked in 1 Companies 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 Q190. Write a Program to print the positive and negative numbers separetly Core Java
Ans. int[] arr = {1,-1,2,-3,3,-4,4,5,6,-5,-6,-7,-8,8,9,-9};
List positiveNumbers = new ArrayList<>();
List negativeNumbers = new ArrayList<>();
for(int i = 0; i < arr.length(); i ){
if(I < 0){
negativeNumbers.add(i);
} else {
positiveNumbers.add(i);
}
}
System.out.println("Positive Numbers:" + positiveNumbers);
System.out.println("Negative Numbers:" + negativeNumbers); 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 Q191. 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 Q192. 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 Q193. 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 Q194. Scale yourself on Java on the scale of 1 to 10 General
Ans. [Open Ended Answer]
The objective of the question is to check how efficient one is in the language so that appropriate level questions are asked. Don't tell too high number if you are being interviewed for a junior or mid level position as the interviewer may throw advance level questions. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 17 Companies Q195. 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 Q196. Can an application have multiple main methods within different classes ? If yes, How will the app decide which one to be executed ? Core Java
Ans. Yes we can have a main method with string[] argument in every class of an application. When we execute an app we specify the starting point i.e the class that will get the control first and hence main method of that class gets executed. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  main method Asked in 3 Companies Q197. 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 Q198. 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 Q199. Is there a way to know size of an object in Java ? Core Java
Ans. No, Java doesn't have a sizeOf operator. In C / C++ , its required to determine how much memory allocation is required which is not the case with Java. Java handles memory allocation and deallocation intrinsically. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  sizeOf  size of object  sizeOf operator Asked in 1 Companies   rare Q200. What are the different ways to handle an exception ? Core Java
Ans. 1. Wrap the desired code in try block followed by a catch / finally to catch the exception
2. Declare the throws clause with exceptions that the code is expected to throw as an indication to the calling method to take care of it. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  exception handling Asked in 4 Companies Try 1 Question(s) Test Q201. How does Java handle integer overflows and underflows? Core Java
Ans. It uses those low order bytes of the result that can fit into the size of the type allowed by the operation. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  integer  data types Asked in 1 Companies   rare Ans. No, delete is not a keyword in Java. Destruction of objects is taken care by Java Garbage Collection mechanism. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  delete  keywords Asked in 1 Companies Ans. No exit is a method to exit execution of a program. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  exit  keywords  exit a program Asked in 1 Companies Q204. Who invokes a thread's run method ? Core Java
Ans. After a thread is started using a call to start method, JVM invokes the thread’s run method when the thread is initially executed. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  threads  thread run method Asked in 1 Companies Q205. How and Why Strings are interned in Java ? Core Java
Ans. String class has a public method intern() that returns a canonical representation for the string object. String class privately maintains a pool of strings, where String literals are automatically interned.
these are automatically interned so as to have efficient String comparison using == operator instead of equals which is usually slower. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  string  string pool  string intern Asked in 1 Companies Q206. Write a Program to print count of each character in a String. Core Java
Ans. public class BuggyBread {
public static void main(String args[]) {
Map<Character, Integer> countMap = new HashMap();
String str = "hello world";
for (char character : str.toCharArray()) {
if (countMap.containsKey(character)) {
countMap.put(character, countMap.get(character) + 1);
} else {
countMap.put(character, 1);
}
}
System.out.println(countMap);
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  String  Code  Coding  Character Asked in 1 Companies Q207. Write a program for 0 and cross games? Core Java
This question was recently asked at 'Compro Technologies'.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  code.coding.0 and cross game Asked in 1 Companies Q208. Write Code showing Inheritance Core Java
Ans. class A {
public void test() {
System.out.println("Class A Test");
}
}
class B extends A {
public void test() {
System.out.println("Class B Test");
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q209. Write a Program / Code showing Inheritance and overridding Core Java
Ans. class A {
public void test() {
System.out.println("Class A Test");
}
}
class B extends A {
public void test() {
System.out.println("Class B Test");
}
public static void main(String[] args){
A a = new B();
a.test(); // will print Class B Test
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q210. 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