Core Java - Interview Questions and Answers for 'Java' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Interview Questions


 2721 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Core Java - Interview Questions and Answers for 'Java' - 1557 question(s) found - Order By Rating

next 40
 Q1. Define CollectionCore Java2018-10-16 10:01:48

 This question was recently asked at 'Amber Road'.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          Amber Road


 Q2. What is the use of final String when Strings are immutable ?Core Java2018-10-13 09:44:41

 This question was recently asked at 'Cyient'.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     string     Cyient


 Q3. How can we check class file format in java ?Core Java2018-09-16 16:27:41

 This question was recently asked at 'Jagan Institute of Management Studies (JIMS)'.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          Jagan Institute of Management Studies (JIMS)


 Q4. Why string pool concept has been introduced in string ?Core Java2018-09-07 09:01:59

Ans. Memory Sharing and Optimal memory utilization.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     String Pool     Tarang


 Q5. What will the following code print upon executing main method of Main class

public class BaseClass {

BaseClass(){
this(2);
System.out.println("Hello I am in Base Class Constructor");
}

BaseClass(int i){
System.out.println("Hello I am in Base Class int argument Constructor");
}
}

public class DerivedClass extends BaseClass{
DerivedClass(){
System.out.println("Hello I am in Derived Class Constructor");
}
}

public class Main {

public static void main(String[] args) {
    DerivedClass derivedClass = new DerivedClass();
}
}
Core Java2018-09-06 08:46:44

Ans. Hello I am in Base Class int argument Constructor
Hello I am in Base Class Constructor
Hello I am in Derived Class Constructor

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     constructor


 Q6. What will the following code print upon executing main method of Main class

public class BaseClass {

BaseClass(){
this(2);
System.out.println("Hello I am in Base Class Constructor");
}

BaseClass(int i){
System.out.println("Hello I am in Base Class int argument Constructor");
}
}

public class DerivedClass extends BaseClass{
DerivedClass(){
super(1);
System.out.println("Hello I am in Derived Class Constructor");
}
}

public class Main {

public static void main(String[] args) {
    DerivedClass derivedClass = new DerivedClass();
}
}
Core Java2018-09-06 08:46:04

Ans. Hello I am in Base Class int argument Constructor
Hello I am in Derived Class Constructor

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     constructor


 Q7. Why line 4 in this code gives error saying "Cannot be referenced from a static context" ?

public class OuterClass {

public static void main(String[] args){
InnerClass innerClass = new InnerClass();
}

class InnerClass {

}
}
Core Java2018-09-05 15:09:21

Ans. InnerClass is a non static inner class and hence can only be instantiated using instance of the outer class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     inner class


 Q8. What will the following code print upon executing main method of Main class ?

public class BaseClass {
BaseClass(int x){
System.out.println("Hello I am in Base Class Constructor");
}
}

public class DerivedClass extends BaseClass{
DerivedClass(){
super(1);
System.out.println("Hello I am in Derived Class Constructor");
}
}

public class Main {

public static void main(String[] args) {
    DerivedClass derivedClass = new DerivedClass();
}
}
Core Java2018-09-05 09:52:37

Ans. Hello I am in Base Class Constructor
Hello I am in Derived Class Constructor

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     constructor


 Q9. What will the following code print upon executing main method of Main class ?

public class BaseClass {
BaseClass(int x){
System.out.println("Hello I am in Base Class Constructor");
}
}

public class DerivedClass extends BaseClass{
DerivedClass(){
System.out.println("Hello I am in Derived Class Constructor");
}
}

public class Main {

public static void main(String[] args) {
    DerivedClass derivedClass = new DerivedClass();
}
}
Core Java2018-09-05 09:51:30

Ans. Compilation error as there is no default constructor available in BaseClass.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     constructor



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. What will the following code print upon executing main method of Main class ?

public class BaseClass {
BaseClass(){
System.out.println("Hello I am in Base Class Constructor");
}
}

public class DerivedClass extends BaseClass{
DerivedClass(){
System.out.println("Hello I am in Derived Class Constructor");

super();
}
}

