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. Briefly explain what is meant by the syntax and the semantics of a programming language.Give an example to illustrate the difference between a syntax error and a semantics error?

    Answer: The syntax of a language is its grammar, and the semantics is its meaning.A program with a syntax error cannot be compiled.A program with a semantic error can be compiled and run, but gives an incorrect result.A missing semicolon in a program is an example of a syntax error, because the compiler will find the error and report it.If N is an integer variable, then the statement "frac = 1/N;" is probably an error of semantics.The value of 1/N will be 0 for any N greater than 1.It's likely that the programmer meant to say 1.0/N.

  2. What does the computer do when it executes a variable declaration statement.Give an example.

    Answer: A variable is a "box", or location, in the computer's memory that has a name.The box holds a value of some specified type.A variable declaration statement is a statement such as

    int x;

    which creates the variable x.When the computer executes a variable declaration, it creates the box in memory and associates a name (in this case, x) with that box.Later in the program, that variable can be referred to by name.

  3. What is a type, as this term relates to programming?

    Answer: A "type" represents a set of possible values.When you specify that a variable has a certain type, you are saying what values it can hold.When you say that an expression is of a certain type, you are saying what values the expression can have.For example, to say that a variable is of type int says that integer values in a certain range can be stored in that variable.

  4. One of the primitive types in Java is boolean.What is the boolean type? Where are boolean values used? What are its possible values?

    Answer: The only values of type boolean are true and false.Expressions of type boolean are used in places where true/false values are expected, such as the conditions in while loops and if statements.

  5. Give the meaning of each of the following Java operators - ++, &&, !=

    Answer: The Operators are Explained as follows:

    • ++:The operator ++ is used to add 1 to the value of a variable.For example, "count++" has the same effect as "count = count + 1".
    • &&:The operator && represents the word and.It can be used to combine two boolean values, as in "(x > 0 && y > 0)", which means, "x is greater than 0 and y is greater than 0."
    • !=:The operation != means "is not equal to", as in "if (x != 0)", meaning "if x is not equal to zero.".

  6. Explain what is meant by an assignment statement, and give an example.What are assignment statements used for?

    Answer: An assignment statement computes a value and stores that value in a variable.
    Examples include:

    x = 17;
    newRow = row;
    ans = 17*x + 42;

    An assignment statement is used to change the value of a variable as the program is running.Since the value assigned to the variable can be another variable or an expression, assignments statements can be used to copy data from one place to another in the computer, and to do complex computations.

  7. What is meant by precedence of operators?

    Answer: If two or more operators are used in an expression, and if there are no parentheses to indicate the order in which the operators are to be evaluated, then the computer needs some way of deciding which operator to evaluate first.The order is determined by the precedence of the operators.For example, * has higher precedence than +, so the expression 3+5*7 is evaluated as if it were written 3+(5*7).

  8. What is a literal?

    Answer: A literal is a sequence of characters used in a program to represent a constant value.For example, 'A' is a literal that represents the value A, of type char, and 17L is a literal that represents the number 17 as a value of type long.A literal is a way of writing a value, and should not be confused with the value itself.

  9. In Java, classes have two fundamentally different purposes.What are they?

    Answer: A class can be used to group together variables and subroutines that are contained in the class.These are called the static members of the class.For example, the subroutine Math.sqrt is a static member of the class called Math.Also, the main routine in any program is a static member of a class.The second possible purpose of a class is to describe and create objects.The class specifies what variables and subroutines are contained in those objects.In this role, classes are used in object-oriented programming (which we haven't studied yet in any detail.)

  10. What is the difference between the statement "x = TextIO.getDouble();" and the statement "x = TextIO.getlnDouble();"

    Answer: Either statements will read a real number input by the user, and store that number in the variable, x.They would both read and return exactly the same value.The difference is that in the second statement, using getlnDouble, after reading the value, the computer will continue reading characters from input up to and including the next carriage return.These extra characters are discarded.

« 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.