Core Java Interview Questions
Tags: java, opensource, interview, career
Published: 2019-12-21 10:24:33

###Q:- What is Java?
<ol>
<li>Java is a general-purpose, high level, object-oriented programming language, and java is also platform independent.</li>
<li>Java was originally developed by James Gosling at Sun Microsystems (which has since been acquired by Oracle Corporation) and released in 1995.</li>
</ol>

###Q:- What is the most important features of Java?
####1. Simple
<p>Java is very popular general-purpose programming language. </p>

####2. Object-Oriented
<ol>
<li> Java is a pure Object oriented </li>
<li> Every thing in java is object </li>
<li>  All programs and data reside inside objects and classes  </li>
</ol>

####3. Distributed
<ol>
<li> Java facilitates it's users to create distributed applications in Java</li>
<li> RMI and EJB are used for creating distributed applications</li>
</ol>

####4. Robust
Java gives importance to memory management by using the technique called Garbage Collection and Exception handling etc. 

####5. Secure
<p>Java is secure becasue of</p>
<ol>
<li> Byte code concept</li>
<li> Java is secured because it doesn't use explicit pointers</li>
<li> Exception handling concept</li>
<li> Garbage collection mechanism</li>
<li> Type-safe reference casting in JVM</li>
</ol>

####6. Platform Independent
Java compiler generates a platform-independent code called bytecode. 

####7. Portable
The Bytecode generated by java can be used on any machine. So it can be portable. 

####8. Compiled and Interpreted
Generally, computer languages are either compiled or interpreted. but java combines both compilers and interpreters. 

####9. Performance
The use of a bytecode makes the performance high. the speed is also high with comparing c, c++. 

####10. Multi-Threading
Multithreading means handling more than one job at a time. Java supports Multithreading. 


###Q:- How to write very first simple program in Java?
<pre class="code" data-language="java">
/* This is a very first simple Java program.
   FileName : "FirstProgram.java". 
*/

public class FirstProgram
{
    // Your program begins with a call to main().
    // Prints "Java Interview Questions" to the terminal window.
	
    public static void main(String args[])
    {
        System.out.println("Core Java Interview Questions and Answers for Experienced");
    }
}

//Output: Core Java Interview Questions and Answers for Experienced
</pre>


###Q:- Print "Java Interview Questions" even before main() is executed. How will you achieve that?

You can print the message inside the static block. It will execute when the class gets loaded into the memory and even before the creation of an object.

Hence it will be executed before the main()method. And it will be executed only once.

<pre class="code" data-language="java">
public class PrintMessage {
    static {
        System.out.println("Core Java Interview Questions");
        System.exit(0);
    } 
}

//Note - 
//1. The System.exit(0) exits the program before the JVM starts to look for main()
//2. This will not work with JDK7 - Because, In JDK7 the code would not execute 
	 as it looks for the main method before any other thing.

//Output: Core Java Interview Questions
</pre>


###Q:- What is a Java package and how is it used?
A java package encapsulates a group of similar types of classes, interfaces, and sub-packages.

####Use of Packages:
>> A Package is used to create a separate namespace for groups of classes and interfaces.
>> A Package are also used to manage and control related classes and interfaces into a single API unit.

####Type of Package:
1. Built-in package: javax, lang, awt, swing, io, util, sql, etc
2. User-defined package

###Q:-Which package is imported by default?
java.lang package

###Q:- What is the base class of all classes?
<pre class="code" data-language="java">
java.lang.Object
</pre>


Read the complete Article - <a href="https://www.fullstacktutorials.com/interviews/core-java-interview-questions-answers-experienced-23.html" target="_blank">Core Java Interview Questions and Answers for Experienced</a>