Questions du site: www.geekinterview.com
What is the output of the following main program? public static void main(String[] args) { int x,y; a = 5; b = 1; while (a > 0) { a = a - 1; b = b * a; System.out.println(b); } }
-
55
24
24
24
0
-
5
12
12
24
24
-
4
12
24
24
0
- None of the Above
Command to execute a compiled java programs is
run
execute
javac
java
A method with name example() that has two integer arguments is declared as
public void example();
public void example(int x, y);
public void example(int x, int y);
public int example(x,y);
What is the output of the following program? public class example { public static void main(String args[]) { int x=0, y=2; do { x=++x; y--; } while(y>0); System.out.println(x); } }
0
1
2
Compilation Error
What is the output of the following piece of code? if(" String ".trim() == "String") System.out.println("Welcome"); else System.out.println("Good Bye");
The code will compile and print "Welcome"
The code will compile and print "Good Bye"
The code will cause a compiler error
None of the Above
Choose the correct statement from the given choice?
Arrays in Java are essentially objects
It is not possible to assign one array to another. Individual elements of array can however be assigned.
Array elements are indexed from 1 to size of array
If a method tries to access an array element beyond its range, a compile warning is generated.
Which of the following statements are true?
The return type for a method can be any Java type, including void
An important principal of object oriented programming is implementation hiding
When you perform mathematical calculations on the unlike data type, java will perform a implicit conversion to unify the types
All the Above
When you add a float, int and byte the result will be
float
int
byte
double
What will happen when the class below is complied?
public class Example
{
//char a = 'u000A';
}
Will not compile - complains on an invalid expression.
Will compile successfully but with a warning message.
Will complete successfully.
None of the Above
When you divide a number of type double by zero then the result will be
Zero
Double.NaN
Unpredictable
None of the Above
How can you ensure that the memory allocated by an object is freed?
By invoking the free method on the object
By calling system.gc() method
By setting all references to the object to new values (say null).
Garbage collection cannot be forced. The programmer cannot force the JVM to free the memory used by an object.
What is the base type of the array given below?
Color[] example = new Color[20];
Color
example
No base type
Both (A) and (B)
The 16 bit coding scheme employed in Java programming is
EDCDIC
UNICODE
ASCII
Hexadecimal
Consider the following piece of code byte x = 0; x += 1;
Results in x having the value 1.
Causes a compiler error.
Will require a cast (byte) before 1.
Will give syntax error.
What is the number of bytes used by Java primitive long?
The number of bytes is compiler dependent
2
4
8
Which of the function is used to convert String to Number in java program?
toNumber()
conString()
valueOf()
None of the Above
What is the output of the following code for exampleprint(1)?
static void exampleprint(int
inputitem)
{
if (inputitem == 0)
{
System.out.print("*");
}
else
{
System.out.print("[");
exampleprint(inputitem - 1);
System.out.print(",");
exampleprint(inputitem - 1);
System.out.println("]");
}
}
*,*,*
[*,*]
*
None of the Above
The Java interpreter is used for the execution of the source code.
True
False
On successful compilation a file with the .exe extension is created.
True
False
The Java Program is enclosed in a class definition.
True
False
Class and main() methods declarations are required for every Java application?
True
False
What output is displayed as the result of executing the
following statement?
System.out.println("// Looks like a comment.");
// Looks like a comment
The statement results in a compilation error
Looks like a comment
No output is displayed
In order for a source code file, containing the public class Test, to successfully compile, which of the following must be true?
It must have a package statement
It must be named Test.java
It must import java.lang
It must declare a public class named Test
Void is the return type of program’s main( ) method.
True
False
string array is the argument type of program’s main( ) method.
True
False
Consider the following program:
import myLibrary.*;
public class ShowSomeClass
{
// code for
the class...
}
What is the name of the java file containing this program?
myLibrary.java
ShowSomeClass.java
ShowSomeClass
ShowSomeClass.class
Any file name with the java suffix will do
Which of the following is TRUE?
In java, an instance field declared public generates a compilation error.
int is the name of a class available in the package java.lang
Instance variable names may only contain letters and digits.
A class has always a constructor (possibly automatically supplied by the java compiler).
The more comments in a program, the faster the program runs.
Consider the following code snippet
String river = new String(“Columbia”);
System.out.println(river.length());
What is printed?
6
7
8
Columbia
River
Consider
public class MyClass{
public MyClass(){/*code*/}
// more code...
}
To instantiate MyClass, you would write?
MyClass mc = MyClass;
MyClass mc = MyClass();
MyClass mc = new MyClass();
MyClass mc = new MyClass;
What is garbage collection in the context of Java?
The operating system periodically deletes all of the java files available on the system.
Any package imported in a program and not used is automatically deleted.
When all references to an object are gone, the memory used by the object is automatically reclaimed.
The JVM checks the output of any Java program and deletes anything that doesn't make sense.
Janitors working for Sun MicroSystems are required to throw away any Microsoft documentation found in the employees' offices.
You read the following statement in a Java program that compiles
and executes.
submarine.dive(depth);
What can you say for sure?
depth must be an int
dive must be a method.
dive must be the name of an instance field.
submarine must be the name of a class
submarine must be a method.
The JVM has an automatic garbage collector that will reclaim the memory from any object that has been discarded by the running program.
True
False
A single-line comment begins with a ________ and ends at the end of the line
/
//
/*
**
A method in Java, that calls itself is said to be recursive.
True
False
The Code in java is contained within Methods
True
False
The methods and variables defined within a class are called members of the class
True
False
If the method does not return a value, its return type must be void
True
False
Methods that have a return type other than void return a value to the calling routine using the following form of the return statement: return value;
True
False
In return value; value is the value returned.
True
False
The type of data returned by a method need not be compatible with the return type specified by the method
True
False
The variable receiving the value returned by a method must also be compatible with the return type specified for the method.
True
False
A parameter is a variable defined by a method that receives a value when the method is called.
True
False
In general, there are _________ ways that a computer language can pass an argument to a subroutine
One
Two
Three
Four
In the Call-by-value methods of passing an argument to a Subroutine, the value of an argument is copied into the formal parameter of the subroutine
True
False
Recursion is the process of defining something in terms of itself.
True
False
A variable declared as final prevents its contents from being modified
True
False
If you want to pass information into a program when you run it then command-line arguments are to main( ).
True
False
Java was conceived by __________
Microsoft
Oracle
Sun Microsystem
Intel
Java compiler is an executable code
True
False
____________ is a highly optimized set of instructions designed to be executed by the Java run-time system
Byte Code
Firewall
Tetra Code
View Code
Java run-time system is also called as Java Virtual Machine (JVM)
True
False
Java Virtual Machine is an interpreter for bytecode
True
False
Java is Architectural _____________
Dependent
Neutral
Independent
None of the above
Java enables the creation of cross-platform programs by compiling into an intermediate representation called Java ____________
Byte Code
Firewall
Tetra Code
View Code
Java is Not designed for the distributed environment of the Internet
True
False
Comments in Java Program must begin with /* and end with */
True
False
All statements in Java end with a _____________
Colon
SemiColon
Hypen
Dot
The simplest form of the for loop in Java is for(initialization; condition; iteration) statement;
True
False
You do not need to follow any special indentation rules in Java
True
False
Java is Case ________
Insensitive
Sensitive
A constant value in Java is created by using a literal representation of it
True
False
The Separator [ ] is Used to declare array types
True
False
The print( ) method is just like println( ), except that it does not output a newline character after each call
True
False
The Java interpreter is used for the execution of the source code.
True
False
State true or false :- On successful compilation a file, with the .class extension is created.
True
False
Which of the option correctly describes the comments in java 1) // -- single line comment 2) /* -- */ multiple line comment 3) /** -- */ documentation
1, 2
2, 3
3, 1
1, 2, 3
Which of the following declare an array of string objects? (Select Multiple)
String[ ] s;
String [ ]s:
String[ s]:
String s[ ]:
Which of the following are primitive types?
byte
String
integer
float
What is the value of 111 % 13?
3
5
7
9
State true or false :- The do-while loop repeats a set of code at least once before the condition is tested.
True
False
State true or false :- All the classes in java.lang package are automatically imported when a program is compiled.
True
False
Which of the following features are common to both Java & C++? (Select multiple)
The class declaration
The access modifiers
The encapsulation of data & methods with in objects
The use of pointers
You would use the ____ operator to create a single instance of a named class.
New
dot
equals
none of the above
Java compiler stores the .class files in the path specified in CLASSPATH environmental variable.
True
False
Which of the following methods cause the String object referenced by s to be changed? (Select multiple)
s.concat( )
s.toUpperCase( )
s.replace( )
s.valueOf( )
Which of these is the correct format to use to create the literal char value a?
'a'
"a"
new Character(a)
\000a
What will be the result of compiling the following code: public class Test { static int age; public static void main (String args []) { age = age + 1; System.out.println("The age is " + age); } }
Compiles and runs with no output
Compiles and runs printing out The age is 1
Compiles but generates a runtime error
Does not compile
Compiles but generates a compile time error