Programming





Interview Question and Answers Part 1

Interview Question and Answers Part 1

by | 31-Mar-2020
Java

Tags:

Share: 


  1. Can a Java interpreter be used for the execution of the source code?

Yes

  1. On successful compilation, a file with the .class extension is created?

Yes

  1. Can a Java source code be written in Notepad editor?

Yes

  1. Is a Java Program enclosed in a class definition?

Yes

  1. What is a compilation unit?

A compilation unit is a Java Source Code file.

  1. Is Empty .java file a valid source file?

Yes, an empty .java file is a perfectly valid source file.

  1. Can a .java file contain more than one java class?

Yes, a .java file contains more than one java class, provided at the most one of them is a public class.

  1. Is Java Virtual Machine (JVM) a compiler or an interpreter?

Interpreter

  1. What is the difference between JVM Spec, JVM Implementation, and JVM Runtime?

The JVM spec is a blueprint for the JVM generated and owned by Sun Microsystems, now Oracle.

The JVM implementation is the actual implementation of the spec by a vendor.

The JVM Runtime is the actual running instance of a JVM implementation.

  1. What is a BDK?

BDK (Bean Development Kit) is a tool that enables us to create, configure and connect a set of Beans and be used to test Beans without writing code.

  1. What is the use of bin and lib in JDK?

bin contains tools such as javac, applet viewer, awt tool etc., whereas lib contains packages and variables.

  1. What are the two parts in executing a Java program and their purposes?

Two parts in executing a Java program are:

Java Compiler is used for the compilation of a Java program.

Java Interpreter is used for executing the compiled program

  1. What is the difference between PATH and CLASSPATH?

PATH is used for setting up an environment for the operating systems. The operating system will look in this PATH for executables.

CLASSPATH is used for setting up the environment for Java. Java will use the classpath to find compiled classes.

  1. What environment variables do I need to set on my machine in order to be able to run Java programs?

You’ll need to set CLASSPATH and PATH in order to be able to run Java programs.

  1. What are Java Beans?

JavaBeans is a portable, platform-independent component model written in the Java programming language. It enables developers to write reusable components once and run them anywhere-benefiting from the platform-independent power of Java technology. JavaBeans are Java classes which adhere to certain coding conventions:

  • Implements java.io.Serializable interface
  • Provides no-argument constructor
  • Provides getter and setter methods for accessing it’s properties
  1. What are the rules for defining a Java Bean class?

Must have setter & getters methods.

Must declare a public default constructor.

Implements Serializable interface.

  1. What is the difference between POJO and java bean class?

A Bean is a java class that has getter and setter methods without any logic in it. It is used for holding data.

A Java class can have everything a java Bean has as well as some logic inside it.

A bean class can be a POJO class but a POJO can’t be a Java Bean class.

  1. How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters?

Unicode requires 16 bits and ASCII requires 7 bits. Although the ASCII characters use only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18-bit patterns. UTF-16 uses 16-bit and larger bit patterns.

  1. What are the requirements of every Java application?

A class and the main( ) method declaration is required. The main method tells the application starting point.

  1. What is the return type of program’s main( ) method?

Void is the return type of the main method.

";"";"Here is a list of one liner Question and Answers which will be helpful in interviews.";"Administrator";"Java";"2020-03-30 00:00:00+00";"''" 32;"Interview Question and Answers Part 3";"
  1. What is the difference between & and && or | and ||?

In the Bitwise operator, if the first operator evaluates to true in OR (|) and False in AND (&) then the second expression will also be evaluated. But, in Logical Operator, if the first operand evaluates to true in OR (|) and False in AND (&) then the second expression will not be evaluated.

  1. What is the difference between the >> and >>> operators?

The >> operator is also called Arithmetic Shift Right which carries a signed bit when shifting right. The >>> operator is also called a logical shift right which does not carry any signed bit.

  1. Can shift operators be applied to float types?

No, shift operators can be applied only to integer or long types

  1. What happens to the bits that fall off after shifting?

They are discarded.

  1. What values of the bits are shifted in after the shift?

In case of signed left shift >> the new bits are set to zero. But in case of signed right shift << it takes the value of most significant bit before the shift that is if the most significant bit before shift is 0 it will introduce 0, else if it is 1, it will introduce 1.

  1. What are operators and what are the various types of operators available in Java?

Operators are special symbols used in expressions. The following are the types of operators:

  • Arithmetic operators
  • Assignment operators
  • Increment & Decrement operators
  • Logical operators
  • Bitwise operators
  • Comparison/Relational operators
  • Conditional operators

 

  1. Can you write an if statement without else statement?

Yes

  1. Can you write else statement without if statement?

No

  1. What restrictions are placed on the values of each case of a switch statement?

During compilation, the values of each case of a switch statement must evaluate to a value that is an integer or compatible with an integer value.

  1. Can a for statement loop indefinitely?

Yes, for statement can loop indefinitely. Here’s the code: for(;;) ;

  1. What is the difference between a break statement and a continue statement?

A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.

  1. What is the difference between a do and a while loop?

A while loop checks at the beginning of a loop to see whether the next loop iteration should occur. A do-while statement checks at the end of a loop to see whether the next iteration of a loop should occur. A do loop will always execute at least once.

  1. What is meant by variable?

Variables are locations in memory that can hold values. Before assigning any value to a variable, it must be declared.

  1. What are the kinds of variables in Java? What are their uses?

Java has three kinds of variables namely:

Instance Variable: Local variables are used inside blocks as counters or in methods as temporary variables and are used to store information needed by a single method.

Local Variable: Instance variables are used to define attributes or the state of a particular object and are used to store information needed by multiple methods in the objects.

Class Variable: Class variables are global to a class and to all the instances of the class and are useful for communicating between different objects of all the same class or keeping track of global states.

  1. What is literal? How many types of literals are there?

A literal represents a value of a certain type. There are different types of literals namely number literals, character literals, boolean literals, string literals, etc.

  1. What is an array?

An array is an object that stores a list of homogeneous datatype elements.

  1. How do you declare an array?

Array variable indicates the type of object that the array holds. Ex:

int intArr[];

String stringArr[];

  1. Which of the following declares an array of string objects?
  2. String[ ] s;
  3. String [ ]s:
  4. String[ s];
  5. String s[ ];

a, b and d are the correct way of declaring an array.

  1. What is a static variable?

Static variables are shared by all instances of a class.

  1. What is final variable?

Final variable’s value cannot be changed. It becomes a constant.


Comments:


There are no comments.

Enter a new Comment:










Copyright Šprgrmmng. All rights reserved.