Core Java Fresher Interview Questions with Answers

 Core Java Fresher Interview Questions with Answers

This blog explains about Core Java Fresher Interview Questions with Answers and is given below :

____________________________________________________________________

 Mock interview questions:

1.Scanner class:

Scanner class is used for for getting inputs of primitive datatypes and string. Scanner is in the package of java.util.

2.Why pointer concept is neglected in Java:

Pointer concept can also points the memory address of the data. Using (&-ampersand symbol), we can get the address of the data. So, Java neglects the pointer to make the concept of data security.

 

3.System.out.print-System is a final class from java.lang package and out is an object for Printstream class and Print is a type of Printstream class.

public final class System {

    static PrintStream out;

    static PrintStream err;

    static InputStream in;

    …

}

public class PrintStream extends FilterOutputStream {

    //out object is inherited from FilterOutputStream class

    public void println() {

    …

}

4.for vs while loop:

for loop and while loop has its difference in the syntax. While loop (condition-controlled loop) is said to be known for unknown iterations but for loop(counter controlled loop) is known for known iterations.

For reference :

https://www.cs.uic.edu/~jbell/CourseNotes/C_Programming/Looping.html, https://teamtreehouse.com/community/why-use-while-loop-instead-of-for

http://java.meritcampus.com/core-java-topics/for-vs-while-loop-in-java

http://www.mkyong.com/java/while-loop-for-loop-and-iterator-performance-test-java/

5.String args[] :

command line arguments  as it is collection of variables in the string format or you can say as passing array of string arguments.

6.static variable vs object:

You can change the variable with the class name but for nonstatic variables you can change only via objects.

For example:

class Test{ static int a=10;int b=5} Test t1=new Test(); Test t2=new Test();

Test.a=6;System.out.print(t1.a); System.out.print(t2.a);-both will print 6 as output.

But t1.b=10; System.out.print(t1.b); System.out.print(t2.b);-t1 will print as 10&t2 as 5.

So, the memory of static will be shared and memory of nonstatic will not be shared and it will be changes with instance.

For reference:

https://www.cis.upenn.edu/~matuszek/cit591-2006/Pages/static-vs-instance.html

 

7.break in switch:

Break in switch statement is necessary because it will break the loop when the case of the loop is executed otherwise it will falls through all the cases. In C programming language, it was referenced with Branch table. In C# programming language, it was overcome with jump statement.

For reference:

https://stackoverflow.com/questions/252489/why-was-the-switch-statement-designed-to-need-a-break

 

8.abstract vs interface:

An interface is an implementation of class and differs with interface keyword. An abstract class will extends the behavior of class and differs with abstract keyword. Interface is a keyword used to create interface and it can’t be used with methods whereas abstract is keyword used to create class and can be used with methods.

For reference:

https://www.journaldev.com/1607/difference-between-abstract-class-and-interface-in-java, https://www.geeksforgeeks.org/difference-between-abstract-class-and-interface-in-java/ https://www.journaldev.com/2752/java-8-interface-changes-static-method-default-method

 

9.final in local variable:

final is a keyword when declared with variables, its value can’t be modified. final keyword can be declared to variables, methods as per our convenience.

For reference:

https://www.geeksforgeeks.org/final-local-variables-java/

10.variable in interface:

we can declare variables in java but it will consider it as public static variable since interface doesn’t allow object creation i.e. instances can’t be created so it will have only one memory all over the load of class.

For reference:

https://stackoverflow.com/questions/2430756/why-are-interface-variables-static-and-final-by-default, http://knowledgehills.com/java/java-interface-variables-default-methods.htm, https://www.javahelps.com/2015/02/introduction-to-interface-with-java-8.html

Only method properties have changed in interface after java 1.8.

 

  1. Apache maven:

  2. Apache maven is a software project management and comprehension tool. It was developed by apache software foundation.

For reference:

https://maven.apache.org/index.html, https://en.wikipedia.org/wiki/Apache_Maven, https://www.geeksforgeeks.org/introduction-apache-maven-build-automation-tool-java-projects/

                                                                                                                                                                             –          BY 

                                                                                                                                                                             SUDHARSANAM 

______________________________________________________________________________________