public class Main {

public static void main(String[] args) {
    DerivedClass derivedClass = new DerivedClass();
}
}

Core Java2018-09-05 09:50:04

Ans. There will be compilation error within constructor of Derived Class as "super must be the first statement in constructor body".

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     constructor


 Q11. What will the following print upon executing main method of Main class ?

public class BaseClass {
BaseClass(){
System.out.println("Hello I am in Base Class Constructor");
}
}

public class DerivedClass extends BaseClass{
DerivedClass(){
System.out.println("Hello I am in Derived Class Constructor");
}
}

public class Main {

public static void main(String[] args) {
    DerivedClass derivedClass = new DerivedClass();
}
}
Core Java2018-09-05 09:48:18

Ans. Hello I am in Base Class Constructor
Hello I am in Derived Class Constructor

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     constructor


 Q12. Will it print the message in Base Class constructor if we execute main method of Main class ? why ?

public class BaseClass {
BaseClass(){
System.out.println("Hello I am in Base Class Constructor");
}
}

public class DerivedClass extends BaseClass{
}

public class Main {

public static void main(String[] args) {
    DerivedClass derivedClass = new DerivedClass();
}
}
Core Java2018-09-05 09:45:42

Ans. Yes.

When the Derived class constructor is initialized , a no argument super will be called intrinsically.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     constructor


 Q13. Isnt the use of HashTable and ConcurrentHashMap the same, i.e providing synchronized map collection ?Core Java2018-08-30 08:37:45

 This question was recently asked at 'Tata Consultancy'.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     synchronized collections  hashtable  ConcurrentHashMap     Tata Consultancy


 Q14. Can we use try within catch block ?Core Java2018-08-28 15:41:21

Ans. Yes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve          Ness Technologies


 Q15. Is java fully platform independent ?Core Java2018-08-27 13:13:05

 This question was recently asked at 'National Informatics Centre (NIC)'.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          National Informatics Centre (NIC)


 Q16. Can you write immutable class without final?Core Java2018-08-27 13:12:25

 This question was recently asked at 'Wells Fargo'.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          Wells Fargo


 Q17. Where to use interface and abstract class ?Core Java2018-08-06 14:52:09

 This question was recently asked at 'Exterro'.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          Exterro


 Q18. What are basic functions of OOPS ?Core Java2018-08-06 14:51:48

 This question was recently asked at 'Zillious'.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          Zillious


 Q19. Write a java program to find the maximum profit in day tradingCore Java2018-08-06 14:51:27

 This question was recently asked at 'Capital One'.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          Capital One



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q20. Why doesn't this code give compile time error when we are clearly trying to add an integer element to an array of Strings

Object[] strArray = new String[2];
strArray[0] = 5;
Core Java2018-07-25 08:18:37

Ans. Because the reference is of Object Array and the resolution of what it holds is identified at the runtime.

String[] strArray = new String[2];
strArray[0] = 5;

would have given the compile time array as the reference is of String array.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     arrays


 Q21. Will this give compile time error ?

Object[] strArray = new String[2];
strArray[0] = 5;
Core Java2018-07-25 08:17:03

Ans. No. But It will throw ArrayStoreException at runtime.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     ArrayStoreException  arrays


 Q22. What is the problem with this code

String[] strArray = new String[2];
strArray[0] = 5;
Core Java2018-07-25 08:16:18

Ans. We are trying to add an integer element to an array of String. Will give compile time error.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     arrays


 Q23. If arrays cannot be resized , Why is this code valid

String[] strArray = new String[2];
strArray = new String[5];
Core Java2018-07-25 08:01:42

Ans. We are not resizing the first array here but assigning the reference strArray to a new Array with size 5.

So after line 2, We have 2 arrays in memory, one with size 2 and other with size 5 with strArray referring to second array with size 5.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     arrays  array initialization


 Q24. Is this code valid

String[] strArray = new String[2];
strArray.length = 5;
Core Java2018-07-25 08:00:02

Ans. It will give compile time error saying "The final field array.length cannot be assigned"

