Java Interview Questions With Answers – Part 3

[1][2]3  –  Here’s part 3 of some Java Interview Questions. The level of questions is suitable for beginners as well advanced core Java programmers.  This part covers basics of Java as well as Java Datatypes.
Java-Datatype-Interview-Questions

The series includes more than 200 questions, so stay tuned for more.

Q21. What is the usage of “args[ ]”parameter in the following,

public static void main(String args[ ]) {}

A21. String args[ ] is an array of instances. Here, the args receives any command-line arguments. These arguments can be worked upon when the program is executed. For example,

          java SampleProgram.java arg1

Here, arg1 is argument one

Q22. What is System.out.println in the following sample program,

class Sample {
public static void main(String args[]) {
System.out.println("Our first Java Program!");
}

}


A22. Here,

  • System = predefined class
  • out = output stream
  • println = It is a method that  prints message, in this case it prints “Our first Java Program”

Q23.  Java programs are a collection of ________?

A23. Whitespace, identifiers, literals, comments, operators, separators, & keywords

Q24. What is Whitespace?

A24. Space, tab, or newline added to a Java program is known as whitespace.

Q25. Define Identifiers?

A25. Identifiers are the name given to a class, method and variables.
For example: temp, i, count1, count2 are all Identifiers.

Q26. Give examples of Literals in Java?
A26
.  Here are three examples showing floating-point, integer, and string literals:

  • 32.7
  • 10
  • Java is awesome!

Q27. Java 8 has added two new operators? Name it?

A 27. The two new operators added in Java 8 are,
1.) :: i.e. Double Colon
2.) Lambda Expressions

Q29. Explain the usage of Double Colon operator introduced in Java 8.

A29.  The :: i.e. double colon operator has been added in Java8, and used to create reference to a method or constructor.

Q30. List some Java Keywords?

A30.  Here are some Java keywords:
Boolean, break, int, float, extends, package, this, throws, void, native, volatile, transient, etc.

Q31. Is Java a Strongly Typed language?

A31. Yes

Q32. List all the primitive types of data (data type) in Java?

A32. Here are the primitive types of data in Java: boolean, byte, int, short, long, char, float, double

Q33. Name the smallest integer type?

A33.  Byte is the smallest integer type

Q34. Which one is a signed 16-bit type,
a.) int
b.) short
c.) long

A34.  short

Q35. Which one is a signed 32-bit type,
a.) int
b.) short
c.) long

A35. int

Q36. Which type is used for huge, whole numbers? For example, 178685726876
a.) int

b.) long
c.) short

A36.  Such huge numbers could only be handled by long type.

Q37. Name the two floating-point types?

A37.  The floating-point types are double and float.

Q38. When double-type is preferred over float-type?

A38.  When you need a large degree of precision and large-valued numbers, and then use double-type.
For example, transcendental math functions like sin( ), cos( ), and sqrt( ), return double values.

Double-type uses 64 bits to store a value, unlike float, which uses only 32 bits to store a value.

Q39. Are chars in C/C++ are same as chars in Java?

A39.  C/C++: char is a 8-bit type.

Java: char is a 16-bit type.

Q40. State the difference between chars in Java and char in C/C++?

A40. char in Java:

  • char is a 16-bit type in Java and uses Unicode, which is a unification of characters
    sets to represent characters.
  • Range from 0 to 65,536
  • No negative chars.

          char in C/C++:

  • char is a 8-bit type in  C/C++ and the characters are represented by ASCII,
  • Range from -128 to 127 or 0 to 255

[1][2]3

thegenericwhiz@gmail.com'
Editorial Staff at Generic Whiz.

Comments

comments

thegenericwhiz@gmail.com'

GW Editorial Staff

Editorial Staff at Generic Whiz.

Leave a Reply

Your email address will not be published. Required fields are marked *