JVM Interview Questions & Answers

5 avg. rating (100% score) - 2 votes

JVM Interview Questions & Answers

Searching for jobs know a day has turned out to be very difficult that searching itself becomes a job. Not only preparing for the interview one must know where to apply for appropriate job. Here in www.wisdomjobs.com to avoid such difficulty and save your precious time we have provided a complete details of interview question and answers in our site. To clear the interview, one must prepare well for the interview. There are many leading companies that offer jobs in various position like Java Virtual Machine Developer, Llvm Compiler Engineer, Software Quality Development Engineer many other roles too. To get the complete details about JVM (java virtual Machine) jobsJVM (java virtual Machine) Interview Question and Answers and different kind of roles visit our site www.wisdomjobs.com.

JVM Interview Questions

JVM Interview Questions
    1. Question 1. What Is A Jvm?

      Answer :

      JVM is Java Virtual Machine which is a run time environment for the compiled java class files.

    2. Question 2. Are Jvm's Platform Independent?

      Answer :

      JVM's are not platform independent. JVM's are platform specific run time implementation provided by the vendor.

    3. Question 3. What Is The Difference Between A Jdk And A Jvm?

      Answer :

      JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.

    4. Question 4. Is Jvm A Compiler Or An Interpreter?

      Answer :

      Interpreter.

    5. Question 5. How Can I Write A Program That Takes Command Line Input?

      Answer :

      Java programs that take input from the command line declare a special static method called main, which takes aString array as an argument and returns void. The example program below loops through any arguments passed to the program on the command line and lists their values.

    6. Question 6. What Does Public Static Void Main(string[]) Mean?

      Answer :

      This is a special static method signature that is used to run Java programs from a command line interface (CLI). There is nothing special about the method itself, it is a standard Java method, but the Java interpreter is designed to call this method when a class reference is given on the command line, as below.

    7. Question 7. Why Are Command Line Arguments Passed As A String?

      Answer :

      Command line arguments are passed to the application's main method by the Java runtime system before theapplication class or any supporting objects are instantiated. It would be much more complex to define and construct arbitrary object types to pass to the main method and primitive values alone are not versatile enough to provide the range of input data that strings can. String arguments can be parsed for primitive values and can also be used for arbitrary text input, file and URL references.

    8. Question 8. Why Doesn't The Main Method Throw An Error With No Arguments?

      Answer :

      When you invoke the Java Virtual Machine on a class without any arguments, the class' main method receives aString array of zero length. Thus, the method signature is fulfilled. Provided the main method does not make any reference to elements in the array, or checks the array length before doing so, no exception will occur.

    9. Question 9. Why Do We Only Use The Main Method To Start A Program?

      Answer :

      The entry point method main is used to the provide a standard convention for starting Java programs. The choice of the method name is somewhat arbitrary, but is partly designed to avoid clashes with the Thread start() andRunnable run() methods, for example.

    10. Question 10. Can The Main Method Be Overloaded?

      Answer :

      Yes, any Java method can be overloaded, provided there is no final method with the same signature already. The Java interpreter will only invoke the standard entry point signature for the main method, with a string array argument, but your application can call its own main method as required.

    11. Question 11. Can The Main Method Be Declared Final?

      Answer :

      Yes, the static void main(String[]) method can be declared final.

    12. Question 12. I Get An Exception If I Remove The Static Modifier From Main?

      Answer :

      The static void main(String[]) method is a basic convention of the Java programming language that provides an entry point into the runtime system. The main method must be declared static because no objects exist when you first invoke the Java Virtual Machine (JVM), so there are no references to instance methods. The JVM creates the initial runtime environment in which this static method can be called, if you remove the static modifier, it will throw aNoSuchMethodException.

    13. Question 13. How Can The Static Main Method Use Instance Variables?

      Answer :

      For very simple programs it is possible to write a main method that only uses static variables and methods. For more complex systems, the main method is used to create an instance of itself, or another primary class, as the basis of the application. The primary application object reference uses instance methods to create and interact with other objects, do the work and return when the application terminates.
      public class SimpleClass {
      public void doSomething() {
      // Instance method statements
      }
      public static main(final String[] args) {
      SimpleClass instance = new SimpleClass();
      instance.doSomething();
      }
      }

    14. Question 14. Main Method From Another Class?

      Answer :

      Yes, the main method can be called from a separate class. First you must prepare the string array of arguments to pass to the method, then call the method through a static reference to the host class, MaxFactors in the example below.
      String[] arguments = new String[] {"123"};
      MaxFactors.main(arguments);

    15. Question 15. What If The Main Method Is Declared As Private?

      Answer :

      The program compiles properly but at runtime it will give “Main method not public.” message.

    16. Question 16. What Is Meant By Pass By Reference And Pass By Value In Java?

      Answer :

      Pass by reference means, passing the address itself rather than passing the value. Pass by value means passing a copy of the value.

    17. Question 17. If You're Overriding The Method Equals() Of An Object, Which Other Method You Might Also Consider?

      Answer :

      hashCode()

    18. Question 18. What Gives Java It's "write Once And Run Anywhere" Nature?

      Answer :

      All Java programs are compiled into class files that contain bytecodes. These byte codes can be run in any platform and hence java is said to be platform independent.

    19. Question 19. Expain The Reason For Each Keyword Of Public Static Void Main(string Args[])?

      Answer :

      public- main(..) is the first method called by java environment when a program is executed so it has to accessible from java environment. Hence the access specifier has to be public.

      static: Java environment should be able to call this method without creating an instance of the class , so this method must be declared as static.

      void: main does not return anything so the return type must be void

      The argument String indicates the argument type which is given at the command line and arg is an array for string given during command line.

    20. Question 20. What If I Do Not Provide The String Array As The Argument To The Method?

      Answer :

      Program compiles. But at runtime throws an error “NoSuchMethodError”.

    21. Question 21. Why Oracle Type 4 Driver Is Named As Oracle Thin Driver?

      Answer :

      Oracle provides a Type 4 JDBC driver, referred to as the Oracle “thin” driver. This driver includes its own implementation of a TCP/IP version of Oracle’s Net8 written entirely in Java, so it is platform independent, can be downloaded to a browser at runtime, and does not require any Oracle software on the client side. This driver requires a TCP/IP listener on the server side, and the client connection string uses the TCP/IP port address, not the TNSNAMES entry for the database name.

    22. Question 22. What Is The Java Api?

      Answer :

      The Java API is a large collection of ready-made software components that provide many useful capabilities, such as graphical user interface (GUI) widgets.

    23. Question 23. What Is The Gregoriancalendar Class?

      Answer :

      The GregorianCalendar provides support for traditional Western calendars.

    24. Question 24. What Is The Resourcebundle Class?

      Answer :

      The ResourceBundle class is used to store locale-specific resources that can be loaded by a program to tailor the program’s appearance to the particular locale in which it is being run.

    25. Question 25. Why There Are No Global Variables In Java?

      Answer :

      Global variables are globally accessible. Java does not support globally accessible variables due to following reasons:
      • The global variables breaks the referential transparency.
      • Global variables creates collisions in namespace.

    26. Question 26. What Is The Simpletimezone Class?

      Answer :

      The SimpleTimeZone class provides support for a Gregorian calendar.

    27. Question 27. What Is The Difference Between A While Statement And A Do Statement?

      Answer :

      A while statement (pre test) checks at the beginning of a loop to see whether the next loop iteration should occur. A do while statement (post test) checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the loop body at least once.

    28. Question 28. What Is The Locale Class?

      Answer :

      The Locale class is used to tailor a program output to the conventions of a particular geographic, political, or cultural region.

    29. Question 29. Describe The Principles Of Oops.

      Answer :

      There are three main principals of oops which are called Polymorphism, Inheritance and Encapsulation.

    30. Question 30. Explain The Inheritance Principle.

      Answer :

      Inheritance is the process by which one object acquires the properties of another object. Inheritance allows well-tested procedures to be reused and enables changes to make once and have effect in all relevant places

    31. Question 31. Can A Method Be Static And Synchronized?

      Answer :

      A static method can be synchronized. If you do so, the JVM will obtain a lock on the java.lang.
      Class instance associated with the object. It is similar to saying:
      synchronized(XYZ.class) {
      }

    32. Question 32. What Is Phantom Memory?

      Answer :

      Phantom memory is false memory. Memory that does not exist in reality.

    33. Question 33. Does Jvm Maintain A Cache By Itself? Does The Jvm Allocate Objects In Heap? Is This The Os Heap Or The Heap Maintained By The Jvm? Why

      Answer :

      Yes, the JVM maintains a cache by itself. It creates the Objects on the HEAP, but references to those objects are on the STACK.

    34. Question 34. What Is Reflection Api? How Are They Implemented?

      Answer :

      Reflection is the process of introspecting the features and state of a class at runtime and dynamically manipulate at run time. This is supported using Reflection API with built-in classes like Class, Method, Fields, Constructors etc. Example: Using Java Reflection API we can get the class name, by using the getName method.

    35. Question 35. What Is Data Encapsulation?

      Answer :

      Encapsulation may be used by creating ‘get’ and ’set’ methods in a class (JAVABEAN) which are used to access the fields of the object. Typically the fields are made private while the get and set methods are public. Encapsulation can be used to validate the data that is to be stored, to do calculations on data that is stored in a field or fields, or for use in introspection (often the case when using javabeans in Struts, for instance). Wrapping of data and function into a single unit is called as data encapsulation. Encapsulation is nothing but wrapping up the data and associated methods into a single unit in such a way that data can be accessed with the help of associated methods. Encapsulation provides data security. It is nothing but data hiding.

    36. Question 36. Explain Working Of Java Virtual Machine (jvm)?

      Answer :

      JVM is an abstract computing machine like any other real computing machine which first converts .java file into .class file by using Compiler (.class is nothing but byte code file.) and Interpreter reads byte codes.

    37. Question 37. How Can I Swap Two Variables Without Using A Third Variable?

      Answer :

      Add two variables and assign the value into First variable. Subtract the Second value with the result Value. and assign to Second variable. Subtract the Result of First Variable With Result of Second Variable and Assign to First Variable. Example:
      int a=5,b=10;a=a+b; b=a-b; a=a-b;

    38. Question 38. Can I Have Multiple Main Methods In The Same Class?

      Answer :

      We can have multiple overloaded main methods but there can be only one main method with the following signature :
      public static void main(String[] args) {}
      No the program fails to compile. The compiler says that the main method is already defined in the class.

    39. Question 39. When Is Static Variable Loaded? Is It At Compile Time Or Runtime? When Exactly A Static Block Is Loaded In Java?

      Answer :

      Static variable are loaded when classloader brings the class to the JVM. It is not necessary that an object has to be created. Static variables will be allocated memory space when they have been loaded. The code in a static block is loaded/executed only once i.e. when the class is first initialized. A class can have any number of static blocks. Static block is not member of a class, they do not have a return statement and they cannot be called directly. Cannot contain this or super. They are primarily used to initialize static fields.

    40. Question 40. Can An Application Have Multiple Classes Having Main Method?

      Answer :

      Yes. While starting the application we mention the class name to be run. The JVM will look for the main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.

    41. Question 41. How Can One Prove That The Array Is Not Null But Empty?

      Answer :

      Print array.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print array.length.

    42. Question 42. What Is The First Argument Of The String Array In Main Method?

      Answer :

      The String array is empty. It does not have any element. This is unlike C/C++ where the first element by default is the program name. If we do not provide any arguments on the command line, then the String array of main method will be empty but not null.

    43. Question 43. What Do You Understand By Casting In Java Language? What Are The Types Of Casting?

      Answer :

      The process of converting one data type to another is called Casting. There are two types of casting in Java; these are implicit casting and explicit casting.

    44. Question 44. What Do You Understand By Numeric Promotion?

      Answer :

      The Numeric promotion is the conversion of a smaller numeric type to a larger numeric type, so that integral and floating-point operations may take place. In the numerical promotion process the byte, char, and short values are converted to int values. The int values are also converted to long values, if necessary. The long and float values are converted to double values, as required.

    45. Question 45. What Do You Understand By A Variable?

      Answer :

      Variable is a named memory location that can be easily referred in the program. The variable is used to hold the data and it can be changed during the course of the execution of the program.

    46. Question 46. Explain The Encapsulation Principle.

      Answer :

      Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. Objects allow procedures to be encapsulated with their data to reduce potential interference. One way to think about encapsulation is as a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper.

    47. Question 47. What Type Of Parameter Passing Does Java Support?

      Answer :

      In Java the arguments (primitives and objects) are always passed by value. With objects, the object reference itself is passed by value and so both the original reference and parameter copy both refer to the same object.

    48. Question 48. What Is The Difference Between Declaring A Variable And Defining A Variable?

      Answer :

      In declaration we only mention the type of the variable and its name without initializing it. Defining means declaration + initialization. E.g. String s; is just a declaration while String s = new String (”bob”); Or String s = “bob”; are both definitions.

    49. Question 49. What If I Write Static Public Void Instead Of Public Static Void?

      Answer :

      Program compiles and runs properly.

    50. Question 50. How Does Java Handle Integer Overflows And Underflows?

      Answer :

      It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.

    51. Question 51. What Is The Difference Between The Boolean & Operator And The && Operator?

      Answer :

      If an expression involving the boolean & operator is evaluated, both operands are evaluated, whereas the && operator is a short cut operator. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. If the first operand evaluates to false, the evaluation of the second operand is skipped.

    52. Question 52. What Is A Static Method?

      Answer :

      A static variable is associated with the class as a whole rather than with specific instances of a class. Each object will share a common copy of the static variables i.e. there is only one copy per class, no matter how many objects are created from it. Class variables or static variables are declared with the static keyword in a class. These are declared outside a class and stored in static memory. Class variables are mostly used for constants. Static variables are always called by the class name. This variable is created when the program starts and gets destroyed when the programs stops. The scope of the class variable is same an instance variable. Its initial value is same as instance variable and gets a default value when its not initialized corresponding to the data type. Similarly, a static method is a method that belongs to the class rather than any object of the class and doesn’t apply to an object or even require that any objects of the class have been instantiated.

      Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object. A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final. However, you can’t override a static method with a non-static method. In other words, you can’t change a static method into an instance method in a subclass.

      Non-static variables take on unique values with each object instance.

    53. Question 53. Name Primitive Java Types.

      Answer :

      The 8 primitive types are byte, char, short, int, long, float, double, and boolean.

    54. Question 54. Which Class Is The Superclass Of Every Class?

      Answer :

      Object.

    55. Question 55. What Are Different Types Of Access Modifiers?

      Answer :

      Access specifiers are keywords that determine the type of access to the member of a class. These keywords are for allowing privileges to parts of a program such as functions and variables. These are:
      • Public : accessible to all classes
      • Protected : accessible to the classes within the same package and any subclasses.
      • Private : accessible only to the class to which they belong
      • Default : accessible to the class to which they belong and to subclasses within the same package.

    56. Question 56. What Do You Understand By Downcasting?

      Answer :

      The process of Downcasting refers to the casting from a general to a more specific type, i.e. casting down the hierarchy

    57. Question 57. What Is The Java Virtual Machine (jvm)?

      Answer :

      The Java Virtual Machine is software that can be ported onto various hardware-based platforms

    58. Question 58. What Is Explicit Casting?

      Answer :

      Explicit casting in the process in which the complier are specifically informed to about transforming the object.
      Example
      long i = 700.20;
      int j = (int) i; //Explicit casting.

    59. Question 59. In System.out.println(), What Is System, Out And Println?

      Answer :

      System is a predefined final class, out is a PrintStream object and println is a built-in overloaded method in the out object.

    60. Question 60. What Is A Native Method?

      Answer :

      A native method is a method that is implemented in a language other than Java.

Jvm Tutorial

Jvm Practice Tests

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JVM Tutorial