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

JPR PIP on chapter 1..

The document outlines the assignment questions and marking schemes for a Java Programming course at Bhivrabai Sawant Polytechnic for the academic year 2022-23. It includes questions on JVM, JDK, primitive data types, operators, type casting, and the concept of variable scope, along with detailed answers and explanations. The document serves as a guide for students to understand key Java concepts and prepare for assessments.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

JPR PIP on chapter 1..

The document outlines the assignment questions and marking schemes for a Java Programming course at Bhivrabai Sawant Polytechnic for the academic year 2022-23. It includes questions on JVM, JDK, primitive data types, operators, type casting, and the concept of variable scope, along with detailed answers and explanations. The document serves as a guide for students to understand key Java concepts and prepare for assessments.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 13

JAYAWANT SHIKSHAN PRASARAK MANDAL’s

Bhivrabai Sawant Polytechnic


(Approved by AICTE, New Delhi, Govt. of Maharashtra, Affiliated to MSBTE Mumbai)
Gat No. 720 (1&2), Wagholi, Pune-Nagar Road, Pune-412207)
Phone: 020 – 65335100 Tele fax: - + 91-020-65335100
E-mail: [email protected] Website: www.jspm.edu.in

Computer Engineering Department


Academic Year 2022-23
PIP Questions on Chapter 1
Course: Java Programming Course Code: 22412 Semester: IV
Que. Bloom’s Marks Assignment Questions Relevance
No. Level to CO
1 1,2 4 What is JVM? What is Byte Code?

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,

4 2 4 Describe arithmetic operators with suitable example

5 2 4 Describe any two relational and any two logical operators in java with simple example

6 2 4 Write any four mathematical functions used in Java

7 2 4 Why java is not 100% object oriented language.


COI402.1
8 2 4 State & explain scope of variable with an 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.

11 2 4 Why java became platform independent language? Explain.

12 2 4 What is scope of variable? Give example of class variable, instance variable and local
variable.

Sign of Course Coordinator Sign of Module Coordinator Sign of H.O.D.


JAYAWANT SHIKSHAN PRASARAK MANDAL’s

Bhivrabai Sawant Polytechnic


(Approved by AICTE, New Delhi, Govt. of Maharashtra, Affiliated to MSBTE Mumbai)
Gat No. 720 (1&2), Wagholi, Pune-Nagar Road, Pune-412207)
Phone: 020 – 65335100 Tele fax: - + 91-020-65335100
E-mail: [email protected] Website: www.jspm.edu.in

Computer Engineering Department


Academic Year 2022-23
PIP Chapter 1 Solution
Course: Java Programming Course Code: 22412 Semester: IV

Que. Bloom’s Relevance


Marks Assignment Questions
No. Level to CO
1 1, 2 2 What is JVM? What is Byte Code? COI402.1

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

Java Program Java Compile Virtual Machine

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

Interpreter is written for each type of machine


Byte code: Byte code is the compiled format for Java programs. Once a Java program has been
converted to byte code, it can real machine be transferred across a network and executed by Java
Virtual Machine (JVM). A Byte code file generally has a .class extension

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

Answer Type Size in Bytes Range

byte 1 byte -128 to 127

short 2 byte -32.768 to 32,767


int 4 byte -2,147,483,648 to 2,147,483, 647

long 8 byte -9,223,372,036,854,775,808 to


9,223,372,036,854,775,807

float 4 byte approximately 3.40282347E+38F (6-7


significant decimal digits)

Java implements IEEE 754 standard

double 8 byte approximately 1.79769313486231570E+308


(15 significant decimal digits)

char 2 byte 0 to 65,536 (unsigned)

Boolean not precisely defined true or false

4 2 4 Describe arithmetic operators with suitable example


Marking Scheme
Answer operator Description Example Explanation
+ Addition X=y+ z Adds the value of y
and z and stores the
result in X
- Subtraction X=y-z Subtracts z from y
and store the result in
X

