Core Java Programming Interview Questions

Core Java Programming Interview Questions

Core Java Programming Interview Questions:

All these below are purely java programming interview questions collected from different attendees and different companies. Walk through all the programming questions and try to figure it out before checking the answers below.

 

Basics:

 

1.What is the output ?


package in.javadomain;

class Basics {
public static void main(String[] args) {
System.out.println("I am main method" + new Basics());
}

Basics() {
System.out.println("I am construtor!");
}
}

 

Output:


I am construtor!
I am main methodtrader.Basics@52e922

 

 

2.What is the output ?


package in.javadomain;

class Basics {
public static void main(String[] args) {
System.out.println("I am main method");
System.out.println(new Basics());
}

Basics() {
System.out.println("I am construtor!");
}
}

 

Output:


I am main method
I am construtor!
in.javadomain.Basics@52e922

 

 

3.What is the output ?


package in.javadomain;

class Basics {
public static void main(String[] args) {
System.out.println(4+2*10);
}
}

 

Output:


24

 

 

String:

 

1.What is the output ?


public class StringIQ {
public static void main(String args[]) {
Integer i = new Integer(10);
String s = "10";
boolean isStrIntEquals = s.equals(String.valueOf(i));
System.out.println(isStrIntEquals);
}
}

 

Output:


true

 

 

2.What is the output ?


public class StringIQ {
public static void main(String args[]) {
Integer i = new Integer(10);
String s = "10";
boolean isStrIntEquals = s.equals(i);
System.out.println(isStrIntEquals);
}
}

 

Output:


false

 

 

3. What is the output ?


public class StringIQ {
public static void main(String args[]) {
byte[] byteArr = {97,98,99};
String s = new String(byteArr);
System.out.println(s);
}
}

 

Output:


abc

 

 

4. What is the output ?


public class StringIQ {
public static void main(String args[]) {
String s = "ABCDEF";
CharSequence charSequence = s.subSequence(1,4);
System.out.println(charSequence);
}
}

 

Output:


BCD

 

 

5. What is the output ?


public class StringIQ {
public static void main(String args[]) {
String s = "ABC";
CharSequence charSequence = "ABC";
System.out.println(s.equals(charSequence));
}
}

 

Output:


true

 

 

6. What is the output ?


public class StringIQ {
public static void main(String args[]) {
String s = "";
s = s.join("-","Hello","Java","domain");
System.out.println(s);
}
}

 

Output:


Hello-Java-domain

 

 

7. What is the output ?

public class StringIQ {
public static void main(String args[]) {
String s1 = “Java”;
String s2 = new String (“Java”);
s1 = s1.intern();
System.out.println(s1==s2);
}
}

 

Output:


false

 

 

8. What is the output ?

public class StringIQ {
public static void main(String args[]) {
String s1 = “Java”;
String s2 = new String (“Java”);
s2 = s2.intern();
System.out.println(s1==s2);
}
}

 

Output:


true

478 total views, 1 views today

Leave a Reply

Your email address will not be published. Required fields are marked *