1) What is the difference between == and equals()?
Answer: The below is the answer for this question:
== operator compares the string objects, where as equals() function compares the text stored in the string objects.
public class Demo{ public static void main(String[] args) { String a = new String("Hello" ); String b = new String("Hello" ); if(a == b) { System. out.println("Strings are equal" ); }else { System. out.println("Strings are not equal" ); } } }
For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:
2) When do we get ArrayIndexOutOfBoundsException?
Answer: The below is the answer for this question:
When you exceed the size of the Array as shown in the below program, we will get ArrayIndexOutOfBoundsException.
public class Demo{ public static void main(String[] args) { int[] a = new int [3]; a[0] = 9; a[1] = 5; a[2] = 8; a[3] = 7; } }
For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:
3) What are the disadvantages of Array?
Answer: The below is the answer for this question:
1. Arrays are fixed in size
2. We cannot store different types of values into a single array
For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:
4) What is static Array?
Answer: The below is the answer for this question:
Arrays are fixed in size, hence we can call them static Arrays
For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:
5) Why void is mentioned while writing the main method?
Answer: The below is the answer for this question:
As we generally don’t return anything from main() method, we specify void while writing the main method.
For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:
6) Can main method be overloaded?
Answer: The below is the answer for this question:
Yes, main method can be overloaded.
For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:
7) Write a Java program to use the Wrapper classes for converting integer value stored in String format to its actual type?
Answer: The below is the answer for this question:
public class Demo{ public static void main(String[] args) { String s = "100"; int a = Integer.parseInt(s ); System.out.println(a +15); } }
For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:
8) What exception do we get on converting the unconvertible String to number using Integer Wrapper Class?
Answer: The below is the answer for this question:
NumberFormatException will be displayed
For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:
9) What is the difference between call by value and call by reference?
Answer: The below is the answer for this question:
1. call by value and call by reference are used to invoke the functions by passing the parameters
2. In call by value, the variables values are passed to the function being called
3. In call by referenced, the object reference will be passed to the function being called
For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:
10) What is the purpose of Constructors?
Answer: The below is the answer for this question:
The purpose of constructors is to simplify the process of initialization.
For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:
Please leave your questions/comments/feedback below.
Happy Learning 🙂
Arun Motoori ( www.QAFox.com )