Chapter 1-1
Chapter 1-1
2.Explain the concept of platform independence and portability with respect to Java
language.
Ans.
1. Java is a platform independent language.
2. This is possible because when a java program is compiled, an intermediate code
called the byte code is obtained rather than the machine code.
3. Byte code is a highly optimized set of instructions designed to be executed by the
JVM which is the interpreter for the byte code.
4. Byte code is not a machine specific code. Byte code is a universal code and can be
moved anywhere to any platform.
5. Therefore java is portable, as it can be carried to any platform.
6. JVM is a virtual machine which exists inside the computer memory and is a simulated
computer within a computer which does all the functions of a computer.
7. Only the JVM needs to be implemented for each platform.
8. Although the details of the JVM will defer from platform to platform, all interpret the
same byte code.
4.Describe instance Of and dot (.) operators in Java with suitable example.
Ans.
Instance of operator:
1. The java instance of operator is used to test whether the object is an instance of the
specified type (class or subclass or interface).
2. The instance of in java is also known as type comparison operator because it
compares the instance with type.
3. It returns either true or false. If we apply the instance of operator with any variable
that has null value, it returns false
4. Example :
class Simple1
{
public static void main(String args[])
{
Simple1 s=new Simple1();
System.out.println(sinstanceofSimple1); //true
}
}
dot (.) operator:
1. The dot operator, also known as separator or period used to separate a variable or
method from a reference variable.
2. Only static variables or methods can be accessed using class name.
3. Code that is outside the object's class must use an object reference or expression,
followed by the dot (.) operator, followed by a simple field name.
4. Example
this.name=”john”; where name is a instance variable referenced by ‘this’ keyword
4.Syntax:
newValue = (typecast)value;
5. Example:
double f = 3.5;
int i; i = (int)f; // it cast double value 3.5 to int 3.