0% found this document useful (0 votes)
12 views

Chapter 1-1

Uploaded by

Yash Gaware
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Chapter 1-1

Uploaded by

Yash Gaware
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Chapter 1

1.List any eight features of Java.


Ans.
Features of Java:
1. Data Abstraction and Encapsulation
2. Inheritance
3. Polymorphism
4. Platform independence
5. Portability
6. Robust
7. Supports multithreading
8. Supports distributed applications
9. Secure
10. Architectural neutral
11. Dynamic

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.

3.Define Class and Object.


Ans.
Class:
A class is a user defined data type which groups data members and its associated functions
together.
Object:
It is a basic unit of Object-Oriented Programming and represents the real life entities.
A typical Java program creates many objects, which as you know, interact by invoking
methods.

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

c.getdata(); where getdata() is a method invoked on object ‘c’


5.Define type casting. Explain its types with syntax and example
Ans.
1. The process of converting one data type to another is called casting or type casting.
2. If the two types are compatible, then java will perform the conversion automatically.
3. It is possible to assign an int value to long variable.
4. However, if the two types of variables are not compatible, the type conversions are
not implicitly allowed, hence the need for type casting.
5. There are two types of conversion:
1.Implicit type-casting
2.Explicit type-casting
Implicit type-casting:
Implicit type-casting performed by the compiler automatically; if there will be no loss of
precision.
Example:
int i = 3; double f;
f = I;
output:
f = 3.0
Explicit type-casting:
1. Explicit type-casting performed via a type-casting operator in the prefix form of (new-
type) operand.
2. Type-casting forces an explicit conversion of type of a value.
3. Type casting is an operation which takes one operand, operates on it and returns an
equivalent value in the specified type.

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.

6.Explain any two logical operator in java with example.


Ans.
Logical Operators:
Logical operators are used when we want to form compound conditions by combining two or
more relations.
Java has three logical operators as shown in table:
Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT

Program demonstrating logical Operators


public class Test
{
public static void main(String args[])
{
boolean a = true;
boolean b = false;
System.out.println("a && b = " + (a&&b));
System.out.println("a || b = " + (a||b) );
System.out.println("!(a && b) = " + !(a && b));
}
}
Output:
a && b = false a || b = true !(a && b) = true

You might also like