Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

Elements of Java

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Elements of Java

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1. Differentiate between operator and expression.

Ans: - Operator represents some specific actions on one or more operands to obtain a result, e.g., +, *,
++, etc.

Expression is a combination of operands and operators yielding a resultant value.

2. State the difference between = and ==.

Ans: - = is an assignment operator, which assigns value to a variable.

== is a relational operator, which is used for checking equality or not of two items.

3. State the difference between token and identifier.

Ans: - The smallest individual unit in a program, such as keyword, identifier, literal, etc. is called a Token.

Whereas, Identifier is a name given to a variable or class or object or array or a method.

4. State the difference between floating point lietral ‘float’ and ‘double’.

Ans: - The size of ‘float’ data type is 4 bytes (32 bits) whereas the size of ‘double’ data type is 8 bytes (64
bits).

5. State the two types of Java programs.

Ans: - 1. Stand Alone Application

2. Internet Applet

6. State the the difference between boolean literal and character literal.

Ans: - A boolean literal can be either ‘true’ or ‘false’ as its value.

A character literal is composed of a single character enclosed within a pair of single quotes, e.g., ‘A’.

6. Rewrite the following using ternary operator:

If (income <= 10000)

Tax = 0;

Else

Tax = 12;

Ans: - tax = (income < = 10000) ? 0 : 12;

7. Name OOP’s principles.

Ans: - Abstraction, Encapsulation, Inheritance, Polymorphism.

8. Define bytecode.

Ans: - Bytecde is a platform independent Java instruction for the Java processor chip called JVM.
9. How is implicit conversion different from explicit conversion?

Ans: - Implicit conversion is the automatic conversion of a smaller datatype to a bigger datatype.

Explicit conversion is the conversion of a bigger datatype to a smaller datatype forcefully using the
typecast operator ( ).

10. Define Encapsulation.

Ans: - Wrapping of data and functions of a class together so that they can be applied as a unit to
perform any operation is termed as Encapsulation.

11. Define Abstraction.

Ans: - Abstraction refers to an act of representing essential features without including background
details.

12. Define Inheritance.

Ans: - Inheritance is the process in which objects of one class can link and share some common
properties from the objects of another class.

13. Define Polymorphism.

Ans: - Polymorphism is the process of using a function for more than one purpose. It allows the use of
different internal structures of the objects by keeping the same external interface.

14. What is meant by precedence of operators?

Ans: - The precedence of operators indicates the order in which the operators are evaluated in an
expression.

15. Give one example of each of (i) Runtime error, (ii) Logical error, (iii) Syntax error.

Ans: - (i) Runtime error – Division by a variable that contains a value of zero (0).

(ii) Logical error – Multiplication operator used when the operation should be division.

(iii) Syntax error – Missing semicolon (;).

16. Differentiate between unary and binary operators.

Ans: - Unary operators act on one operand and binary operators act on two operands.

17. Define keyword with example.

Ans: - A keywords is a reserved word with a predefined special meaning which the java compiler can
recognize. It cannot be used for other meanings. For example, for, if, while, break, etc.

18. What is ternary operator? Give the syntax.

Ans: - The ternary operator in Java is a conditional operator, also called ‘conditional assignment’. It is a
substitute for the if … else control statement. A ternary operator requires three operands.

Syntax – conditional_expression ? exp1 : exp2;


19. What is compound statement? Give an example.

Compound statement is a block of statements enclosed within curly brackets { }.

Example:

Int k = 1;

While (k < 10)

K++;

System.out.println(5 * k);

20. Name Java Tokens.

Ans: - Keywords, Identifiers, punctuators, operators and literals.

21. What is an Identifier?

Ans: - The names of variables, classes, objects, functions, etc., are referenced by identifiers which are
names given by the programmer to them.

22. Which OOP principle implements function overloading?

Ans: - Polymorphism

23. Differentiate between class and object.

Ans: -

Class Object

(i) Class is a blueprint or template from which objects are created. (i) Object is an instance
of a class.
(ii) Class is a logical entity. (ii) Object is a physical entity.
(iii) Class is declared once. (iii) Object is created many times as per requirement.

(iv) Class doesn’t allocated memory when it is created. (iv) Object allocates memory when it is created.

24. Define JVM.

Ans: - A Java Virtual Machine (JVM) is software capable of executing Java byte code. It interprets the
byte code of our class file and executes the instructions within it. The JVM is like a ‘virtual’ processor,
which exists in the computer’s processor.

25. Java is a ‘platform independent’ language. Explain.

Ans: - A Java program can be compiled once into a Java Byte code program. The compiled program can
then be run on any computer that has an interpreter for the Java Virtual Machine. It is therefore
considered ‘platform independent’.
26. Differentiate between operator and operands.

Ans: - An operator is a symbol such as +, -, =, etc, taking one or more operands which yield results.

The object used for operation of an expression or the values on which an expression operates upon,
namely variables are referred to as an operand, e.g.: int a = 5, Here ‘a’ is an operand.

27. What is an Exception? Name two Exception handling blocks.

Ans: - Exception is an unexpected situation which occurs during the execution of a program due to
improper use of input resources or overflow occurrence. It can be handled using:

(i) Try – catch

(ii) with throws keyword.

28. Differentiate between ‘/’ and ‘%’ operator.

Ans: - ‘/’ is a arithmetic division operator, which is used to return quotient value in a division whereas,
‘%’ is a modulus (remainder) operator which is used to return remainder value in a division.

You might also like