Professional Documents
Culture Documents
Ans. Programming involves taking in some data, processing it using some instructions and
giving
some meaningful result. Taking in some data is called Input.
7. What are the different type of errors that may occur in a Java program?
Ans. Errors in a program in Java can broadly be classified into three categories:
• Syntax errors
• Logical errors
• Run-time errors
10. What are comments? Name the different types of comments used in Java.
Ans. A comment is a programmer-readable explanation or annotation in the source code of a
computer program. The different types of comments in Java are:
• Singleline comment
• Multiline comment
5. What is increment/decrement operator used for? Explain with the help of an example.
Ans The increment/decrement operator is used to increase/decrease the value of a variable by
1.
For example a++; increases the value of the variable a by 1, similarly a--; decreases the value
of
the variable a by 1.
6. What is an expression?
Ans. An expression is a construct that is made up of variables, operators and method
invocations,
which are constructed according to the syntax of the language that evaluates to a single value.
7. State the different types of binary arithmetic operators. Also state their hierarchy of
operations.
Ans These are operators that work on two operands. The operator is placed between the
operands.
The symbols that are used as binary arithmetic operators are:
+ For performing addition
- For performing subtraction.
* For performing multiplication.
/ For performing division.
% For getting the remainder when divided.
Hierarchy of Arithmetic Operators
1. First Brackets/Parenthesis: In Java the expression in bracket is done first. However brackets
in an expression should only be first bracket ( ). Nested brackets can also be used, but in that
case the expressions in the innermost bracket are done first and then the subsequent outer-
level brackets. Eg. (5+6*(7-3)) will give 29. Notice that only first-bracket is used.
2. Then /, *, or % whichever comes first while evaluating from left to right will get evaluated
first.
3. Then + or – whichever comes first while evaluating from left to right will get evaluated first..
14. Give the general syntax of conditional operator and also label its operands.
Ans. It has the following general syntax:
1. Name the class that is used for different mathematical functions. Give an example of a
mathematical function.
Ans. class: Math
Functions: Math.pow(), Math.sqrt(), Math.floor(), etc.
2. Give the output of the following expressions.
i. If x = -9.99, calculate Math.abs(x);
ii. If x = 9.0, calculate Math.sqrt(x);
Ans. i. 9.99
ii. 3.0