Arrays once initialized cannot be resized.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     arrays  array initialization


 Q25. Is this array initialization correct ? If Yes, What will be the size of array ?

String[] strArray = new String[3]{"Buggy","Bread"};
Core Java2018-07-25 07:55:04

Ans. No. It will result in error saying "Cannot define dimension expressions when an array initializer is provided"

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     arrays  array initialization


 Q26. Is this array initialization correct ? If Yes, What will be the size of array ?

String[] strArray = new String[]{"Buggy","Bread"};
Core Java2018-07-25 07:54:15

Ans. Yes, size of the array will be 2.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     arrays  array initialization


 Q27. Is this array declaration correct ? If not , Why ?

String[] strArray = new String[];
Core Java2018-07-25 07:52:50

Ans. No, We haven't specified the size of array to be initialized.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     arrays  array initialization


 Q28. Which memory segment holds the byte code ?Core Java2018-07-24 07:52:02

Ans. Code Segment

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Memory Management  Code Memory Segment  Code Segment Memory  Code Segment


 Q29. Can we call a static method using reference currently pointing to null.Core Java2018-07-23 11:35:15

 This question was recently asked at 'CIGNEX Datamatics'.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     static methods   static     CIGNEX Datamatics



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q30. How to run jar file using command promptCore Java2018-07-23 11:34:34

 This question was recently asked at 'CIGNEX Datamatics'.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     jar  running jar using command line  cron entry   setting java app as cron     CIGNEX Datamatics


 Q31. Tell something about Sleep method.Core Java2018-07-23 09:42:30

 This question was recently asked at 'IBM'.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     Thread  sleep  multithreading     IBM      Basic


 Q32. Which Java version supports Interface Default methods ?Core Java2018-07-22 11:46:24

Ans. Java 1.8 or Java 8

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     default methods   interface default methods   java 8  java 8 features


 Q33. Can we declare an array without assigning the size of an array? Core Java2018-07-22 07:36:26

Ans. No, It will throw compile time error saying "must provide either dimension expressions or an array initializer"

Alternatively we can provide array initializer like

String[] strArray = new String[]{"Buggy","Bread"};

which will initialize it to size 2 with values as "Buggy" and "Bread"


 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     arrays  array initialization


  Q34. Difference between Arrays and ArrayList ?Core Java2018-07-22 07:23:59

Ans. Both Arrays and ArrayLists are used to store elements. Elements can be either primitives or objects in case of Arrays, but only objects can be stored in Arraylist. Array is a fixed length data structure while arraylist is variable length collection class. Once created, you cannot change the size of the arrays, but arraylists can dynamically resize itself when needed.Another notable difference between Arrays and Arrayslist is that arary is part of core java programming and array list is part of collection classes

  Sample Code for arrays arraylist

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     array  arraylist  array vs arraylist     Infosys  HCL Technologies  TMC Bonds  FJA-US  Fareportal  LandaCorp  Mindera      basic        frequent


 Q35. What is ArrayStoreException ?Core Java2018-07-22 07:18:05

Ans. It's an exception that is thrown when we attempt to add value of an incompatible type to an array.

For example -

Object[] strArray = new String[2];
strArray[0] = 5;

In this code, strArray reference of type Object has currently been assigned the String array but at line 2 we are trying to add an integer value.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     arrays   ArrayStoreException


 Q36. Can we change the size of array once created ?Core Java2018-07-22 07:16:31

Ans. No. Arrays cannot resize dynamically.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     array  array size      Basic


 Q37. Does Java generate .class file for interfaces ? Core Java2018-07-20 18:20:53

Ans. Yes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     .class file  java byte code  interfaces


 Q38. Can we declare an Interface with abstract keyword ? Core Java2018-07-20 18:20:27

Ans. Yes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     abstract keyword


 Q39. Can we declare constructor inside an interface ? Why ?Core Java2018-07-20 18:19:59

 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     interface   constructor



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q40. What is method hiding in Java ?Core Java2018-07-20 18:17:00

 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     method hiding


next 40


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: