Introduction to Java
Basic Java programming concepts covering compilation, syntax, operators, arrays, classes, and access modifiers
Questions
Java does not support __________.
- arrays
- multithreading
- pointers
- constructors
Which of the following commands is used to compile a java program(.java extension file)?
- java
- javac
- jvm
- jcc
Which of the following is a part of class definition?
- Variables
- Methods
- Constructors
- All of the above
After compilation of file Myprog.java, a new file is created with the name ___________.
- Myprog.obj
- Myprog.cls
- Myprog.class
- Myprog.exe
Which of the following statements is correct with respect to byte code?
A. Byte code is generated by Java compiler.
B. Byte code is generated by Java virtual machine.
- Only A
- Only B
- Both A and B
- Neither A nor B
Which of the following is true regarding the following statement in Java?
student.result(marks);
- student is the name of a structure.
- result is the name of a method.
- result is a form of a datatype.
- student is the name of a method.
Which operator is used for the bitwise XOR in Java?
- ~
- &
- |
- ^
What is the value of the statement 23>>2 in Java?
- 5
- 6
- 7
- 8
Which of the following array declarations is not correct?
- Student s[];
- Student s[]=new Student[4];
- Student s[][]=new Student[5][];
- Student s[][]=new Student[5][3];
Match the following:
| 1. int | A. 2 bytes |
| 2. short | B. 1 byte |
| 3. long | C. 4 bytes |
| 4. byte | D. 8 bytes |
- 1 - C, 2 - A, 3 - B, 4 - D
- 1 - C, 2 - A, 3 - D, 4 - B
- 1 - A, 2 - C, 3 - D, 4 - B
- 1 - C, 2 - D, 3 - A, 4 - B
What will be the file name for the following program?
class Student
{
public static void main(String args[])
{
System.out.println(“Hello Student”);
}
}
- Any file name
- Student.class
- Student.java
- Student
Which of the following is the correct format of a Java program?
-
java class abc { Public static void main(String args[]) {……………} } -
java class abc { public Static void main(String args[]) {……………} } -
java class abc { Public static void Main(String args[]) {……………} } -
java class abc { public static void main(String args[]) {……………} }
Which of the following is the correct syntax of switch statement in Java?
- switch(exp)
{
case value1: statement_1;
case value2: statement_2;
……………………
case valuen: statement_n;
[default: statements ;]
} - switch(exp)
{
case value1: statement_1;
case value2: statement_2;
……………………
case valuen: statement_n;
default: statements ;
} - switch(exp)
{
case value1: statement_1;
case value2: statement_2;
……………………
case valuen: statement_n;
} - switch(exp)
{
case value1; statement_1;
case value2; statement_2;
……………………
case valuen; statement_n;
[default: statements ;]
}
In Java, final keyword gives the same result as ________ declaration in C++.
- throw
- cout
- const
- cin
If there is a protected method within the Public class, then which of the following statements is correct?
- Protected method does not access the public method.
- Method is accessible from inside a class and a subclasses.
- Protected method is not allowed within the Public class.
- Method is accessible from inside the class and all the classes defined in the same package, where the class is defined itself.