JPR PIP on chapter 1..
JPR PIP on chapter 1..
2 1,2 2 Define JDK. List the tools available in JDK explain any one in detail
3 1 4 Write all primitive data types available in Java with their storage sizes in bytes,
5 2 4 Describe any two relational and any two logical operators in java with simple example
9 1,2 4 Define a class and object. Write syntax to create class and object with an example
10 2 4 What is type casting? Explain its types with proper syntax and example.
12 2 4 What is scope of variable? Give example of class variable, instance variable and local
variable.
Marking Scheme
JVM is the Java Virtual Machine
The java compiler compiles produces an intermediate code known as byte code for the
java virtual machine, which exists only n the computer memory It is a simulated computer
within the computer and does all the major functions of a real computer
Source code
Byte Code
Answer process of compilation
Virtual machine code is not machine specific Machine specific code is generated by Java
Interpreter by acting as an intermediary between the virtual machine and the real
2 1 2 Define JDK. List the tools available in JDK explain any one in detail
Marking Scheme
A Java Development Kit (JDK) is a collection of tools which are used for developing, designing,
debugging. executing and running java programs.
Answer Tools of JDK: java, javap, javah, javadoc, jdb, appletviewer, javac 1. Java Compiler-it is used to
translate java source code to byte code files that the interpreter can
3 2 4 Write all primitive data types available in Java with their storage sizes in bytes,
Marking Scheme
Describe any two relational and any two logical operators in java with simple example
5 2 4
Marking Scheme
Answer Relational Operators: When comparison of two quantities is performed depending on their relation,
certain decisions are made. Java supports six relational operators as shown in table.
Operators Meaning
<
Less than
> Greater than
== Equal to
!= Not equal to
Operators Meaning
|| Logical OR
! Logical NOT
class Log
{
public static void main(String args[])
boolean A=true;
boolean B-false;
Use: This method returns the correctly rounded positive square root of a double value.
4) pow():
Syntax: static double pow(double a, double b)
Answer Use: This method returns the value of the first argument raised to the power of the second
argument.
5) exp():
Use: This method returns Euler's number e raised to the power of a double value.
Syntax: static double exp(double a)
6) round():
Syntax: static int round(float a)
Use: This method returns the closest int to the argument.
7) abs():
Syntax: static int abs(int a)
Use: This method returns the absolute value of an int value
Marking Scheme
There are several reasons why java is not a 100% Object Oriented Programming Language:
Because it supports Primitive data type such as int, byte, long... etc, to be used, which are not
Answer objects. Multiple inheritance through classes is not possible. Availability of static methods and
variables. Operator overloading is not possible in java.
One block equal to one new scope in Java thus each time you start a new block, you are
creating a new scope.
A scope determines what objects are visible to other parts of your program. It also
determines the lifetime of those objects
Program:
Output:
n1 and n2: 10 20
nl is 10
Define a class and object. Write syntax to create class and object with an example
9 2 4
Marking Scheme
Java is complete object oriented programming language. All program code and data reside in
object and class. Java classes create objects and objects will communicate between using
methods.
Class:
A class is a user defined data type. Data and methods are encapsulated in class
It is a template or a pattern which is used to define its properties.
Java is fully object oriented language. All program code and data reside within objects
and classes
SYNTAX:
class classname
{
type-instance-variable1;
.
.
type methodname1(parameter-list)
{
//body of method
}
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, internet by invoking methods. An object
consists of state behavior and identity.
syntax:
class_name object=new class_name();
What is type casting? Explain its types with proper syntax and example.
10 2 4
Marking Scheme
Assigning a value or one type to a variable of another type is known as Type Casting
There are 2 types of type casting
1.Widening of Implicit type casting
2.Narrowing or Explicit casting
program:
public class Test {
int i= 100;
}}
Output:
When you are assigning a larger type value to a variable of smaller type. Ther need to perform
explicit type casting
}}
Output:
Java is a platform independent language. This is possible because when a java program is
compiled, an intermediate code called the byte code is obtained rather than the machine code.
Byte code is a highly optimized set of instructions designed to be executed by the JVM which is
the interpreter for the byte code. Byte code is not a machine specific code. Byte code iss universal
code and can be moved anywhere to any platform. 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. Only the JVM needs to be implemented for each platform. Although the details of
the JVM will defer from platform to platform, all interpret the same byte code.
12 2 4
What is scope of variable? Give example of class variable, instance variable and local
variable.
Marking Scheme
Answer The scope of a variable defines the section of the code in which the variable is visible. The
variable can be class variable which is associated with the class and is shared with all the
instances of the class or an instance variable which in a class and each instance has a separate
copy or a local variable which is defined in a block or method as a general rule, variables that are
defined within a block are not accessible outside that block. The lifetime of a variable long the
variable exists before it is destroyed.
VariableTypes()
a++;
b++;
System.out.println("in main printing c "+s.c);//will not be accessed because this is a local variable
declared in
constructor
}
}