Java Language Fundamentals ---Java certification
Which of these are legal identifiers. Select the three correct answers.
1. number_1
2. number_a
3. $1234
4. -volatile
Which of these are not legal identifiers. Select the four correct answers.
1. 1alpha
2. _abcd
3. xy+abc
4. transient
5. account-num
6. very_long_name
Which of the following are keywords in Java. Select the two correct answers.
1. friend
2. NULL
3. implement
4. synchronized
5. throws
Which of the following are Java keywords. Select the four correct answers.
1. super
2. strictfp
3. void
4. synchronize
5. instanceof
Which of these are Java keywords. Select the five correct answers
1. TRUE
2. volatile
3. transient
4. native
5. interface
6. then
7. new
Using up to four characters, write the Java representation of octal literal 6.
Using up to four characters, write the Java representation of integer literal 3 in hexadecimal.
Using up to four characters, write the Java representation of integer literal 10 in hexadecimal.
What is the minimum value of char type. Select the one correct answer.
1. 0
2. -215
3. -28
4. -215 - 1
5. -216
6. -216 - 1
How many bytes are used to represent the primitive data type int in Java. Select the one correct answer.
1. 2
2. 4
3. 8
4. 1
5. The number of bytes to represent an int is compiler dependent.
What is the legal range of values for a variable declared as a byte. Select the one correct answer.
1. 0 to 256
2. 0 to 255
3. -128 to 127
4. -128 to 128
5. -127 to 128
6. -215 to 215 - 1
The width in bits of double primitive type in Java is --. Select the one correct answer.
1. The width of double is platform dependent
2. 64
3. 128
4. 8
5. 4
What would happen when the following is compiled and executed. Select the one correct answer.
public class Compare {
public static void main(String args[]) {
int x = 10, y;
if(x < 10)
y = 1;
if(x>= 10) y = 2;
System.out.println("y is " + y);
}
}
1. The program compiles and prints y is 0 when executed.
2. The program compiles and prints y is 1 when executed.
3. The program compiles and prints y is 2 when executed.
4. The program does not compile complaining about y not being initialized.
5. The program throws a runtime exception.
What would happen when the following is compiled and executed. Select the one correct answer.
class example {
int x;
int y;
String name;
public static void main(String args[]) {
example pnt = new example();
System.out.println("pnt is " + pnt.name +
" " + pnt.x + " " + pnt.y);
}
}
1. The program does not compile because x, y and name are not initialized.
2. The program throws a runtime exception as x, y, and name are used before initialization.
3. The program prints pnt is 0 0.
4. The program prints pnt is null 0 0.
5. The program prints pnt is NULL false false
The initial value of an instance variable of type String that is not explicitly initialized in the program is --. Select the one correct answer.
1. null
2. ""
3. NULL
4. 0
5. The instance variable must be explicitly assigned.
The initial value of a local variable of type String that is not explicitly initialized and which is defined in a member function of a class. Select the one correct answer.
1. null
2. ""
3. NULL
4. 0
5. The local variable must be explicitly assigned.
Which of the following are legal Java programs. Select the four correct answers.
1. // The comments come before the package
package pkg;
import java.awt.*;
class C{}
2. package pkg;
import java.awt.*;
class C{}
3. package pkg1;
package pkg2;
import java.awt.*;
class C{}
4. package pkg;
import java.awt.*;
5. import java.awt.*;
class C{}
6. import java.awt.*;
package pkg;
class C {}
Which of the following statements are correct. Select the four correct answers.
1. A Java program must have a package statement.
2. A package statement if present must be the first statement of the program (barring any comments).
3. If a Java program defines both a package and import statement, then the import statement must come before the package statement.
4. An empty file is a valid source file.
5. A Java file without any class or interface definitions can also be compiled.
6. If an import statement is present, it must appear before any class or interface definitions.
What would be the results of compiling and running the following class. Select the one correct answer.
class test {
public static void main() {
System.out.println("test");
}
}
1. The program does not compile as there is no main method defined.
2. The program compiles and runs generating an output of "test"
3. The program compiles and runs but does not generate any output.
4. The program compiles but does not run.
Which of these are valid declarations for the main method? Select the one correct answer.
1. public void main();
2. public static void main(String args[]);
3. static public void main(String);
4. public static void main(String );
5. public static int main(String args[]);
Which of the following are valid declarations for the main method. Select the three correct answers.
1. public static void main(String args[]);
2. public static void main(String []args);
3. final static public void main (String args[]);
4. public static int main(String args[]);
5. public static abstract void main(String args[]);
What happens when the following program is compiled and executed with the command - java test. Select the one correct answer.
class test {
public static void main(String args[]) {
if(args.length > 0)
System.out.println(args.length);
}
}
1. The program compiles and runs but does not print anything.
2. The program compiles and runs and prints 0
3. The program compiles and runs and prints 1
4. The program compiles and runs and prints 2
5. The program does not compile.
What is the result of compiling and running this program? Select the one correct answer.
public class test {
public static void main(String args[]) {
int i, j;
int k = 0;
j = 2;
k = j = i = 1;
System.out.println(k);
}
}
1. The program does not compile as k is being read without being initialized.
2. The program does not compile because of the statement k = j = i = 1;
3. The program compiles and runs printing 0.
4. The program compiles and runs printing 1.
5. The program compiles and runs printing 2.
What gets printed on the standard output when the class below is compiled and executed by entering "java test lets see what happens". Select the one correct answer.
public class test {
public static void main(String args[]) {
System.out.println(args[0]+" "+args[args.length-1]);
}
}
1. The program will throw an ArrayIndexOutOfBounds exception.
2. The program will print "java test"
3. The program will print "java happens";
4. The program will print "test happens"
5. The program will print "lets happens"
What gets printed on the standard output when the class below is compiled and executed by entering "java test lets see what happens". Select the one correct answer.
public class test {
public static void main(String args[]) {
System.out.println(args[0]+" "+args[args.length]);
}
}
1. The program will throw an ArrayIndexOutOfBounds exception.
2. The program will print "java test"
3. The program will print "java happens";
4. The program will print "test happens"
5. The program will print "lets happens"
What all gets printed on the standard output when the class below is compiled and executed by entering "java test lets see what happens". Select the two correct answers.
public class test {
public static void main(String args[]) {
System.out.println(args[0]+" "+args.length);
}
}
1. java
2. test
3. lets
4. 3
5. 4
6. 5
7. 6
What happens when the following program is compiled and run. Select the one correct answer.
public class example {
int i = 0;
public static void main(String args[]) {
int i = 1;
i = change_i(i);
System.out.println(i);
}
public static int change_i(int i) {
i = 2;
i *= 2;
return i;
}
}
1. The program does not compile.
2. The program prints 0.
3. The program prints 1.
4. The program prints 2.
5. The program prints 4.
What happens when the following program is compiled and run. Select the one correct answer.
public class example {
int i = 0;
public static void main(String args[]) {
int i = 1;
change_i(i);
System.out.println(i);
}
public static void change_i(int i) {
i = 2;
i *= 2;
}
}
1. The program does not compile.
2. The program prints 0.
3. The program prints 1.
4. The program prints 2.
5. The program prints 4.
What happens when the following program is compiled and run. Select the one correct answer.
public class example {
int i[] = {0};
public static void main(String args[]) {
int i[] = {1};
change_i(i);
System.out.println(i[0]);
}
public static void change_i(int i[]) {
i[0] = 2;
i[0] *= 2;
}
}
1. The program does not compile.
2. The program prints 0.
3. The program prints 1.
4. The program prints 2.
5. The program prints 4.
What happens when the following program is compiled and run. Select the one correct answer.
public class example {
int i[] = {0};
public static void main(String args[]) {
int i[] = {1};
change_i(i);
System.out.println(i[0]);
}
public static void change_i(int i[]) {
int j[] = {2};
i = j;
}
}
1. The program does not compile.
2. The program prints 0.
3. The program prints 1.
4. The program prints 2.
5. The program prints 4.
No comments:
Post a Comment