Core Java Interview Questions Part 6/ input and output, arrays, and strings.

Hello Friends, In this blog post I am going to let you know about a few more interview questions of core java related to input and output, arrays, and strings.

Core java interview questions covers all the important questions of the topics mentioned above.

These core java interview questions is a great help to remember all the important highlights and important topics from each java chapter.

These interview questions will surely help to understand a few very confusing concepts in java.

What is the difference between System.out and system.errr?

System.out and System.err both represent the monitor by default and hence can be used to send data or results to the monitor. But system.out is used to display normal messages and results whereas system.err is used to display error messages.

On which memory, array are created in java?

Arrays are created on dynamic memory by JVM. There is no question of static memory in java; every thing (variable, array, object etc.) is created on dynamic memory only.

Can you call the main method of a class from another class?

Yes, we can call the main () method of a class from another class using classname.main(). At the time of calling the main() method, we should pass a string type array to it.

Is string a class or data type?

String is a calss in java.lang package. But in java, all classes are also considered as data types. So we can take string as a data type also

Can we call a class as a data type?

Yes, a class in also called user-defined data type. This is because a user can create a class.

What is object reference?

An object reference is a unique hexadecimal number representing the memory address of the object. It is useful to access the members of the object.

What is the difference between == and equal() while comparing strings? Which one is reliable?

== operator compare the references of the string objects, it does not compare the content of the objects.

equal() method compares the contents. While comparing the strings, equal() method should be used as it yields the correct result.

What is string constant pool?

String constant pool is a separate block of memory where the string objects are held by JVM. If a string object is created directly, using assignment operator as: string s1 = “hello”, then it stored in string constant pool.

Explain the difference between the following statements?

  1. String s = “Hello”;
  2. String s = new String(“Hello”);

In the first statement assignment operator is used to assign the string literal to the string variable s. In this case, JVM first of all checks whether the same object is already available in the string constant pool.

If it is available, then it creates another reference to it. If the same object is not available, then it cretes another object with the content “Hello” and store it into the string constant pool.

In the second statement, new operator is used to create the string object. In this case, JVM always creates a new object without looking in the string constant pool.

So this was all about the Core java interview questions in this topic.

These Core java interview questions could be a great help in your college viva, academic study, and any job interview.

In the case of any queries, you can write to us at [email protected] we will get back to you ASAP.

Hope! you would have enjoyed this post about Core Java Interview Questions Part 6/ input and output, arrays, and strings.

Please feel free to give your important feedbacks in the comment section below.

Have a great time!

Anurag

I am a blogger by passion, a software engineer by profession, a singer by consideration and rest of things that I do is for my destination.