Core Java interview questions

Core Java interview questions

Java is a platform independent, case sensitive language which is used to create secure and robust applications. It was developed by James Gosling in 1991. Apart from having a C like notation, it was much easier, uniform and simple than C/C++. The first version of Java was released by Sun Microsystems in 1995. It works on a "Write Once Run Anywhere" platform. Java is open source software. The J2 versions of Java were renamed as Java SE, Java EE, and Java ME. Java is an object-oriented programming language. Java is a combination of the features of C and C++. It has inherited its features from C and object-oriented programming feature from C++.

Interview questions on Java Core:-

Download Core Java interview questions PDF

Core Java interview questions

Access specifiers in java are the keywords which define the access scope of the function. It can be used before a class or a method. There are basically 4 types of access specifiers in java: –
  • Public: – class, methods, and fields are accessible from anywhere.
  • Protected: – methods and fields are accessed from the same class to which they belong. Even from the subclass and class from the same package. Any outside class cannot access the methods and fields.
  • Default: – only from the same package, the methods and fields be accessed and not from the outside package.
  • Private: – the methods and fields can be only accessed from the same class to which they belong.

Java use garbage collection which is performed automatically in Java to free the memory space from unused objects automatically. It is used to identify and dispose those objects that are no longer needed for the application. In other languages like C and C++ you must perform garbage collection by yourself to manage the memory, it means Java provides good memory management.

The major features of Java are listed below: –

  • Object-oriented: – Java language is based on object-oriented programming. In this, the class and the methods describe the state and behavior of an object. The programming is done by relating a problem with the real world object.
  • Portable: – the conversion of java program into Java bytecodes take place. This helps in running the program in any environment or platform without any dependency.
  • Platform independent: – java ensures “write once run anywhere” as its programs can be run on multiple platforms like- Windows, Mac, Sun Solaris, Linux, etc.
  • Robust: – java’s strong memory due to no pointer allocations, make it robust. The memory leaks are prohibited with the help of automatic garbage collection in java.
  • Interpreted: – the java code is converted into bytecodes by the java compiler which is then interpreted and executed by the Java interpreter or a just-in-time compiler (JIT).
Following are some of the differences between array list and vectors in java: –
  • An array list is not synchronized, whereas a vector is synchronized.
  • An array list works fast, whereas a vector does not.
  • There is an increase of 50% in the array size whenever any element is inserted inside the array list, whereas vector defaults to doubling the size of its array.
  • The increment size is not defined in an array list, whereas in vector it is defined.
  • Only iterators can be used in an array list for traversing an array, whereas vectors can use both enumeration and iterators for traversing an array.