Friday, 6 June 2014

Java interview questions and answers on basics

Posted by Charan Veera
Hey java is a modern object oriented language, which has been designed keeping the internet in mind. java has eliminated many problematic areas found in C++. This covers the interview questions on java language.





Java interview questions :

Describe a java source file ?

  • A java source file must have '.java' extension.
  • It  should have at-least one top-level,public class definition and any number of non-public class definitions. The file name should match the public class name.

Why does the main method need a static identifier ?

  • The main method needs a static identifier because static methods and members do not need an instance of their class to invoke them and main in the first method, which is invoked.

Will the program compile, if the main method does not have static identifier ?

  • It will compile. But the program cannot be executed.

How are Java objects passed to a method ?

  • In Java, both the primitive types and objects will be passed by value. During object passing, the object's reference will be copied.

What are native methods ?

  • Native methods are methods implemented in another programming language, such as C. The java native interface ( JNI ) is the API to invoke these native methods from a java class.

How are 'this and super' keyword used ?

  • 'this' keyword is used to refer to the current object instance. 'super' keyword is used to refer to the variables and methods of the superclass of the current object instance.

Can a Private method be static ?

  • Yes

Can a variable be an unsigned integer ?

  • No. In java all the data types are signed numeric numbers.

Which keywords are reserved ?

  • 'goto' and 'const' are the 2 reserved keywords in java.

What is the Bytecode ?

  • Each java program is converted into one or more class files. The content of the class file is a set of instructions called bytecode to be executed by Java Virtual Machine ( JVM ). JVM is an interpreter for bytecode. Java introduces bytecode to create Platform (hardware) independent program.

Which is the default parent class for a java class ?

  • java.lang.object . By default ( implicit ), all the java classes extend this class unless they have their own parent class. Also, the package java.lang is imported into all java files by default.

0 comments:

Post a Comment