Interview Questions and Answers - Order By Newest Q1191. Is a string an array of characters in Java ? Core Java
Ans. No, String is a class whose objects are called strings in Java. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  String Q1192. Can we synchronize the run() method in Java? Core Java
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  synchronization  multithreading  run method Q1193. Difference between if and switch ? Can we replace all switch statements with if statements ? Core Java
Ans. if statement is used to do 2 direction branching whereas switch is used to do multi direction branching in Java.
Yes we can replace all switch statements with nested if statements. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  switch  if vs switchAns. if statements nested within another if or else blocks are called nested if statements.
if(condition1) {
if(condition2){
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  if statement  control statements   nested if Q1195. Write a Program to check if the entered number is a Duck Number ( Number having 0 in it ) ? Core Java
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  duck number Q1196. What will the following code print ?
int x[] = new int[5];
x[0] = 1;
x[1] = 2;
for(int count=0;count<x.length;count++){
System.out.println(x[count]);
} Core Java
Ans. 1
2
0
0
0
As arrays are not dynamically expanded , we have declared the array for size 10. As we have only initialized only 2 values , it will print rest as their default values. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  arrays Q1197. What will the following code print
int x[] = new int[5];
x[0] = 1;
x[1] = 2;
for(int count=0;count<=x.length;count++){
System.out.println(x[count]);
} Core Java
Ans. 1
2
0
0
0
ArrayIndexOutOfBoundException: 5
As array index starts with 0 and ends with the index of (size - 1), the index 5 is inaccessible for the array and hence will throw the exception. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  arrays Q1198. what are different pointer operators used ? Core Java
This question was recently asked at 'Huawei 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   Asked in 1 Companies 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   Q1200. Which java features makes java different from other languages ? Core Java
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   Q1201. Why cant we start an identifier with a number in Java? Core Java
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   Q1202. What is the default data type of Serialized methods?' Core Java
This question was recently asked at 'Intime Tec'.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   Asked in 1 Companies Q1203. Do we have a method to reverse a string in String class ? Core Java
Ans. No but we have it in StringBuilder. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  String  StringBuilder  Reverse a string Q1204. How can we convert char into a String ? Core Java
Ans. We can use StringBuilder. StringBuilder accepts char as the argument for it's constructor.
new StringBuilder('').toString(); Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  convert char to String  char  String Q1205. How can we check if a particular character is upper case in Java ? Core Java
Ans. 1. We can compare the ascii value of the character. Ascii for Capital case character is from 65 to 90.
2. We can compare to see if lowerCase of the character is not equal to character itself.
For example -
if character is 'a' the following code
new StringBuilder(char).toString().toLowerCase().equals(new StringBuilder(char)
will return true and hence char is lower case
if character is 'A' the following code
new StringBuilder(char).toString().toLowerCase().equals(new StringBuilder(char)
will return false and hence char is upper case Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  check upper case character  character Q1206. How different is it when final applied to variables and object references ? Core Java
Ans. final when assigned to object references doesn't make them immutable. It means that the references cannot be de-referenced.
final when applied to variables means that the value cannot be changed. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  final keyword  final variable Q1207. Why the following code produced this output ?
int x = 5;
int y = x;
y = 10;
System.out.println(x); // prints 5 and not 10 Core Java
Ans. Because when we say y = x, the value of x is copied to another memory location and then y points to that new memory location.
Unlike object references that once assigned point to same object in memory, value is copied in case of variable assignment. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  variable assignment Q1208. In which memory segment - heap or stack, the following stored by JVM
1. static members
2. objects
3. object references
4. local or method variables
Core Java
Ans. static members are stored in method area of heap
objects are stored on heap
object references are stored on stack
local or method variables are stored on stack Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  jvm  memory management  stack  heap Q1209. How can we convert String into Char array and vice versa ? Core Java
Ans. There is a method toCharArray() within String class that can be used to convert string to char array.
string.toCharArray();
String class has an argument constructor that takes a char array and create a string
new String(charArray); Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  string  char array Q1210. How can we convert a character or a character array into a String ? Core Java
Ans. String has an argument constructor that take char array as argument and creates a string.
There is no constructor available with String that takes in a character and creates a String. We can use StringBuilder which has a char argument constructor. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  character  char  char array  String  char to String  char array to StringAns. Generics are a facility of generic programming that were added to the Java programming language in 2004 within J2SE5.0. They allow "a type or method to operate on objects of various types while providing compile-time type safety. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  generics Asked in 7 Companies Q1212. What are the uses of Abstraction ? Core Java
Ans. Loose Coupling
Facilitates designing complex applications by making them modular. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  oops concepts  abstraction Asked in 1 Companies Q1213. Why is JVM called Virtual machine ? Core Java
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  jvm Q1214. Lets say we have a set "set1" with objects of Class A, Class has a non static string called element1, Write a code ( using lambda expression ) to see if there is any object in the set with element1 = "Hello". Core Java
Ans. set1.stream().filter(p->p.element1.equals("Hello")).findAny().isPreent();
or
set1.stream().map(A::getElement1).anyMatch("Hello"::equals) Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  lambda expressions  java 8  java8  java 8 filter  findAny() Q1215. Is Runtime Polymorphism possible without Inheritance ? Core Java
Ans. Yes, Runtime Polymprohism requires either Class inheritance or Interface implementation. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  runtime polymorphism  object oriented programming (oops)  oops concepts  method overriding  inheritance  object oriented programming (oops)  oops concepts Q1216. Why is Java such an important Programming language ? Core Java
Ans. Because of following features
Object Oriented and hence helps build maintainable and easily enhanceable code.
Platform Independence and hence can be executed anywhere
Fast due to JIT compiler Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q1217. Why Java is considered more purer object oriented language than C++ ? Core Java
Ans. Because of
lack of use of pointers,
Lack of structural programming and
Lack of Multiple Inheritance Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  oops  java vc c++ Q1218. Does Wrapper classes produces immutable objects ? Core Java
Ans. Yes Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  wrapper classes  immutable  immutability Q1219. Why shouldn't we use string concatenation extensively or in a loop ? Core Java
Ans. Because String being an immutable object creates a new object upon each concatenation cycle. If there is any such need , we should use String Builder whose objects are mutable. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  string  string immutable  immutability  for loop  control statements  loop statement Asked in 1 Companies Q1220. What do we mean by a Data Type ? Core Java
Ans. if you have similar type of data or objects or entities, then we can give them a type with unique name. And this name will be our Data type. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  data type