Elements of Java
Elements of Java
Ans: - Operator represents some specific actions on one or more operands to obtain a result, e.g., +, *,
++, etc.
== is a relational operator, which is used for checking equality or not of two items.
Ans: - The smallest individual unit in a program, such as keyword, identifier, literal, etc. is called a Token.
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).
2. Internet Applet
6. State the the difference between boolean literal and character literal.
A character literal is composed of a single character enclosed within a pair of single quotes, e.g., ‘A’.
Tax = 0;
Else
Tax = 12;
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 ( ).
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.
Ans: - Abstraction refers to an act of representing essential features without including background
details.
Ans: - Inheritance is the process in which objects of one class can link and share some common
properties from the objects of another class.
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.
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.
Ans: - Unary operators act on one operand and binary operators act on two operands.
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.
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.
Example:
Int k = 1;
K++;
System.out.println(5 * k);
Ans: - The names of variables, classes, objects, functions, etc., are referenced by identifiers which are
names given by the programmer to them.
Ans: - Polymorphism
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.
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.
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.
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:
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.