Introduction to Java

Fill in the blanks with the correct words:

  1. The int data type takes four bytes of storage.
  2. ‘A’ is a character constant.
  3. float a = 45.34; is a/an initialization statement.
  4. The output of 20 % 6 in Java will be 2.
  5. The do-while is an exit-controlled loop.

State whether True or False. Correct the false statement(s):

  1. In Java, a class is a capsule of data members and member functions. TRUE
  2. To run a Java program, double-click the compiled class. FALSE
    (Right-click the class icon and click void main() to run a Java program.)
  3. A variable name can start with a digit. FALSE
    (A variable name can start with a letter/underscore/dollar character.)
  4. The selection statements in Java are if and switch. TRUE
  5. The while loop is executed at least once. FALSE
    (The do-while loop is executed at least once.)

Choose the correct option:

  1. Which data type is used to store a whole number?
    a) float
    b) int
    c) double
    d) long double
  2. Which of these is an invalid String constant?
    a) “9”
    b) “Hello”
    c) ‘9’
    d) “*****”
  3. In the switch statement, if the value does not match any case label, then:
    a) Statements after break are executed
    b) Statements in the default case are executed
    c) An error occurs
    d) None of these
  4. Which of the following is a conditional statement?
    a) for
    b) while
    c) if
    d) do-while
  5. Which of these is not a valid initialization?
    a) int a = 12;
    b) float b = 34.6
    c) char a = ‘A’;
    d) String s = ‘Hello’;

Answer the following:

  1. What do you understand by object-oriented programming?
    An object-oriented programming is a different and modern approach to programming that is based on the fundamental concept of objects.
  2. What is a class in Java? What is it composed of?
    A class is a collection of similar objects. It is composed of properties and behavior.
  3. What is a method? Explain its general format.
    A method/function is a set of code that can be used at different points in the program. Following is its general format:

    <access specifier> <return type> <method name>(formal parameter list)
        //body of the method
  4. What do you understand by data type? List the data types in Java.
    Data types help decide how many bytes a variable will take for storage, and the range of values it can store. Following is the list of data types in Java: byte, short, int, long, float, double, char, boolean.
  5. Name the three looping statements in Java. Write their syntax.
    The three looping statements in Java are: while loop, do-while loop and for loop.
    Syntax of for loop:

    for(initialization; condition; increment/update){

    Syntax of while loop:


    Syntax of do-while loop:


1 thought on “Introduction to Java”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: