0% found this document useful (0 votes)
24 views

Java Technical Aptitude Questions and Answers

sdfgh

Uploaded by

Ramesh k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Java Technical Aptitude Questions and Answers

sdfgh

Uploaded by

Ramesh k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

JAVA TECHNICAL APTITUDE QUESTIONS AND ANSWERS.

(Theory)

1) Which company started developing Java (as a Green Project)?

1. Microsoft
2. Oracle
3. Apple
4. Sun Microsystem
Answer

Correct Answer: 4

Sun Microsystem

2) Firstly Java was called __________ by James Gosling.

1. Greentalk
2. Oak
3. Java
4. Gosl
Answer

Correct Answer: 1

Greentalk

3) Java Interpreter is used for which purpose?

1. Compile Java program


2. Execute class file
3. Both 1 and 2
4. None of these
Answer
Correct Answer: 2

Execute class file

4) After compilation of a Java program which code generated?


1. Executable code (.exe)
2. Assembly code (.asm)
3. Object Code (.obj)
4. Byte Code (.class)
Answer

Correct Answer: 4

Byte Code (.class)

After compilation class file (Byte code) generated.

5) Which declarations are required in a Java program?

1. There should be a main function


2. There should be a class
3. There should be a class and a main function
4. None of these
Answer

Correct Answer: 3

There should be a class and a main function

6) What can be the return type of main method?


A) int B) char c) void D) float

1. Only A)
2. Only C)
3. Both A) and C)
4. All
Answer
Correct Answer: 2
Only C)
7) Which is not a valid type of variable?
1. Global variable
2. Local variable
3. Class variable
4. Instance variable
Answer

Correct Answer: 1

Global variable

8) Which is a primitive data type?

1. String
2. Character
3. Float
4. byte
Answer

Correct Answer: 4

byte

All primitive data types have their own classes, here String, Character and Float are classes but
byte is primitive data type.

9) Does Java provide the feature of Multi threading?

1. Yes
2. No
Answer

Yes

10) JRE stands for __________.

1. Java Running Environment


2. Java Run Time Environment
3. Java Runnable Environment
4. None of these
Answer

Correct Answer: 2

Java Run Time Environment

1) What will be the output of following program?


public class Prg {
    public static void main(String args[]){
        System.out.print('A' + 'B');
    }
}

1. AB
2. 195
3. 131
4. Error
Answer

Correct Answer: 3

131

Here, ‘A’ and ‘B’ are not strings they are characters. ‘A’ and ‘B’ will not concatenate. The
Unicode of the ‘A’ and ‘B’ will add. The Unicode of ‘A’ is 65 and ‘B’ is 66. Hence Output will
be 131.

2) What will be the output of following program ?


public class Prg {
    public static void main(String args[]){
        System.out.print("A" + "B" + 'A');
    }
}

1. ABA
2. AB65
3. Error
4. AB
Answer
Correct Answer: 1

ABA

If you try to concatenate any type of data like integer, character, float with string value, the result
will be a string. So 'A' will be concatenated with "AB" and answer will be "ABA".

3) What will be the output of following program?


public class Prg {
    public static void main(String args[]){
        System.out.print(20+ 1.34f + "A" + "B");
    }
}

1. 201.34AB

2. 201.34fAB

3. 21.34AB

4. Error
Answer

Correct Answer: 3

21.34AB

20 and 1.34f will be added and then 21.34 will be concatenated with “A” and “B”, hence output will
be 21.34AB.

4) What will be the output of following program?


public class Prg {
    public static void main(String[] args) {
        char [] str={'i','n','c','l','u','d','e','h','e','l','p'};
        System.out.println(str.toString());
    }
}

1. includehelp
2. Error
3. [C@19e0bfd (Memory Address)
4. NULL
Answer
Correct Answer: 3

[C@19e0bfd (Meory Address)

str is a character array, if you try to print str.toString() it will not converted to string because str
is an object of character array that will print an address in string format.

5) What will be the output of following program?


public class prg {
    public static void main(String[] args) {
        System.out.print("Hello");
        System.out.println("Guys!");
    }
}

1. HelloGuys!
2. Hello Guys!
3. Hello
 Guys!

4. Compile with a Warning


Answer

Correct Answer: 1

HelloGuys!

System.out.print () does not print new line after printing string,


whileSystem.out.println(); prints new line after printing string. Hence output will be
HelloGuys! and then new line.

6) What will be the output of following program?


public class prg {
    public static void main(String[] args) {
        char a=0x41;    //Unicode of 'A'
        char b=0x42;    //Unicode of 'B'
         
        System.out.print(a+"" + b+"");
        System.out.print("-");
        System.out.print(a+b);      
    }
}

1. AB-AB
2. AB-131
3. AB-ERROR
4. A B -131
 
Answer

Correct Answer: 2

AB-131

a+"" and b+"" will be converted into string, .toString() or +"" after variable or value converts
value into the string and a+b will be added because they are not converted into string. Hence
output will be AB-131.

7) What should be the name of java program file containing this program?
public class MyPrg
{
    public static void main(String args[])
    {
        System.out.print("IncludeHelp");
  
    }
}

1. MyPrg.class
2. MyPrg.java
3. MyPrg
4. Any file name with java extension
Answer

Correct Answer: 2

MyPrg.java

In this program class MyPrg is public, so we cannot take any file name, we must save this
program by MyPrg.java file name otherwise Compilation error is occurred.

8) What is byte code in Java?

1. It is another name for java source file that contain the information about the hardware.
2. It is a binary code generated by the Java Virtual Machine for operating system.
3. It is an intermediate code generated by the java compiler for Java Virtual Machine.
4. None of these
Answer

Correct Answer: 3

It is an intermediate code generated by the java compiler for Java Virtual Machine.

9) What is Garbage Collection (GC) in the Java?

1. It is a thread to free the memory of de-referenced objects automatically.


2. It is a method to collect the garbage values of variables.
3. It is a package included in program to free the memory occupied by objects.
4. None of these
Answer

Correct Answer: 1

It is a thread to free the memory of de-referenced objects automatically.

10) What will be the output of following program?


class Prg
{
    public static void main(String args[])
    {
        const int a=10;
        System.out.println(a);
  
    }
}

1. 10
2. a
3. Unprintable Character
4. Error
Answer

Correct Answer: 4

Error:
illegal start of expression.

JAVA does not support the const keyword, instead of const, final keyword is used.

11) What will be the output of following program?


public class prg {
    public static void main(String[] args) {
        System.out.println( (byte) 0xff);
    }
}

1. -1
2. 255
3. 65535
4. 0xff
Answer

Correct Answer: 1

-1

0xff is the maximum value of a byte. And in Decimal maximum value of a byte is -1.

12 What will be the output of following program?


public class prg {
    public static void main(String[] args) {
        System.out.println( (int)(char)(byte) 0xff);
    }
}

1. -1
2. 255
3. 65535
4. 0xff
Answer

Correct Answer: 3

65535

13 Which is the correct declaration of a Boolean variable?

1. boolean isAdult='false';
2. boolean isAdult=0;
3. boolean isAdult="false";
4. boolean isAdult=false;
 
 
Answer

Correct Answer: 4

boolean isAdult=false;

A boolean variable can store only true or false.

You might also like