Sample Questions Best site for GRE, LSAT, SAT, GMAT, TOEFL, CCNA, CCSA and interview sample questions  

Technical Sample Questions : C |  C++ |  Oracle |  Java | Unix |  Operating Systems |  Data Structure

Java Sample Questions ›› Java questions

Technical General Java Sample Questions

  1. Explain briefly what is meant by "pseudocode" and how is it useful in the development of algorithms.

    Answer: Pseudocode refers to informal descriptions of algorithms, written in a language that imitates the structure of a programming language, but without the strict syntax.Pseudocode can be used in the process of developing an algorithm with stepwise refinement.You can start with a brief pseudocode description of the algorithm and then add detail to the description through a series of refinements until you have something that can be translated easily into a program written in an actual programming language.

  2. What is a block statement? How are block statements used in Java programs?

    Answer: A block statement is just a sequence of Java statements enclosed between braces, { and }.The body of a subroutine is a block statement.Block statements are often used in control structures.A block statement is generally used to group together several statements so that they can be used in a situation that only calls for a single statement.For example, the syntax of a while loop calls for a single statement: "while (condition) do statement".However, the statement can be a block statement, giving the structure: "while (condition) { statement; statement;...}".

  3. What is the main difference between a while loop and a do..while loop?

    Answer: Both types of loop repeat a block of statements until some condition becomes false.The main difference is that in a while loop, the condition is tested at the beginning of the loop, and in a do..while loop, the condition is tested at the end of the loop.It is possible that the body of a while loop might not be executed at all.However, the body of a do..while loop is executed at least once since the condition for ending the loop is not tested until the body of the loop has been executed.

  4. What does it mean to prime a loop?

    Answer: The condition at the beginning of a while loop has to make sense even the first time it is tested, before the body of the loop is executed.To prime the loop is to set things up before the loop starts so that the test makes sense (that is, the variables that it contains have reasonable values).For example, if the test in the loop is "while the user's response is yes," then you will have to prime the loop by getting a response from the user (or making one up) before the loop.

  5. Explain what is meant by an animation and how a computer displays an animation?

    Answer: An animation consists of a series of "frames." Each frame is a still image, but there are slight differences from one frame to the next.When the images are displayed rapidly one frame after another, the eye perceives motion.A computer displays an animation by showing one image on the screen, then replacing it with the next image, then the next, and so on.

  6. Write a for loop that will print out all the multiples of 3 from 3 to 36, that is: 3 6 9 12 15 18 21 24 27 30 33 36.

    Answer: Here are two possible answers.Assume that N has been declared to be a variable of type int:

    for ( N = 3;N <= 36;N = N + 3 )
    System.out.println( N );

    for ( N = 3;N <= 36;N++ )
    if ( N % 3 == 0 )
    System.out.println( N );

  7. Fill in the following main() routine so that it will ask the user to enter an integer, read the user's response, and tell the user whether the number entered is even or odd.(You can use TextIO.getInt() to read the integer.Recall that an integer n is even if n % 2 == 0.)

    public static void main(String[] args) {


    Answer: The problem already gives an outline of the program.The last step, telling the user whether the number is even or odd, requires an if statement to decide between the two possibilities.

    public static void main (String[] args)
    int n;
    TextIO.put("Type an integer: ");
    n = TextIO.getInt();
    if (n % 2 == 0)
    System.out.println("That's an even number.");
    System.out.println("That's an odd number.");

  8. Show the exact output that would be produced by the following main() routine:

    public static void main(String[] args) {
    int N;
    N = 1;
    while (N <= 32)
    N = 2 * N;

    Answer: The exact output printed by this program is:


  9. What output is produced by the following program segment? Why?

    String name;
    int i;
    boolean startWord;
    name = "Richard M.Nixon";
    startWord = true;
    for (i = 0; i < name.length(); i++) {
    if (startWord)
    if (name.charAt(i) == ' ')
    startWord = true;
    startWord = false;

    Answer: This is a tough one! The output from this program consists of the three lines:


    As the for loop in this code segment is executed, name.charAt(i) represents each of the characters in the string "Richard M.Nixon" in succession.The statement System.out.println(name.charAt(i)) outputs the single character name.charAt(i) on a line by itself.However, this output statement occurs inside an if statement, so only some of the characters are output.The character is output if startWord is true.This variable is initialized to true, so when i is 0, startWord is true, and the first character in the string, 'R', is output.Then, since 'R' does not equal ' ', startWorld becomes false, so no more characters are output until startWord becomes true again.This happens when name.charAt(i) is a space, that is, just before the 'M' is processed and again just before the 'N' is processed.In fact whatever the value of name, this for statement would print the first character in name and every character in name that follows a space

  10. A "black box" has an interface and an implementation.Explain what is meant by the terms interface and implementation.

    Answer: The interface of a black box is its connection with the rest of the world, such as the name and parameters of a subroutine or the dial for setting the temperature on a thermostat.The implementation refers to internal workings of the black box.To use the black box, you need to understand its interface, but you don't need to know anything about the implementation.

« Previous || Next »

Java Sample Question Number: 1-10| 11-20| 21-30| 31-40| 41-50| 51-60| 61-70| 71-80| 81-90| 91-100| 101-110| 111-120| 121-130| 131-140| 141-150| 151-160| 161-170| 171-180| 181-190| 191-200| 201-210| 211-220| 221-230| 231-240| 241-250| 251-260| 261-270| 271-280| 281-290| 291-300| 301-310| 311-320| 321-330
Sample Test Questions
GRE Sample Questions
CAT Sample Questions
GMAT Sample Questions
TOEFL Sample Questions
ACT Sample Questions
SAT Sample Questions
LSAT Sample Questions
PSAT Sample Questions
MCAT Sample Questions
PMP Sample Questions
GED Sample Questions
ECDL Sample Questions
DMV Sample Questions
CCNA Sample Questions
MCSE Sample Questions
Network+ Sample Questions
A+ Sample Questions
Technical Sample Questions
WASL Sample Questions
CISA Sample Questions

Other Sample Questions
Sample Interview Questions
Sample Teacher Interview Questions
Sample Citizenship Questions
Accuplacer Sample Questions
Science Bowl sample Questions
Driving Test Sample Questions
Sample Survey Questions Sample Essay Questions
Sample Behavioral Interview Questions

Copyright © 2004-2013, Best BSQ. All Rights Reserved.