* Multiplication X=y*z Multiplies the values y


and z and store the
result in X

/ Division X=y/z Divides y by z and


stores the result in X

% Modulo X=y %z Divides y by z and


stores the remainder
in X

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

<= Less than or equal to

>= Greater than or equal to

== Equal to

!= Not equal to

Program demonstrating Relational Operators.


class relational
{
public static void main(String args[]) {
int i-37; int j=42;

System. out. Println("i>j"+(i>j)); //false


System. out. println("i<j"+(i<j)); //true
System. out. println("i==j”+i==j )); //false
System. out. println("i!=j”+(i!=j)); // true
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:

Operators Meaning

&& Logical AND

|| Logical OR

! Logical NOT

Program demonstrating logical Operators

class Log
{
public static void main(String args[])

boolean A=true;

boolean B-false;

System. Out .println("A\B"+(A|B)); //true

System. out. println("A&B"+(A&B)); // false

System. out. println("!A"+(IA)); // false

System. out. println("A^B"+(A^B)); // true

System. out.println("(A/B)&A"+((A|B)&A)); // true

6 2 4 Write any four mathematical functions used in Java


Marking Scheme
1)min():
syntax: static int min(int a,int b)
Use: This method returns the smaller of two int values.
2) max():
Syntax: static int max(int a,int b)
Use: This method return e greater of two int values.
3) sqrt():
Syntax static double sqrt(double a)

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

Why java is not 100% object oriented language.


7 2 4

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.

State & explain scope of variable with an example.


8 2 4
Marking Scheme
 We can declare variables within any block

 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:

//demonstrate block scope.


class Scope (

public static void main (String args[])


{ int nl; // Visible in main
int n1=10;
if(n1==10)
{
//new scope
Answer int n2 = 20; // visible only to this block
//nl and n2 both visible here.

System.out.println("nl and n2: "+nl+" "+n2);


}

//n2=100; // Error! N2 not known here

//nl is still visible here.


System.out.println(“n1 is”+n1);
}
}

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

1.Widening of Implicit type casting


byte short int long float double
Implicitly Type casting take place when
The two types are compatible
The target type is larger than the source type

program:
public class Test {

public static void main(String args[]) {

int i= 100;

long 1 = i; // no explicit type casting require

float f=1; // no explicit type casting required


System.out.println ("Int value " + i);

System.out.println ("Long value" +1):

System.out.println ("Float value "+f):

}}
Output:

Int value 100

Float value 100.0

Long value 100

2.Narrowing or Explicit casting

When you are assigning a larger type value to a variable of smaller type. Ther need to perform
explicit type casting

public class Test


{
public static void main(String args[])
{
double d-100.04:

long 1 (long) d; // explicit type casting required


int I= (int) 1:

System.out.println ("Double value + d):

System.out.println ("Logn value "+1).

System.out.println ("Int value "+I):

}}
Output:

Int value 100


Double value 100.04
value 100

11 2 4 Why java became platform independent language? Explain.


Marking Scheme

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.

java program java compiler virtual machine

source code Byte code


process of compilation

byte code java interpreter machine code

virtual machine real machine

process of converting byte code into machine 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.

Eg: class VariableTypes

static int a = 0; //class variable

int b = 0; //instance variable

VariableTypes()

a++;

b++;

int c = 0; //local variable


c++;

System.out.println("In constructor printing a: "+a);//will be accessed


System.out.println("In constructor printing b: "+b);//will be accessed
System.out.println("In constructor printing c: "+c)://will be accessed

public static void main(String args[])

VariableTypes s = new VariableTypes();

VariableTypes sl = new VariableTypes();

VariableTypes s2 = new VariableTypes();

System.out.println("in main printing a: "+VariableTypes.a);//will be accessed


System.out.println("in main printing b: "+s.b);://will be accessed

System.out.println("in main printing c "+s.c);//will not be accessed because this is a local variable
declared in

constructor

}
}

You might also like