0% found this document useful (0 votes)
16 views78 pages

All in One JPR I Scheme Model Answer Papers

The document is a model answer for the Summer 2019 Java Programming examination by the Maharashtra State Board of Technical Education. It provides important instructions for examiners on how to assess student answers, along with a series of questions and model answers covering key Java concepts such as features of Java, inheritance types, constructors, and thread creation. The document serves as a guideline for evaluating students' understanding of Java programming principles.

Uploaded by

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

All in One JPR I Scheme Model Answer Papers

The document is a model answer for the Summer 2019 Java Programming examination by the Maharashtra State Board of Technical Education. It provides important instructions for examiners on how to assess student answers, along with a series of questions and model answers covering key Java concepts such as features of Java, inheritance types, constructors, and thread creation. The document serves as a guideline for evaluating students' understanding of Java programming principles.

Uploaded by

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

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

Important Instructions to examiners:


1) The answers should be examined by key words and not as word-to-word as given in the model
answer scheme.
2) The model answer and the answer written by candidate may vary but the examiner may try to
assess the understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given more Importance
(Not applicable for subject English and Communication Skills).
4) While assessing figures, examiner may give credit for principal components indicated in the
figure. The figures drawn by candidate and model answer may vary. The examiner may give
credit for any equivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed constant
values may vary and there may be some difference in the candidate’s answers and model
answer.
6) In case of some questions credit may be given by judgement on part of examiner of relevant
answer based on candidate’s understanding.
7) For programming language papers, credit may be given to any other program based on
equivalent concept.

Q. Sub Answer Marking


No Q.N. Scheme
.
1. Attempt any FIVE of the following: 10
a) List any eight features of Java. 2M
Ans. Features of Java:
1. Data Abstraction and Encapsulation
2. Inheritance
3. Polymorphism
4. Platform independence Any
5. Portability eight
6. Robust features
2M
7. Supports multithreading
8. Supports distributed applications
9. Secure
10. Architectural neutral
11. Dynamic
b) State use of finalize( ) method with its syntax. 2M
Ans. Use of finalize( ):
Sometimes an object will need to perform some action when it is

Page 1 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

destroyed. Eg. If an object holding some non java resources such as


file handle or window character font, then before the object is
garbage collected these resources should be freed. To handle such
situations java provide a mechanism called finalization. In Use 1M
finalization, specific actions that are to be done when an object is
garbage collected can be defined. To add finalizer to a class define
the finalize() method. The java run-time calls this method whenever it
is about to recycle an object.

Syntax: Syntax
protected void finalize() { 1M
}
c) Name the wrapper class methods for the following: 2M
(i) To convert string objects to primitive int.
(ii) To convert primitive int to string objects.
Ans. (i) To convert string objects to primitive int:
String str=”5”;
int value = Integer.parseInt(str); 1M for
each
(ii) To convert primitive int to string objects: method
int value=5;
String str=Integer.toString(value);
d) List the types of inheritances in Java. 2M
(Note: Any four types shall be considered)
Ans. Types of inheritances in Java:
i. Single level inheritance Any
ii. Multilevel inheritance four
iii. Hierarchical inheritance types
iv. Multiple inheritance ½M
v. Hybrid inheritance each

e) Write the syntax of try-catch-finally blocks. 2M


Ans. try{
//Statements to be monitored for any exception
} catch(ThrowableInstance1 obj) { Correct
//Statements to execute if this type of exception occurs syntax
} catch(ThrowableInstance2 obj2) { 2M
//Statements
}finally{

Page 2 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

//Statements which should be executed even if any exception happens


}
f) Give the syntax of < param > tag to pass parameters to an applet. 2M
Ans.
Syntax:
<param name=”name” value=”value”> Correct
syntax
Example: 2M
<param name=”color” value=”red”>

g) Define stream class. List its types. 2M


Ans. Definition of stream class:
An I/O Stream represents an input source or an output destination. A
stream can represent many different kinds of sources and
destinations, including disk files, devices, other programs, and Definitio
memory arrays. Streams support many different kinds of data, n 1M
including simple bytes, primitive data types, localized characters, and
objects. Java’s stream based I/O is built upon four abstract classes:
InputStream, OutputStream, Reader, Writer.

Types of stream classes:


i. Byte stream classes Types
ii. Character stream classes. 1M

2. Attempt any THREE of the following: 12


a) Explain the concept of platform independence and portability 4M
with respect to Java language.
(Note: Any other relevant diagram shall be considered).
Ans. 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 Explana
JVM which is the interpreter for the byte code. Byte code is not a tion 3M
machine specific code. Byte code is a universal code and can be
moved anywhere to any platform. Therefore java is portable, as it
can be carried 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
Page 3 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

byte code.

Diagram
1M

b) Explain the types of constructors in Java with suitable example. 4M


(Note: Any two types shall be considered).
Ans. Constructors are used to initialize an object as soon as it is created.
Every time an object is created using the ‘new’ keyword, a
constructor is invoked. If no constructor is defined in a class, java
compiler creates a default constructor. Constructors are similar to
methods but with to differences, constructor has the same name as
that of the class and it does not return any value. Explana
The types of constructors are: tion of
1. Default constructor the two
2. Constructor with no arguments types of
3. Parameterized constructor construc
4. Copy constructor tors 2M

1. Default constructor: Java automatically creates default constructor


if there is no default or parameterized constructor written by user. Example
Default constructor in Java initializes member data variable to default 2M
values (numeric values are initialized as 0, Boolean is initialized as
false and references are initialized as null).
class test1 {
int i;
boolean b;
byte bt;
float ft;
String s;

Page 4 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

public static void main(String args[]) {


test1 t = new test1(); // default constructor is called.
System.out.println(t.i);
System.out.println(t.s);
System.out.println(t.b);
System.out.println(t.bt);
System.out.println(t.ft);
}
}
2. Constructor with no arguments: Such constructors does not have
any parameters. All the objects created using this type of constructors
has the same values for its datamembers.
Eg:
class Student {
int roll_no;
String name;
Student() {
roll_no = 50;
name="ABC";
}
void display() {
System.out.println("Roll no is: "+roll_no);
System.out.println("Name is : "+name);
}
public static void main(String a[]) {
Student s = new Student();
s.display();
}
}

3. Parametrized constructor: Such constructor consists of parameters.


Such constructors can be used to create different objects with
datamembers having different values.
class Student {
int roll_no;
String name;
Student(int r, String n) {
roll_no = r;

Page 5 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

name=n;
}
void display() {
System.out.println("Roll no is: "+roll_no);
System.out.println("Name is : "+name);
}
public static void main(String a[]) {
Student s = new Student(20,"ABC");
s.display();
}
}

4. Copy Constructor : A copy constructor is a constructor that creates


a new object using an existing object of the same class and initializes
each instance variable of newly created object with corresponding
instance variables of the existing object passed as argument. This
constructor takes a single argument whose type is that of the class
containing the constructor.
class Rectangle
{
int length;
int breadth;
Rectangle(int l, int b)
{
length = l;
breadth= b;
}
//copy constructor
Rectangle(Rectangle obj)
{
length = obj.length;
breadth= obj.breadth;
}
public static void main(String[] args)
{
Rectangle r1= new Rectangle(5,6);
Rectangle r2= new Rectangle(r1);
System.out.println("Area of First Rectangle : "+
(r1.length*r1.breadth));

Page 6 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

System .out.println("Area of First Second Rectangle : "+


(r1.length*r1.breadth));
}
}
c) Explain the two ways of creating threads in Java. 4M
Ans. Thread is a independent path of execution within a program.
There are two ways to create a thread:
1. By extending the Thread class.
Thread class provide constructors and methods to create and perform 2M
operations on a thread. This class implements the Runnable interface. each for
When we extend the class Thread, we need to implement the method explaini
run(). Once we create an object, we can call the start() of the thread ng of
class for executing the method run(). two
Eg: types
class MyThread extends Thread { with
public void run() { example
for(int i = 1;i<=20;i++) {
System.out.println(i);
}
}
public static void main(String a[]) {
MyThread t = new MyThread();
t.start();
}
}
a. By implementing the runnable interface.
Runnable interface has only on one method- run().
Eg:
class MyThread implements Runnable {
public void run() {
for(int i = 1;i<=20;i++) {
System.out.println(i);
}
}
public static void main(String a[]) {
MyThread m = new MyThread();
Thread t = new Thread(m);
t.start();
}

Page 7 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

d) Distinguish between Input stream class and output stream class. 4M


Ans. Java I/O (Input and Output) is used to process the input and produce
the output.
Java uses the concept of a stream to make I/O operation fast. The
java.io package contains all the classes required for input and output
operations. A stream is a sequence of data. In Java, a stream is
composed of bytes. Any
four
Sr. Input stream class Output stream class points
No. for input
1 Java application uses an Java application uses an output stream
input stream to read data stream to write data to a class
from a source; destination;. and
2 It may read from a file, an It may be a write to file, an output
array, peripheral device or array, peripheral device or stream
socket socket class 1M
3 Input stream classes reads Output stream classes writes each
data as bytes data as bytes
4 Super class is the abstract Super class is the abstract
inputStream class OutputStream class
5 Methods: Methods:
public int read() throws public void write(int b) throws
IOException IOException
public int available() public void write(byte[] b)
throws IOException throws IOException
public void close() throws public void flush() throws
IOException IOException
public void close() throws
IOException
6 The different subclasses The different sub classes of
of Input Stream are: Output Stream class are:
File Input stream, File Output Stream,
Byte Array Input Stream, Byte Array Output Stream ,
Filter Input Stream, Filter output Stream,
Piped Input Stream, Piped Output Stream,
Object Input Stream, Object Output Stream,
DataInputStream. DataOutputStream

Page 8 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

3. Attempt any THREE of the following: 12


a) Define a class student with int id and string name as data 4M
members and a method void SetData ( ). Accept and display the
data for five students.
Ans. import java.io.*;
class student
{
int id;
String name;
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
void SetData() Correct
{ logic 4M
try
{
System.out.println("enter id and name for student");
id=Integer.parseInt(br.readLine());
name=br.readLine();
}
catch(Exception ex)
{}
}
void display()
{
System.out.println("The id is " + id + " and the name is "+ name);
}
public static void main(String are[])
{
student[] arr;
arr = new student[5];
int i;
for(i=0;i<5;i++)
{
arr[i] = new student();
}
for(i=0;i<5;i++)
{
arr[i].SetData();
}

Page 9 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

for(i=0;i<5;i++)
{
arr[i].display();
}
}
}
b) Explain dynamic method dispatch in Java with suitable example. 4M
Ans. Dynamic method dispatch is the mechanism by which a call to an
overridden method is resolved at run time, rather than compile time.
 When an overridden method is called through a superclass
reference, Java determines which version (superclass/subclasses) of
that method is to be executed based upon the type of the object being
referred to at the time the call occurs. Thus, this determination is
made at run time.
 At run-time, it depends on the type of the object being referred to
Explana
(not the type of the reference variable) that determines which version
tion 2M
of an overridden method will be executed
 A superclass reference variable can refer to a subclass object. This
is also known as upcasting. Java uses this fact to resolve calls to
overridden methods at run time.
Therefore, if a superclass contains a method that is overridden by a
subclass, then when different types of objects are referred to through
a superclass reference variable, different versions of the method are
executed. Here is an example that illustrates dynamic method
dispatch:
// A Java program to illustrate Dynamic Method
// Dispatch using hierarchical inheritance
class A
{
void m1()
{
System.out.println("Inside A's m1 method");
}
}
Example
2M
class B extends A
{
// overriding m1()
void m1()

Page 10 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

{
System.out.println("Inside B's m1 method");
}
}

class C extends A
{
// overriding m1()
void m1()
{
System.out.println("Inside C's m1 method");
}
}

// Driver class
class Dispatch
{
public static void main(String args[])
{
// object of type A
A a = new A();

// object of type B
B b = new B();

// object of type C
C c = new C();

// obtain a reference of type A


A ref;

// ref refers to an A object


ref = a;

// calling A's version of m1()


ref.m1();

// now ref refers to a B object


ref = b;

Page 11 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

// calling B's version of m1()


ref.m1();

// now ref refers to a C object


ref = c;

// calling C's version of m1()


ref.m1();
}
}
c) Describe the use of following methods: 4M
(i) Drawoval ( )
(ii) getFont ( )
(iii) drawRect ( )
(iv) getFamily ( )
Ans. (i) Drawoval ( ): Drawing Ellipses and circles: To draw an Ellipses
or circles used drawOval() method can be used. Syntax: void
drawOval(int top, int left, int width, int height) The ellipse is drawn
within a bounding rectangle whose upper-left corner is specified by
top and left and whose width and height are specified by width and
height.To draw a circle or filled circle, specify the same width and Each
height. method
1M
Example: g.drawOval(10,10,50,50);

(ii) getFont ( ): It is a method of Graphics class used to get the font


property
Font f = g.getFont();
String fontName = f.getName();
Where g is a Graphics class object and fontName is string containing
name of the current font.

(iii) drawRect ( ): The drawRect() method display an outlined


rectangle.
Syntax: void drawRect(int top,int left,int width,int height)
The upper-left corner of the Rectangle is at top and left. The
dimension of the Rectangle is specified by width and height.
Example: g.drawRect(10,10,60,50);

Page 12 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

(iv) getFamily ( ): The getfamily() method Returns the family of the


font.
String family = f.getFamily();
Where f is an object of Font class
d) Write a program to count number of words from a text file using 4M
stream classes.
(Note : Any other relevant logic shall be considered)
Ans. import java.io.*;
public class FileWordCount
{
public static void main(String are[]) throws IOException
{
File f1 = new File("input.txt");
int wc=0;
FileReader fr = new FileReader (f1); Correct
int c=0; program
try 4M
{
while(c!=-1)
{
c=fr.read();
if(c==(char)' ')
wc++;
}
System.out.println("Number of words :"+(wc+1));
}
finally
{
if(fr!=null)
fr.close();
}
}
}
4. Attempt any THREE of the following: 12
a) Describe instance Of and dot (.) operators in Java with suitable 4M
example.
Ans. Instance of operator:
The java instance of operator is used to test whether the object is an
instance of the specified type (class or subclass or interface).

Page 13 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

The instance of in java is also known as type comparison operator


because it compares the instance with type. It returns either true or
false. If we apply the instance of operator with any variable that has
null value, it returns false.
Example
class Simple1{ Descript
public static void main(String args[]){ ion and
Simple1 s=new Simple1(); example
of each
System.out.println(sinstanceofSimple1);//true
operator
} 2M
}

dot (.) operator:


The dot operator, also known as separator or period used to separate a
variable or method from a reference variable. Only static variables or
methods can be accessed using class name. 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.
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’.
b) Explain the four access specifiers in Java. 4M
Ans. There are 4 types of java access modifiers:
1. private 2. default 3. Protected 4. public

1) private access modifier: The private access modifier is accessible


only within class. Each
2) default access specifier: If you don’t specify any access control access
specifier, it is default, i.e. it becomes implicit public and it is specifier
accessible within the program. s 1M
3) protected access specifier: The protected access specifier is
accessible within package and outside the package but through
inheritance only.
4) public access specifier: The public access specifier is accessible
everywhere. It has the widest scope among all other modifiers.

Page 14 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

c) Differentiate between method overloading and method 4M


overriding.
Ans. Sr. Method overloading Method overriding
No.
1 Overloading occurs when Overriding means having two
two or more methods in methods with the same
one class have the same method name and parameters Any
method name but different (i.e., method signature) four
parameters. points
2 In contrast, reference type The real object type in the 1M each
determines which run-time, not the reference
overloaded method will be variable's type, determines
used at compile time. which overridden method is
used at runtime
3 Polymorphism not applies Polymorphism applies to
to overloading overriding
4 overloading is a compile- Overriding is a run-time
time concept. concept
d) Differentiate between Java Applet and Java Application (any 4M
four points)
Ans. Sr. Java Applet Java Application
No.
1 Applets run in web pages Applications run on stand-
alone systems.
2 Applets are not full Applications are full featured
featured application programs.
programs. Any
3 Applets are the small Applications are larger four
programs. programs. points
4 Applet starts execution Application starts execution 1M each
with its init(). with its main ().
5 Parameters to the applet Parameters to the application
are given in the HTML are given at the command
file. prompt
6 Applet cannot access the Application can access the
local file system and local file system and
resources resources.
7 Applets are event driven Applications are control
driven.

Page 15 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

e) Write a program to copy content of one file to another file. 4M


Ans. class fileCopy
{
public static void main(String args[]) throws IOException
{
FileInputStream in= new FileInputStream("input.txt");
FileOutputStream out= new FileOutputStream("output.txt");
int c=0; Correct
try logic 2M
{
while(c!=-1)
{
c=in.read(); Correct
out.write(c); Syntax
} 2M
System.out.println("File copied to output.txt....");
}
finally
{
if(in!=null)
in.close();
if(out!=null)
out.close();
}
}
}
5. Attempt any TWO of the following: 12
a) Describe the use of any methods of vector class with their syntax. 6M
(Note: Any method other than this but in vector class shall be
considered for answer).
Ans.  boolean add(Object obj)-Appends the specified element to the
end of this Vector.
 Boolean add(int index,Object obj)-Inserts the specified element at Any 6
the specified position in this Vector. methods
 void addElement(Object obj)-Adds the specified component to with
the end of this vector, increasing its size by one. their use
 int capacity()-Returns the current capacity of this vector. 1M each
 void clear()-Removes all of the elements from this vector.
 Object clone()-Returns a clone of this vector.

Page 16 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

 boolean contains(Object elem)-Tests if the specified object is a


component in this vector.
 void copyInto(Object[] anArray)-Copies the components of this
vector into the specified array.
 Object firstElement()-Returns the first component (the item at
index 0) of this vector.
 Object elementAt(int index)-Returns the component at the
specified index.
 int indexOf(Object elem)-Searches for the first occurence of the
given argument, testing for equality using the equals method.
 Object lastElement()-Returns the last component of the vector.
 Object insertElementAt(Object obj,int index)-Inserts the specified
object as a component in this vector at the specified index.
 Object remove(int index)-Removes the element at the specified
position in this vector.
 void removeAllElements()-Removes all components from this
vector and sets its size to zero.
b) Explain the concept of Dynamic method dispatch with suitable 6M
example.
Ans. Method overriding is one of the ways in which Java supports Runtime
Polymorphism. Dynamic method dispatch is the mechanism by which
a call to an overridden method is resolved at run time, rather than
compile time.
When an overridden method is called through a superclass reference,
Explana
Java determines which version (superclass/subclasses) of that method
tion 3M
is to be executed based upon the type of the object being referred to at
the time the call occurs. Thus, this determination is made at run time.
At run-time, it depends on the type of the object being referred to (not
the type of the reference variable) that determines which version of
an overridden method will be executed
A superclass reference variable can refer to a subclass object. This is
also known as upcasting. Java uses this fact to resolve calls to
overridden methods at run time.
If a superclass contains a method that is overridden by a subclass,
then when different types of objects are referred to through a
superclass reference variable, different versions of the method are
executed. Here is an example that illustrates dynamic method
dispatch:

Page 17 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

/ A Java program to illustrate Dynamic Method


// Dispatch using hierarchical inheritance
class A
{
void m1()
{
System.out.println("Inside A's m1 method");
}
}
class B extends A
{
// overriding m1() Example
void m1() 3M
{
System.out.println("Inside B's m1 method");
}
}
class C extends A
{
// overriding m1()
void m1()
{
System.out.println("Inside C's m1 method");
}
}

// Driver class
class Dispatch
{
public static void main(String args[])
{
// object of type A
A a = new A();

// object of type B
B b = new B();

// object of type C
C c = new C();

Page 18 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

// obtain a reference of type A


A ref;

// ref refers to an A object


ref = a;

// calling A's version of m1()


ref.m1();

// now ref refers to a B object


ref = b;

// calling B's version of m1()


ref.m1();

// now ref refers to a C object


ref = c;

// calling C's version of m1()


ref.m1();
}
}

Output:
Inside A’s m1 method
Inside B’s m1 method
Inside C’s m1 method
Explanation:
The above program creates one superclass called A and it’s two
subclasses B and C. These subclasses overrides m1( ) method.
1. Inside the main() method in Dispatch class, initially objects of
type A, B, and C are declared.
2. A a = new A(); // object of type A
3. B b = new B(); // object of type B
C c = new C(); // object of type C

Page 19 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

c) Write a program to create two threads. One thread will display 6M


the numbers from 1 to 50 (ascending order) and other thread will
display numbers from 50 to 1 (descending order).
Ans. class Ascending extends Thread
{
public void run()
{
for(int i=1; i<=15;i++)
{
System.out.println("Ascending Thread : " + i); Creation
} of two
} threads
} 4M

class Descending extends Thread Creating


{ main to
public void run() create
{ and start
for(int i=15; i>0;i--) { objects
System.out.println("Descending Thread : " + i); of 2
} threads:
} 2M
}

public class AscendingDescending Thread


{
public static void main(String[] args)
{
Ascending a=new Ascending();
a.start();
Descending d=new Descending();
d.start();
}
}
6. Attempt any TWO of the following: 12
a) Explain the command line arguments with suitable example. 6M
Ans. Java Command Line Argument:
The java command-line argument is an argument i.e. passed at the
time of running the java program.

Page 20 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

The arguments passed from the console can be received in the java
program and it can be used as an input.
So, it provides a convenient way to check the behaviour of the
program for the different values. You can pass N (1,2,3 and so on)
numbers of arguments from the command prompt.
4M for
Command Line Arguments can be used to specify configuration explanat
information while launching your application. ion
There is no restriction on the number of java command line
arguments.
You can specify any number of arguments
Information is passed as Strings.
They are captured into the String args of your main method

Simple example of command-line argument in java

In this example, we are receiving only one argument and printing it.
To run this java program, you must pass at least one argument from
the command prompt.

class CommandLineExample
{
public static void main(String args[]){
System.out.println("Your first argument is: "+args[0]); 2M for
} example
}
compile by > javac CommandLineExample.java
run by > java CommandLineExample sonoo
b) Write a program to input name and salary of employee and 6M
throw user defined exception if entered salary is negative.
Ans. import java.io.*;
class NegativeSalaryException extends Exception Extende
{ d
public NegativeSalaryException (String str) Exceptio
{ n class
super(str); with
} construc
} tor 2M
public class S1

Page 21 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

{
public static void main(String[] args) throws IOException
{ Acceptin
BufferedReaderbr= new BufferedReader(new g data
InputStreamReader(System.in)); 1M
System.out.print("Enter Name of employee");
String name = br.readLine();
System.out.print("Enter Salary of employee");
int salary = Integer.parseInt(br.readLine()); Throwin
Try g user
{ defining
if(salary<0) Exceptio
throw new NegativeSalaryException("Enter Salary amount n with
isnegative"); try catch
System.out.println("Salary is "+salary); and
} throw
catch (NegativeSalaryException a) 3M
{
System.out.println(a);
}
}
}
c) Describe the applet life cycle in detail. 6M
Ans.

2M
Diagram

Below is the description of each applet life cycle method:


init(): The init() method is the first method to execute when the
applet is executed. Variable declaration and initialization operations

Page 22 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2019 EXAMINATION


MODEL ANSWER
Subject: Java Programming Subject Code: 22412

are performed in this method.

start(): The start() method contains the actual code of the applet that 4M
should run. The start() method executes immediately after descripti
the init() method. It also executes whenever the applet is restored, on
maximized or moving from one tab to another tab in the browser.

stop(): The stop() method stops the execution of the applet. The
stop() method executes when the applet is minimized or when
moving from one tab to another in the browser.

destroy(): The destroy() method executes when the applet window is


closed or when the tab containing the webpage is
closed. stop() method executes just before when destroy() method is
invoked. The destroy() method removes the applet object from
memory.

paint(): The paint() method is used to redraw the output on the applet
display area. The paint() method executes after the execution
of start() method and whenever the applet or browser is resized.
The method execution sequence when an applet is executed is:

 init()
 start()
 paint()
The method execution sequence when an applet is closed is:
 stop()
 destroy()

Page 23 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
SUMMER – 2022 EXAMINATION
Subject Name:Data Communication & Computer Network Model Answer Subject Code: 22414
Important Instructions to examiners:
1) The answers should be examined by key words and not as word-to-word as given in the model
XXXXX
answer scheme.
2) The model answer and the answer written by candidate may vary but the examiner may try to
assess the understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given more Importance
(Not applicable for subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components indicated in the
figure. The figures drawn by candidate and model answer may vary. The examiner may give
credit for any equivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed constant
values may vary and there may be some difference in the candidate’s answers and model
answer.
6) In case of some questions credit may be given by judgement on part of examiner of relevant
answer based on candidate’s understanding.
7) For programming language papers, credit may be given to any other program based on
equivalent concept.
8) As per the policy decision of Maharashtra State Government, teaching in English/Marathi and
Bilingual (English + Marathi) medium is introduced at first year of AICTE diploma Programme
from academic year 2021-2022. Hence if the students in first year (first and second semesters)
write answers in Marathi or bilingual language (English +Marathi), the Examiner shall consider
the same and assess the answer based on matching of concepts with model answer.

Q. Sub Answer Marking


No. Q. Scheme
N.

1 Attempt any FIVE of the following: 10 M

a) Define computer Network. 2M

Ans A computer network is a system that connects various independent computers in order to Correct
share information (data) and resources. definition-2
M
OR

A computer network is a collection of two or more computer systems that are linked
together. A network connection can be established using either cable or wireless media.

OR

A computer network is defined as a system that connects two or more computing devices
for transmitting and sharing information.

b) List types of multiplexing. 2M

Page No: 1 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans Following are the types of multiplexing: Correct
1. Frequency-Division Multiplexing types-2 M
2. Wavelength-Division Multiplexing
3. Time-Division Multiplexing
a) Synchronous Time-Division Multiplexing
b) Asynchronous Time-Division Multiplexing
c) List different types of errors 2M

Ans Single-Bit Error: 2 types-2 M


The term single-bit error means that only 1 bit of a given data unit (such as a byte,
character, or packet) is changed from 1 to 0 or from 0 to 1.
Burst Error:
The term burst error means that 2 or more bits in the data unit have changed from 1 to 0 or
from 0 to 1.
d) List different types of network connecting devices. 2M

Ans 1. Hub Any 4


a. Passive Hubs devices-2 M
b. Active Hubs
2. Bridges
3. Two-Layer Switches
4. Routers
5. Three-Layer Switches
6. Gateway
7. Modem
8. Repeaters
e) Define: 2M

(i) Bit rate


(ii) Baud rate

Ans i. Bit rate: Correct


Bit rate is defined as the transmission of a number of bits per second. definition -1
Bit Rate cannot determine the bandwidth. M each
ii. Baud rate:
Baud rate is defined as the number of signal units per second.
Baud rate can determine the amount of bandwidth necessary to send the signal.
f) List classes of IP addresses. 2M

Ans Class A, Class B, Class C, class D and Class E Correct


types-2 M

Page No: 2 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

g) Define following terms: - 2M


(i) Protocol
(ii) Bandwidth

Ans i) Protocol: Correct


A protocol is a set of rules that govern data communications. It represents an definition- 1
agreement between the communicating devices. Without a protocol, two devices M each
may be connected but not communicating, just as a person speaking French cannot
be understood by a person who speaks only Japanese.

ii) Bandwidth:
The bandwidth of a composite signal is the difference between the highest and the
lowest frequencies contained in that signal.
For example, if a composite signal contains frequencies between 1000 and 5000, its
bandwidth is 5000 - 1000, or 4000.

2. Attempt any THREE of the following: 12 M

a) Describe modes of communication. 4M

Ans o The way in which data is transmitted from one device to another device is known List-1M
as transmission mode. All 3 modes
o The transmission mode is also known as the communication mode. Explanation
with figure-
3M
The Transmission mode is divided into three categories:
o Simplex mode
o Half-duplex mode
o Full-duplex mode

Simplex mode

Page No: 3 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
o In Simplex mode, the communication is unidirectional, i.e., the data flow in one
direction.
o A device can only send the data but cannot receive it or it can receive the data but
cannot send the data.
o This transmission mode is not very popular as mainly communications require the
two-way exchange of data. The simplex mode is used in the business field as in
sales that do not require any corresponding reply.
o The radio station is a simplex channel as it transmits the signal to the listeners but
never allows them to transmit back.
o Keyboard and Monitor are the examples of the simplex mode as a keyboard can
only accept the data from the user and monitor can only be used to display the data
on the screen.

Fig: Simplex mode

Half-Duplex mode

o In a Half-duplex channel, direction can be reversed, i.e., the station can transmit and
receive the data as well.
o Messages flow in both the directions, but not at the same time.
o The entire bandwidth of the communication channel is utilized in one direction at a
time.
o In half-duplex mode, it is possible to perform the error detection, and if any error
occurs, then the receiver requests the sender to retransmit the data.
o A Walkie-talkie is an example of the Half-duplex mode. In Walkie-talkie, one party
speaks, and another party listens. After a pause, the other speaks and first party
listens. Speaking simultaneously will create the distorted sound which cannot be
understood.

Page No: 4 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

Fig: Half-Duplex mode

Full-duplex mode
o In Full duplex mode, the communication is bi-directional, i.e., the data flow in both
the directions.
o Both the stations can send and receive the message simultaneously.
o Full-duplex mode has two simplex channels. One channel has traffic moving in one
direction, and another channel has traffic flowing in the opposite direction.
o The Full-duplex mode is the fastest mode of communication between devices.
o The most common example of the full-duplex mode is a telephone network. When
two people are communicating with each other by a telephone line, both can talk and
listen at the same time.

Fig: Full -Duplex mode


b) Explain 802.11 Architecture. 4M

Ans IEEE 802.11 BSS:


IEEE has defined the specifications for a wireless LAN, called IEEE 802.11, which explanation
covers the physical and data link layers with fig:2M

Architecture: ESS:
The standard defines two kinds of services: the basic service set (BSS) and the extended
explanation
service set (ESS).
with fig:2M

Basic Service Set


IEEE 802.11 defines the basic service set (BSS) as the building block of a wireless
LAN.
Page No: 5 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
A basic service set is made of stationary or mobile wireless stations and an optional
central base station, known as the access point (AP).
Figure shows two sets in this standard. The BSS without an AP is a stand-alone network
and cannot send data to other BSSs. It is called an ad hoc architecture.

In this architecture, stations can form a network without the need of an AP; they can
locate one another and agree to be part of a BSS. A BSS with an AP is sometimes
referred to as an infrastructure network.

Fig:basic service set (BSS)

Extended Service Set


An extended service set (ESS) is made up of two or more BSSs with APs. In this case,
the BSSs are connected through a distribution system, which is usually a wired LAN.
The distribution system connects the APs in the BSSs. IEEE 802.11 does not restrict the
distribution system; it can be any IEEE LAN such as an Ethernet. Note that the
extended service set uses two types of stations: mobile and stationary. The mobile
stations are normal stations inside a BSS. The stationary stations are AP stations that are
part of a wired LAN. Figure shows an ESS.

Fig: Extended service set (ESS)

When BSSs are connected, the stations within reach of one another can communicate
without the use of an AP. However, communication between two stations in two
different BSSs usually occurs via two APs. The idea is similar to communication in a
cellular network if we consider each BSS to be a cell and each AP to be a base station.
Note that a mobile station can belong to more than one BSS at the same time.
c) Explain Bluetooth Architecture. 4M

Ans Bluetooth technology is the implementation of a protocol defined by the IEEE 802.15 Explanation
standard. of Piconet
Page No: 6 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
with
Architecture diagram-2M
Bluetooth defines two types of networks: piconet and scatternet.

Piconets: Explaination
of Scatternet
A Bluetooth network is called a piconet, or a small net. A piconet can have up to eight
with
stations, one of which is called the primary;t the rest are called secondaries. All the
diagram-2M
secondary stations synchronize their clocks and hopping sequence with the primary. Note
that a piconet can have only one primary station. The communication between the primary
and the secondary can be one-to-one or one-to-many. Figure shows a piconet.

Fig: Piconet

Although a piconet can have a maximum of seven secondaries, an additional eight


secondaries can be in the parked state. A secondary in a parked state is synchronized
with the primary, but cannot take part in communication until it is moved from the
parked state. Because only eight stations can be active in a piconet, activating a station
from the parked state means that an active station must go to the parked state.

Scatternet:
Piconets can be combined to form what is called a scatternet. A secondary station in one
piconet can be the primary in another piconet. This station can receive messages from
the primary in the first piconet (as a secondary) and, acting as a primary, deliver them to
secondaries in the second piconet. A station can be a member of two piconets. Figure
illustrates a scatternet.

Page No: 7 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

Fig: Scatternet
d) Draw a neat diagram of twisted pair cable and state its types. 4M

Ans A twisted pair consists of two conductors (normally copper), each with its own plastic Diagram with
insulation, twisted together, as shown in Figure. naming-2 m

All types -2M

Fig: Twisted pair cable

Types of Twisted–Pair Cables

There are two types of twisted pair cables −

 Unshielded Twisted Pair (UTP): These generally comprise of wires and insulators.

Unshielded twisted pair cables are classified into seven categories −

 Category 1 − UTP used in telephone lines with data rate < 0.1 Mbps
 Category 2 − UTP used in transmission lines with a data rate of 2 Mbps
 Category 3 − UTP used in LANs with a data rate of 10 Mbps
 Category 4 − UTP used in Token Ring networks with a data rate of 20 Mbps
 Category 5 − UTP used in LANs with a data rate of 100 Mbps
 Category 6 − UTP used in LANs with a data rate of 200 Mbps
 Category 7 − STP used in LANs with a data rate of 10 Mbps

 Shielded Twisted Pair ( STP ): STP cable has a metal foil or braided mesh covering
Page No: 8 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
that encases each pair of insulated conductors.

3. Attempt any THREE of the following: 12 M

a) Describe the components of data communication with neat diagram. 4M

Ans Components of data communication: - 2M for block


diagram
2M for
explanations

Figure: components of data communication.


1. Message - It is the information to be communicated. Popular forms of information
include text, pictures, audio, video etc. Text is converted to binary, number doesn’t
converted, image is converted to pixels, etc.

2. Sender - It is the device which sends the data messages. It can be a computer,
workstation, telephone handset etc.

3. Receiver - It is the device which receives the data messages. It can be a computer,
workstation, telephone handset etc.

4. Transmission Medium - It is the physical path by which a message travels from sender
to receiver. Some examples include twisted-pair wire, coaxial cable, radio waves etc.

5. Protocol - It is a set of rules that governs the data communications. It represents an


agreement between the communicating devices. Without a protocol, two devices may be
connected but not communicating.

b) Explain LRC with example. 4M

Ans Longitudinal redundancy check 2M for


explanation
 Longitudinal Redundancy Check (LRC) is the error detection method which is used and 2M for
by upper layers to detect error in data. example
 The other name for LRC is 2-D parity check. In this method, data which the users
want to send is organized into tables of rows and columns.
 To detect an error, a redundant bit is added to the whole block after addition this
block is transmitted to receiver side.
 This redundant bit is used by receiver to detect error. If there is no error, receiver
accepts the data and discards the redundant row of bits.

Page No: 9 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

Example

If a block of 32 bits is to be transmitted, it is divided into matrix of four rows and eight
columns which as shown in the following figure:

Figure: LRC

In this matrix of bits, a parity bit (odd or even) is calculated for each column. It means 32
bits data plus 8 redundant bits are transmitted to receiver. Whenever data reaches at the
destination, receiver uses LRC to detect error in data.
Advantage:
LRC is used to detect burst errors.
c) Describe line of sight transmission. 4M

Ans Line of sight communication Explanation-


 Line of sight (LoS) is a type of communication that can transmit and receive data 3M
only where transmit and receive stations are in view of each other without any sort Diagram-1M
of an obstacle between them.
 Transmitting and receiving media should be in line of sight.
 In line of sight communication, very high frequency signals are transmitted in
straight lines directly from antenna to antenna.
 Antenna must be directional, facing each other, and either tall enough or close
enough together not to be effected by the curvature of earth.
 Above 30 MHz, neither ground wave nor sky wave propagation modes operate, and
communication must be by line of sight
 For satellite communication, a signal above 30 MHz is not reflected by the
ionosphere and therefore a signal can be transmitted between an earth station and a
satellite overhead that is not beyond the horizon. For ground-based communication,

Page No: 10 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
the transmitting and receiving antennas must be within an effective line of sight of
each other.

This is better understood with the help of the following diagram:

The figure depicts this mode of propagation very clearly. The line-of-sight propagation will
not be smooth if there occurs any obstacle in its transmission path. As the signal can travel
only to lesser distances in this mode, this transmission is used for infrared or microwave
transmissions.

d) Describe various mobile generations in detail. 4M

Ans 1G – First generation 1M for any


four correct
1G refers to the first generation of wireless mobile communication where analog signals generations
were used to transmit data. It was introduced in the US in early 1980s and designed along with
exclusively for voice communication. two features
Features:


Speeds up to 2.4 kbps
 Poor voice quality
 Large phones with limited battery life
 No data security
 Used analog signals
2G-Second generation

2G refers to the second generation of mobile telephony which used digital signals for the
first time. It was launched in Finland in 1991 and used GSM technology.
2G networks used digital technology.
It implemented the concept of CDMA and GSM. Provided small data services like sms and
mms.
2G capabilities are achieved by allowing multiple users on a single channel via
multiplexing.

Page No: 11 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Features:

 Data speeds up to 64 kbps


 Text and multimedia messaging possible
 Better quality than 1G
 2G requires strong digital signals to help mobile phones work. If there is no
network coverage in any specific area, digital signals would weak.
 These systems are unable to handle complex data such as Videos.
When GPRS technology was introduced, it enabled web browsing, e-mail services and fast
upload/download speeds. 2G with GPRS is also referred as 2.5G, a step short of next
mobile generation
3G- Third generations
Third generation (3G) of mobile telephony began with the start of the new millennium and
offered major advancement over previous generations.
3G has multimedia services support along with streaming. In 3G universal access and
portability across different devices types are made possible.
3G increased the efficiency of frequency spectrum by improving how audio is compressed
during a call. so more simultaneous calls can take place in same frequency range.
Like 2G, 3G evolved into 3.5G and 3.75G as more features were introduced in order to
bring about 4G.
Features:
 Data speeds of 144 kbps to 2 Mbps
 High speed web browsing
 Running web based applications like video conferencing, multimedia e-mails,
etc.
 Fast and easy transfer of audio and video files
 3D gaming
 TV Streaming/ Mobile TV/ Phone Calls MUM1 Large Capacities and
Broadband Capabilities
 Expensive fees for 3G Licenses Services

4G- Fourth generation


The main purpose of 4G is to provide high speed, high quality and high capacity to
users while improving security and lower the cost of voice and date services,
multimedia and internet over IP.

Fourth Generation (4G) mobile phones provides broadband cellular network


services and is successor to 3G mobile networks. It provides an all IP based cellular
communications. The capabilities provided adhere to IMT-Advanced specifications
as laid down by International Telecommunication Union (ITU).

Page No: 12 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

Features
 It provides an all IP packet switched network for transmission of voice, data,
signals and multimedia.
 It aims to provide high quality uninterrupted services to any location at any
time.
 As laid down in IMT-Advanced specifications, 4G networks should have
peak data rates of 100Mbps for highly mobile stations like train, car etc., and
1Gbps for low mobility stations like residence etc.
 It also lays down that 4G networks should make it possible for 1 Gbps
downlink over less than 67 MHz bandwidth.
 They provide have smooth handoffs across heterogeneous network areas.

5G- Fifth generation

 5G is the 5th generation mobile network. It is a new global wireless standard after
1G, 2G, 3G, and 4G networks. 5G enables a new kind of network that is designed to
connect virtually everyone and everything together including machines, objects, and
devices.
5G wireless technology is meant to deliver higher multi-Gbps peak data
speeds, ultra low latency, more reliability, massive network capacity, increased
availability, and a more uniform user experience to more users. Higher performance
and improved efficiency empower new user experiences and connects new
industries.
Features
 High Speed, High Capacity 5G technology providing large broadcasting of data in
Gbps.
 Multi - Media Newspapers, watch T. V pro clarity as to that of an HD Quality.
 Faster data transmission that of the previous generations.
 Large Phone Memory, Dialing Speed, clarity in Audio/Video.
 Support interactive multimedia, voice, streaming video, Internet and other
 5G is More Effective and More Attractive.

4. Attempt any THREE of the following: 12 M

a) Consider a network with 8 computers, which network architecture should be 4M


used peer to peer or Client Server? Justify the answer

Ans In the question it is given that we are supposed to consider eight computers. Both For valid
architecture can be considered depending upon the requirement. for eight explanation
computers I would like to prefer Peer to Peer network architecture. 4M : either
peer to peer
Because
or client-
Page No: 13 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
 The number of computers or devices in the network is less than 15. For peer to peer server
network less than 10 devices shows good performance.
 Data security is not the top priority
 Networking is mainly required for hardware sharing.
 Advanced sharing is not required.
 Additional networking features are not required.
 The administrator personally knows all users of the network.
 The above conditions are usually fulfilled in home and small office networks. Thus,
peer-to-peer networking is mostly used in home and small office networks.
 Less costly

Also if security is in priority and cost is not the consideration then I would prefer client
server network it will provide a stable network.

b) Compare packet switched and circuit switched network. 4M

Ans Packet switching and circuit switching comparison 1 mark for


each
Packet switching circuit switching
difference:
In-circuit switching has there are 3 phases: In Packet switching directly data transfer any
i)Connection Establishment. takes place.
ii) Data Transfer. 4 points 4 M
iii) Connection Released.
In-circuit switching, each data unit knows In Packet switching, each data unit just
the entire path address which is provided knows the final destination address
by the source. intermediate path is decided by the routers.
In Packet switching, data is processed at all
In-Circuit switching, data is processed at intermediate nodes including the source
the source system only system.
Resource reservation is the feature of
circuit switching because the path is fixed There is no resource reservation because
for data transmission. bandwidth is shared among users.
Wastage of resources is more in Circuit Less wastage of resources as compared to
Switching Circuit Switching
Transmission of the data is done not only
Transmission of the data is done by the by the source but also by the intermediate
source. routers.
Congestion can occur during the
connection establishment phase because Congestion can occur during the data
there might be a case where a request is transfer phase; a large number of packets
being made for a channel but the channel is comes in no time.
already occupied.
Circuit switching is not convenient for Packet switching is suitable for handling

Page No: 14 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
handling bilateral traffic. bilateral traffic.
In-Circuit switching, the charge depends on
time and distance, not on traffic in the In Packet switching, the charge is based on
network. the number of bytes and connection time.
Recording of packets is never possible in Recording of packets is possible in packet
circuit switching. switching.
In-Circuit Switching there is a physical In Packet Switching there is no physical
path between the source and the destination path between the source and the destination
Circuit Switching does not support store Packet Switching supports store and
and forward transmission forward transmission
No call setup is required in packet
Call setup is required in circuit switching. switching.
In-circuit switching each packet follows the In packet switching packets can follow any
same route. route.
The circuit switching network is Packet switching is implemented at the
implemented at the physical layer. datalink layer and network layer
Circuit switching requires simple protocols Packet switching requires complex
for delivery. protocols for delivery.
c) List the protocols related to all layers of OSI reference model 4M

Ans 1 M for two


protocol each
layer.
consider any
four layer in
case of all
correct.

d) Explain satellite communication. 4M

Page No: 15 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans 1. Satellite is a manmade system which is kept in continuous rotation around the earth 2M diagram
in a specific orbit at a specific height above the earth and with specific speed.
2M for
2. In satellite communication, signal transferring between the sender and receiver is
explanation
done with the help of satellite.
3. In this process, the signal which is basically a beam of modulated microwaves is
sent towards the satellite called UPLINK (6 GHz).
4. Then the satellite amplifies the signal and sent it back to the receiver’s antenna
present on the earth’s surface called as DOWNLINK (4Ghz), as shown in the
diagram given

5 . As the entire signal transferring is happening in space. Thus this type of communication
is known as space communication. The satellite does the functions of an antenna and the
Page No: 16 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
repeater together. If the earth along with its ground stations is revolving and the satellite is
stationery, the sending and receiving earth stations and the satellite can be out of sync over
time.

6. Therefore Geosynchronous satellites are used which move at same RPM as that of the
earth in the same direction.

7. So the relative position of the ground station with respect to the satellite never changes.

8. However 3 satellites are needed to cover earth’s surface entirely.

e) Describe the process of DHCP server configuration. 4M

Ans Configuring the DHCP Server Step by step


procedure
To configure the DHCP server: 4M

1. From the Control Panel, go to Administrative Tools >> Computer Management >>
Services and Application >> DHCP.

2. From the Action menu, select New Scope. The New Scope wizard is displayed.

3. Enter the following information as prompted:

 Scope name and description:


 IP address range (for example, 192.168.0.170 to 192.168.0.171)
 Subnet mask (for example, 255.255.255.0)
 Add exclusions (do not exclude any IP addresses)
 Lease duration (accept the default of 8 days)
 Router (default gateway) of your subnet (for example, 192.168.0.1)
 Domain name, WINS server (these are not needed)
 Activate Scope? (select “Yes, I want to activate this scope now”)
4. Click Finish to exit the wizard. The contents of the DHCP server are listed.

5. Right-click Scope [iPad dress] scope-name and select Properties.

6. In the Scope Properties box, click the Advanced tab.

7. Select BOOTP only, set the lease duration to Unlimited, and click OK.

8. Right-click Reservations. The Controller A Properties box is displayed. 9. Enter the IP


address and the MAC address for Controller A. Click Add. The Controller B Properties box
is displayed

10. Enter the IP address and the MAC address for Controller B. Click Add. The
controllers are added to the right of the Reservations listing.

Page No: 17 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
11. Right-click Scope [iPad dress] scope-name to disable the scope.

12. Click Yes to confirm disabling of the scope.

13. Right-click Scope and select Activate.

5. Attempt any TWO of the following: 12 M

a) Explain the working of hub, switch and bridge. 6M

Ans I. Hub: 2M each for


Hub, switch
Hubs are networking devices operating at a physical layer of the OSI model that are used to and Bridge
connect multiple devices in a network. They are generally used to connect computers in a
LAN.

Working:
A hub has many ports in it. A computer which intends to be connected to the network is
plugged in to one of these ports. When a data frame arrives at a port, it is broadcast to every
other port, without considering whether it is destined for a particular destination device or
not.

Features of Hubs
 A hub operates in the physical layer of the OSI model.
 A hub cannot filter data. It is a non-intelligent network device that sends message to
all ports.
 It primarily broadcasts messages. So, the collision domain of all nodes connected
through the hub stays one.
 Transmission mode is half duplex.

Page No: 18 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

Fig: working of Hub

II. Switch:

Switches are networking devices operating at layer 2 or a data link layer of the OSI model.
They connect devices in a network and use packet switching to send, receive or forward
data packets or data frames over the network.

Working:
A switch has many ports, to which computers are plugged in. When a data frame arrives at
any port of a network switch, it examines the destination address, performs necessary
checks and sends the frame to the corresponding device(s). It supports unicast, multicast as
well as broadcast communications.

Page No: 19 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

Fig: working of Switch

Features of Switches
 It is an intelligent network device that can be conceived as a multiport network
bridge.
 It uses MAC addresses (addresses of medium access control sublayer) to send data
packets to selected destination ports.
 It uses packet switching technique to receive and forward data packets from the
source to the destination device.
 It is supports unicast (one-to-one), multicast (one-to-many) and broadcast (one-to-
all) communications

III. Bridge:
Bridges are used to connect similar network segments.
It combines two LANs to form an extended LAN.

Working:
A bridge accepts all the packets and amplifies all of them to the other side. The bridges are
intelligent devices that allow the passing of only selective packets from them. A bridge only
passes those packets addressed from a node in one network to another node in the other
network.

Page No: 20 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

Figure – Bridge combines two LANs to form an extended LAN

b) Describe the procedure to configure the TCP/IP network layer services. 6M

Ans Before beginning configuration procedure, the following are the prerequisites. Step by step
procedure -
 Network hardware is installed and cabled. 6M
 TCP/IP software is installed.
To configure your TCP/IP network, the following steps are followed:

1) Read TCP/IP protocols for the basic organization of TCP/IP.


2) Minimally configure each host machine on the network.
This means adding a network adapter, assigning an IP address, and assigning
a
host name to each host, as well as defining a default route to your network.
For
background information on these tasks, refer to TCP/IP network
interfaces, TCP/IP addressing, and Naming hosts on your network.
3) Configure and start the intend daemon on each host machine on the network. Read
TCP/IP daemons and then follow the instructions in Configuring the intend daemon.
4) Configure each host machine to perform either local name resolution or to
use a name server. If a hierarchical Domain Name networks being set up, configure
at least one host to function as a name server.

5) If the network needs to communicate with any remote networks, configure


at least one host to function as a gateway. The gateway can use static routes or a
routing daemon to perform internetwork routing.

Page No: 21 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
6) Decide which services each host machine on the network will use.
By default, all services are available. Follow the instructions in Client network
services if you wish to make a particular service unavailable.

7) Decide which hosts on the network will be servers, and which services a
particular server will provide. Follow the instructions in Server network
services to start the server daemons you wish to run.

8) Configure any remote print servers that are needed.


9) Optional: If desired, configure a host to use or to serve as the master time
server for the network.
c) Explain multiplexing techniques. 6M

Ans Multiplexing is the set of techniques that allows the simultaneous transmission of multiple 2 M for 3
signals across a single data link. multiplexing

technique

with diagram

Frequency-Division Multiplexing

Frequency-division multiplexing (FDM) is an analog technique that can be applied when


the bandwidth of a link (in hertz) is greater than the combined bandwidths of the signals to
be transmitted. In FOM, signals generated by each sending device modulate different carrier
frequencies. These modulated signals are then combined into a single composite signal that
can be transported by the link. Carrier frequencies are separated by sufficient bandwidth to
accommodate the modulated signal. These bandwidth ranges are the channels through
which the various signals travel. Channels can be separated by strips of unused bandwidth-
guard bands-to prevent signals from overlapping. In addition, carrier frequencies must not
interfere with the original data frequencies.

Page No: 22 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

Fig: Frequency-Division Multiplexing

In above figure, the transmission path is divided into three parts, each representing a
channel that carries one transmission.

Wavelength-Division Multiplexing

Wavelength-division multiplexing (WDM) is designed to use the high-data-rate capability


of fiber-optic cable. The optical fiber data rate is higher than the data rate of metallic
transmission cable. Using a fiber-optic cable for one single line wastes the available
bandwidth. Multiplexing allows us to combine several lines into one.

WDM is conceptually the same as FDM, except that the multiplexing and de-multiplexing
involve optical signals transmitted through fiber-optic channels. The idea is the same: We
are combining different signals of different frequencies. The difference is that the
frequencies are very high.

Fig: Wavelength-Division Multiplexing

Time-Division Multiplexing

Time-division multiplexing (TDM) is a digital process that allows several connections to


share the high bandwidth of a linle Instead of sharing a portion of the bandwidth as in FDM,
time is shared. Each connection occupies a portion of time in the link.

Figure gives a conceptual view of TDM. Note that the same link is used as in FDM; here,
however, the link is shown sectioned by time rather than by frequency. In the figure,
portions of signals 1,2,3, and 4 occupy the link sequentially.

Page No: 23 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

Fig: Time-Division Multiplexing

We also need to remember that TDM is, in principle, a digital multiplexing technique.
Digital data from different sources are combined into one timeshared link. However, this
does not mean that the sources cannot produce analog data; analog data can be sampled,
changed to digital data, and then multiplexed by using TDM.

6. Attempt any TWO of the following: 12 M

a) Explain the working of following topologies: 6M

1) Bus 2) Ring 3) Tree

Ans Bus Topology: 2M each for


each
In networking, a topology that allows all network nodes to receive the same message topology
through the network cable at the same time is called as bus topology.

In this type of network topology, all the nodes of a network are connected to a common
transmission medium having two endpoints.

All the data that travels over the network is transmitted through a common transmission
medium known as the bus or the backbone of the network.

When the transmission medium has exactly two endpoints, the network topology is known
by the name, 'linear bus topology'. A network that uses a bus topology is referred to as a
“Bus Network”.

Working of Bus Topology:

Fig.shows bus topology. The central cable is the backbone of the network and is known as
Bus (thus the name). Every workstation or node communicates with the other device
through this Bus.

A signal from the source is broadcasted and it travels to all workstations connected to bus
cable. Although the message is broadcasted but only the intended recipient, whose MAC

Page No: 24 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
address or IP address matches, accepts it.

If the MAC/IP address of machine does not match with the intended address, machine
discards the signal. A terminator is added at ends of the central cable, to prevent bouncing
of signals. A barrel connector can be used to extend it.

Fig: Bus Topology

II.Ring Topology:

Ring topology is a network topology that is set-up in circular fashion. It is called ring
topology because it forms a ring as each computer is connected to another computer, with
the last one connected to the first. Exactly two neighbors for each device.
Each node in this topology contains repeater. A signal passes node to node, until it reaches
its destination. If a node receives a signal intended for another node its repeater regenerates
the signal and passes it.

Token is a special three-byte frame that travels around the ring network. It can flow
clockwise or anticlockwise. Ring topology is a point to point network.

The transmission is unidirectional, but it can be made bidirectional by having 2 connections


between each network node, it is called Dual Ring Topology.

In dual ring topology, two ring networks are formed, and data flow is in opposite direction
in them. Also, if one ring fails, the second ring can act as a backup, to keep the network up.

In a ring network, the data and the signals that pass over the network travel in a single
direction. In ring topology network arrangement, a signal is transferred sequentially using a
‘token’ from one node to the next.

Fig. shows a ring topology. The token travels along the ring until it reaches its destination.
Once, token reaches destination, receiving computer acknowledges receipt with a return
message to the sender. The sender then releases the token for the token for use by another
computer.

Page No: 25 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

Fig: Ring Topology

Tree Topology:
As its name implies in this topology devices make a tree structure. Tree topology integrates
the characteristics of star and bus topology.
• In tree topology, the number of star networks are connected using Bus. This main cable
seems like a main stem of a tree, and other star networks as the branches.
• It is also called expanded star topology. Ethernet protocol is commonly used in this type
of topology.
• Fig. shows tree topology. A tree topology can also combine characteristics of linear bus
and star topologies. It consists of groups of star configure workstations connected to a linear
bus backbone cable.
• Tree topologies allow for the expansion of an existing network and enable schools to
configure a network to meet their needs.

Fig: Tree Topology

b) Explain the working of OSI model layers. 6M

Page No: 26 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans Layered Architecture of ISO-OSI Model: 1M for
Diagram and
1. The basic idea of a layered architecture is to divide the ISO-OSI model into small pieces. 5M for
Each layer adds to the services provided by the lower layers in such a manner that the explanation
highest layer is provided a full set of services to manage communications and run the
applications.

2. A basic principle is to ensure independence of layers by defining services provided by


each layer to the next higher layer without defining how the services are to be performed.

3. In an n-layer architecture, layer n on one machine carries on conversation with the layer n
on other machine. The rules and conventions used in this conversation are collectively
known as the layer-n protocol.

7 Layers of OSI reference Model

ISO-OSI model has 7 layered architectures.

Functions of each layer are given below

Layer1: Physical Layer

1. It activates, maintains and deactivates the physical connection.

2. It is responsible for transmission and reception of the unstructured raw data over
network.

3. Voltages and data rates needed for transmission is defined in the physical layer.

4. It converts the digital/analog bits into electrical signal or optical signals.

5. Data encoding is also done in this layer.

Page No: 27 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Layer2: Data Link Layer

1. Data link layer synchronizes the information which is to be transmitted over the physical
layer.

2. The main function of this layer is to make sure data transfer is error free from one node to
another, over the physical layer.

3. Transmitting and receiving data frames sequentially is managed by this layer.

4. This layer sends and expects acknowledgements for frames received and sent
respectively. Resending of no acknowledgement received frames is also handled by this
layer.

Layer3: The Network Layer

1. Network Layer routes the signal through different channels from one node to other.

2. It acts as a network controller. It manages the Subnet traffic.

3. It decides by which route data should take.

4. It divides the outgoing messages into packets and assembles the incoming packets into
messages for higher levels.

Layer 4: Transport Layer

1. Transport Layer decides if data transmission should be on parallel path or single path.

2. Functions such as Multiplexing, Segmenting or Splitting on the data are done by this
layer

3. It receives messages from the Session layer above it, converts the message into smaller
units and passes it on to the Network layer.

4. Transport layer can be very complex, depending upon the network requirements.

Transport layer breaks the message (data) into small units so that they are handled more
efficiently by the network layer.

Layer 5: The Session Layer

1. Session Layer manages and synchronizes the conversation between two different
applications.

2. Transfer of data from source to destination session layer streams of data are marked and
are resynchronized properly, so that the ends of the messages are not cut prematurely and
data loss is avoided.

Page No: 28 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Layer 6: The Presentation Layer

1. Presentation Layer takes care that the data is sent in such a way that the receiver will
understand the information (data) and will be able to use the data.

2. While receiving the data, presentation layer transforms the data to be ready for the
application layer.

3. Languages(syntax) can be different of the two communicating systems. Under this


condition presentation layer plays a role of translator.

4. It performs Data compression, Data encryption, Data conversion etc.

Layer 7: Application Layer

1. Application Layer is the topmost layer.

2. Transferring of files disturbing the results to the user is also done in this layer. Mail
services, directory services, network resource etc are services provided by application layer.

3. This layer mainly holds application programs to act upon the received and to be sent data.

c) Explain ARP, subnetting and supernetting with example. 6M

Ans ARP: 2M each for


ARP,
Most of the computer programs/applications use logical address (IP address) to subnetting
send/receive messages, however, the actual communication happens over the physical and
address (MAC address) i.e from layer 2 of the OSI model. So our mission is to get the supernetting
destination MAC address which helps in communicating with other devices. This is where with example
ARP comes into the picture, its functionality is to translate IP address to physical
addresses.

ARP finds the hardware address, also known as Media Access Control (MAC) address, of
a host from its known IP address.
It is responsible to find the hardware address of a host from a know IP address there are
three basic ARP terms.
Page No: 29 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
The important terms associated with ARP are:
(i) Reverse ARP
(ii) Proxy ARP
(iii) Inverse ARP

Subnetting:

Dividing the network into smaller contiguous networks or subnets is called subnetting.
Suppose we take a network of class A. So, in class A, we have 2²⁴ hosts. So to manage
such a large number of hosts is tedious. So if we divide this large network into the smaller
network then maintaining each network would be easy.

Suppose we have a class C network having network ID as 201.10.1.0(range of class C


192–223). So the total number of hosts is 256(for class C host is defined by last octet i.e.
2⁸). But, the total usable host is 254. This is because the first IP address is for the network
ID and the last IP address is Direct Broadcast Address (for sending any packet from one
network to all other hosts of another network).

So, in subnetting we will divide these 254 hosts logically into two networks. In the above
class C network, we have 24 bits for Network ID and the last 8 bits for the Host ID.

Supernetting:

Supernetting is the opposite of Subnetting. In subnetting, a single big network is divided


into multiple smaller subnetworks. In Supernetting, multiple networks are combined into
a bigger network termed as a Supernetwork or Supernet.
Supernetting is mainly used in Route Summarization, where routes to multiple networks
with similar network prefixes are combined into a single routing entry, with the routing
entry pointing to a Super network, encompassing all the networks. This in turn
significantly reduces the size of routing tables and also the size of routing updates
exchanged by routing protocols.
More specifically, when multiple networks are combined to form a bigger network, it is
termed as super-netting
 Super netting is used in route aggregation to reduce the size of routing tables and routing
table updates
There are some points which should be kept in mind while supernetting:
1. All the IP address should be contiguous.
2. Size of all the small networks should be equal and must be in form of 2n.
3. First IP address should be exactly divisible by whole size of supernet.

For example:

Page No: 30 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

Page No: 31 | 31
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
WINTER – 2022 EXAMINATION
Subject Name: Java Programming Model Answer Subject Code: 22412

Important Instructions to examiners: XXXXX


1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme.
2) The model answer and the answer written by candidate may vary but the examiner may try to assess the
understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given more Importance (Not applicable for
subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components indicated in the figure. The figures
drawn by candidate and model answer may vary. The examiner may give credit for any equivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed constant values may vary and
there may be some difference in the candidate’s answers and model answer.
6) In case of some questions credit may be given by judgement on part of examiner of relevant answer based on
candidate’s understanding.
7) For programming language papers, credit may be given to any other program based on equivalent concept.
8) As per the policy decision of Maharashtra State Government, teaching in English/Marathi and Bilingual (English +
Marathi) medium is introduced at first year of AICTE diploma Programme from academic year 2021-2022. Hence if
the students in first year (first and second semesters) write answers in Marathi or bilingual language (English
+Marathi), the Examiner shall consider the same and assess the answer based on matching of concepts with
model answer.

Q. Sub Answer Marking


No. Q. N. Scheme

1 Attempt any FIVE of the following: 10 M

a) State any four relational operators and their use. 2M

Ans 2M (1/2 M
Operator Meaning
each)
< Less than Any Four
> Greater than
<= Less than or equal to
>= Greater than or equal to
== Equal to
!= Not equal to

b) Enlist access specifiers in Java. 2M

Ans The access specifiers in java specify accessibility (scope) of a data member, 2M (1/2 M
method, constructor or class. There are 5 types of java access specifier: each)
 public Any Four
 private

Page No: 1 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
 default (Friendly)
 protected
 private protected
c) Explain constructor with suitable example. 2M

Ans Constructors are used to assign initial value to instance variable of the class. 1M-
It has the same name as class name in which it resides and it is syntactically similar Explanation
to anymethod. 1M-
Constructors do not have return value, not even ‘void’ because they return the instance if Example
class.
Constructor called by new operator.
Example:
class Rect
{
int length, breadth;
Rect() //constructor
{
length=4; breadth=5;
}
public static void main(String args[])
{
Rect r = new Rect();
System.out.println(“Area : ” +(r.length*r.breadth));
}
}
Output : Area : 20
d) List the types of inheritance which is supported by java. 2M

Ans Any two

1 M each

Page No: 2 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

e) Define thread. Mention 2 ways to create thread. 2M

Ans 1. Thread is a smallest unit of executable code or a single task is also called as thread. 1 M-
2. Each tread has its own local variable, program counter and lifetime. Define
3. A thread is similar to program that has a single flow of control. Thread
There are two ways to create threads in java:
1M -2ways
1. By extending thread class to create
Syntax: - thread
class Mythread extends Thread
{
-----
}
2. Implementing the Runnable Interface
Syntax:
class MyThread implements Runnable
{
public void run()
{
------
}
f) Distinguish between Java applications and Java Applet (Any 2 points) 2M

Page No: 3 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans 1 M for
each point
(any 2
Applet Application Points)
Applet does not use main() Application use main() method
method for initiating execution of for initiating execution of code
code
Applet cannot run independently Application can run
independently
Applet cannot read from or write Application can read from or
to files in local computer write to files in local computer
Applet cannot communicate with Application can communicate
other servers on network with other servers on network
Applet cannot run any program Application can run any program
from local computer. from local computer.
Applet are restricted from using Application are not restricted
libraries from other language from using libraries from other
such as C or C++ language
Applets are event driven. Applications are control driven.

g) Draw the hierarchy of stream classes. 2M

Ans 2M-Correct
diagram

Fig: hierarchy of stream classes

Page No: 4 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
2. Attempt any THREE of the following: 12 M

a) Write a program to check whether the given number is prime or not. 4M

Ans Code: 4M (for any


correct
class PrimeExample program
{ and logic)

public static void main(String args[]){

int i,m=0,flag=0;

int n=7;//it is the number to be checked

m=n/2;

if(n==0||n==1){

System.out.println(n+" is not prime number");

}else{

for(i=2;i<=m;i++){

if(n%i==0){

System.out.println(n+" is not prime number");

flag=1;

break;

if(flag==0) { System.out.println(n+" is prime number"); }

}//end of else

Output:

7 is prime number

Page No: 5 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
b) Define a class employee with data members 'empid , name and salary. 4M
Accept data for three objects and display it
Ans class employee 4M (for
{ correct
int empid; program
String name; and logic)
double salary;
void getdata()
{
BufferedReader obj = new BufferedReader (new InputStreamReader(System.in));
System.out.print("Enter Emp number : ");
empid=Integer.parseInt(obj.readLine());
System.out.print("Enter Emp Name : ");
name=obj.readLine();
System.out.print("Enter Emp Salary : ");
salary=Double.parseDouble(obj.readLine());
}
void show()
{
System.out.println("Emp ID : " + empid);
System.out.println(“Name : " + name);
System.out.println(“Salary : " + salary);
}
}
classEmpDetails
{
public static void main(String args[])
{
employee e[] = new employee[3];
for(inti=0; i<3; i++)
{
e[i] = new employee(); e[i].getdata();
}
System.out.println(" Employee Details are : ");
for(inti=0; i<3; i++)
e[i].show();
}
}

Page No: 6 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
c) Describe Life cycle of thread with suitable diagram. 4M

Ans 1) Newborn State 1M-digram


A NEW Thread (or a Born Thread) is a thread that's been created but not yet of life
started. It remains in this state until we start it using the start() method. cycle
3M-
The following code snippet shows a newly created thread that's in the NEW state:
explanation
Runnable runnable = new NewState();

Thread t = new Thread(runnable);

2) Runnable State
It means that thread is ready for execution and is waiting for the availability of the
processor i.e. the thread has joined the queue and is waiting for execution. If all
threads have equal priority, then they are given time slots for execution in round
robin fashion. The thread that relinquishes control joins the queue at the end and
again waits for its turn. A thread can relinquish the control to another before its turn
comes by yield().
Runnable runnable = new NewState();
Thread t = new Thread(runnable); t.start();
3) Running State
It means that the processor has given its time to the thread for execution. The thread
runs until it relinquishes control on its own or it is pre-empted by a higher priority
thread.
4) Blocked State
A thread can be temporarily suspended or blocked from entering into the runnable
and running state by using either of the following thread method.

o suspend() : Thread can be suspended by this method. It can be rescheduled


by resume().
o wait(): If a thread requires to wait until some event occurs, it can be done
using wait method and can be scheduled to run again by notify().
o sleep(): We can put a thread to sleep for a specified time period using
sleep(time) where time is in ms. It reenters the runnable state as soon as
period has elapsed /over.
5) Dead State
Whenever we want to stop a thread form running further we can call its stop(). The
stop() causes the thread to move to a dead state. A thread will also move to dead
state automatically when it reaches to end of the method. The stop method may be
used when the premature death is required

Page No: 7 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

Fig: Life cycle of Thread


d) Write a program to read a file (Use character stream) 4M

Ans import java.io.FileWriter; 4M (for


import java.io.IOException; correct
public class IOStreamsExample { program
public static void main(String args[]) throws IOException { and logic)
//Creating FileReader object
File file = new File("D:/myFile.txt");
FileReader reader = new FileReader(file);
char chars[] = new char[(int) file.length()];
//Reading data from the file
reader.read(chars);
//Writing data to another file
File out = new File("D:/CopyOfmyFile.txt");
FileWriter writer = new FileWriter(out);
//Writing data to the file
writer.write(chars);
writer.flush();
System.out.println("Data successfully written in the specified file");
}
}

3. Attempt any THREE of the following: 12 M

Page No: 8 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
a) Write a program to find reverse of a number. 4M

Ans public class ReverseNumberExample1 Any


Correct
{ public static void main(String[] args) program
{ with proper
logic -4M
int number = 987654, reverse =0;

while(number !=0)

int remainder = number % 10;

reverse = reverse * 10 + remainder;

number = number/10;

System.out.printtln(“The reverse of the given number is: “ + reverse);

} }

b) State the use of final keyword with respect to inheritance. 4M

Ans Final keyword : The keyword final has three uses. First, it can be used to create the Use of final
equivalent of a named constant.( in interface or class we use final as shared constant or keyword-2
constant.) M
Program-2
Other two uses of final apply to inheritance
M
Using final to Prevent Overriding While method overriding is one of Java’s most powerful
features,
To disallow a method from being overridden, specify final as a modifier at the start of its
declaration. Methods declared as final cannot be overridden.
The following fragment illustrates final:
class A
{
final void meth()
{
System.out.println("This is a final method.");

Page No: 9 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
}
}
class B extends A
{
void meth()
{ // ERROR! Can't override.
System.out.println("Illegal!");
}
}
As base class declared method as a final , derived class can not override the definition of
base class methods.

c) Give the usage of following methods 4M


i) drawPolygon ()
ii) DrawOval ()
iii) drawLine ()
iv) drawArc ()
Ans i) drawPolygon (): Method use
with
 drawPolygon() method is used to draw arbitrarily shaped figures. description
 Syntax: void drawPolygon(int x[], int y[], int numPoints) 1M
 The polygon‟s end points are specified by the co-ordinates pairs contained within
the x and y arrays. The number of points define by x and y is specified by
numPoints.
Example: int xpoints[]={30,200,30,200,30};
int ypoints[]={30,30,200,200,30};
int num=5;
g.drawPolygon(xpoints,ypoints,num);
ii) drawOval ():
 To draw an Ellipses or circles used drawOval() method can be used.
 Syntax: void drawOval(int top, int left, int width, int height) The ellipse is drawn
within a bounding rectangle whose upper-left corner is specified by top and left
and whose width and height are specified by width and height to draw a circle or
filled circle, specify the same width and height the following program draws
several ellipses and circle.
 Example: g.drawOval(10,10,50,50);
ii) drawLine ():
 The drawLine() method is used to draw line which take two pair of coordinates,

Page No: 10 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
(x1,y1) and (x2,y2) as arguments and draws a line between them.
 The graphics object g is passed to paint() method.
 Syntax: g.drawLine(x1,y1,x2,y2);
 Example: g.drawLine(100,100,300,300;)
iv) drawArc ()
drawArc( ) It is used to draw arc.

Syntax: void drawArc(int x, int y, int w, int h, int start_angle, int sweep_angle);

where x, y starting point, w & h are width and height of arc, and start_angle is starting
angle of arc sweep_angle is degree around the arc

Example: g.drawArc(10, 10, 30, 40, 40, 90);

d) Write any four methods of file class with their use. 4M

Ans One
public String getName() Returns the name of the file or directory denoted by this method
abstract pathname.
public String getParent() Returns the pathname string of this abstract pathname's 1M
parent, or null if this pathname does not name a parent
directory
public String getPath() Converts this abstract pathname into a pathname string.
public boolean isAbsolute() Tests whether this abstract pathname is absolute. Returns
true if this abstract pathname is absolute, false otherwise
public boolean exists() Tests whether the file or directory denoted by this abstract
pathname exists. Returns true if and only if the file or
directory denoted by this abstract pathname exists; false
otherwise
public boolean isDirectory() Tests whether the file denoted by this abstract pathname is
a directory. Returns true if and only if the file denoted by
this abstract pathname exists and is a directory; false
otherwise.
public boolean isFile() Tests whether the file denoted by this abstract pathname is
a normal file. A file is normal if it is not a directory and, in
addition, satisfies other system-dependent criteria. Any
nondirectory file created by a Java application is guaranteed
to be a normal file. Returns true if and only if the file
denoted by this abstract pathname exists and is a normal
file; false otherwise.

4. Attempt any THREE of the following: 12 M

a) Write all primitive data types available in Java with their storage Sizes in 4M

Page No: 11 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
bytes.

Ans Data type


name, size
Data Type Size
and default
Byte 1 Byte
Short 2 Byte value and
Int 4 Byte description
Long 8 Byte carries 1 M
Double 8 Byte
Float 4 Byte
Char 2 Byte
boolean 1 Bit
b) Write a program to add 2 integer, 2 string and 2 float values in a vector. 4M
Remove the element specified by the user and display the list.

Ans import java.io.*; Correct


import java.lang.*; program- 4
import java.util.*; M, stepwise
class vector2 can give
{ marks
public static void main(String args[])
{
vector v=new vector();
Integer s1=new Integer(1);
Integer s2=new Integer(2);
String s3=new String("fy");
String s4=new String("sy");
Float s7=new Float(1.1f);
Float s8=new Float(1.2f);
v.addElement(s1);
v.addElement(s2);
v.addElement(s3);
v.addElement(s4);
v.addElement(s7);
v.addElement(s8);
System.out.println(v);
v.removeElement(s2);
v.removeElementAt(4);
System.out.println(v);
}
}
c) Develop a program to create a class ‘Book’ having data members author, title 4M
and price. Derive a class 'Booklnfo' having data member 'stock position’ and

Page No: 12 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
method to initialize and display the information for three objects.
Ans class Book Correct
{ program- 4
String author, title, publisher; M
Book(String a, String t, String p)
{
author = a;
title = t;
publisher = p;
}
}
class BookInfo extends Book
{
float price;
int stock_position;
BookInfo(String a, String t, String p, float amt, int s)
{
super(a, t, p);
price = amt;
stock_position = s;
}
void show()
{
System.out.println("Book Details:");
System.out.println("Title: " + title);
System.out.println("Author: " + author);
System.out.println("Publisher: " + publisher);
System.out.println("Price: " + price);
System.out.println("Stock Available: " + stock_position);
}
}
class Exp6_1
{
public static void main(String[] args)
{
BookInfo ob1 = new BookInfo("Herbert Schildt", "Complete Reference", "ABC
Publication", 359.50F,10);
BookInfo ob2 = new BookInfo("Ulman", "system programming", "XYZ Publication",
359.50F, 20);
BookInfo ob3 = new BookInfo("Pressman", "Software Engg", "Pearson Publication",
879.50F, 15);
ob1.show();

Page No: 13 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
ob2.show();
ob3.show();
}
}
OUTPUT
Book Details:
Title: Complete Reference
Author: Herbert Schildt
Publisher: ABC Publication
Price: 2359.5
Stock Available: 10
Book Details:
Title: system programming
Author: Ulman
Publisher: XYZ Publication
Price: 359.5
Stock Available: 20
Book Details:
Title: Software Engg
Author: Pressman
Publisher: Pearson Publication
Price: 879.5
Stock Available: 15

d) Mention the steps to add applet to HTML file. Give sample code. 4M

Ans Adding Applet to the HTML file: Steps – 2M


Steps to add an applet in HTML document Example –
1. Insert an <APPLET> tag at an appropriate place in the web page i.e. in the body section 2M
of HTML
file.
2. Specify the name of the applet’s .class file.
3. If the .class file is not in the current directory then use the codebase parameter to
specify:-
a. the relative path if file is on the local system, or
b. the uniform resource locator(URL) of the directory containing the file if it is on a remote
computer.
4. Specify the space required for display of the applet in terms of width and height in
pixels.
5. Add any user-defined parameters using <param> tags
6. Add alternate HTML text to be displayed when a non-java browser is used.
7. Close the applet declaration with the </APPLET> tag.
Open notepad and type the following source code and save it into file name

Page No: 14 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
“Hellojava.java”
import java.awt.*;
import java.applet.*;
public class Hellojava extends Applet
{
public void paint (Graphics g)
{
g.drawString("Hello Java",10,100);
}}
Use the java compiler to compile the applet “Hellojava.java” file.
C:\jdk> javac Hellojava.java
After compilation “Hellojava.class” file will be created. Executable applet is nothing but
the .class file
of the applet, which is obtained by compiling the source code of the applet. If any error
message is
received, then check the errors, correct them and compile the applet again.
We must have the following files in our current directory.
o Hellojava.java
o Hellojava.class
o HelloJava.html
If we use a java enabled web browser, we will be able to see the entire web page containing
the
applet.
We have included a pair of <APPLET..> and </APPLET> tags in the HTML body section.
The
<APPLET…> tag supplies the name of the applet to be loaded and tells the browser how
much space
the applet requires. The <APPLET> tag given below specifies the minimum requirements
to place the
HelloJava applet on a web page. The display area for the applet output as 300 pixels width
and 200
pixels height. CENTER tags are used to display area in the center of the screen.
<APPLET CODE = hellojava.class WIDTH = 400 HEIGHT = 200 > </APPLET>
Example: Adding applet to HTML file:
Create Hellojava.html file with following code:
<HTML>
<! This page includes welcome title in the title bar and displays a welcome message. Then
it specifies
the applet to be loaded and executed.
>
<HEAD> <TITLE> Welcome to Java Applet </TITLE> </HEAD>
<BODY> <CENTER> <H1> Welcome to the world of Applets </H1> </CENTER> <BR>
<CENTER>
Page No: 15 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
<APPLET CODE=HelloJava.class WIDTH = 400 HEIGHT = 200 > </APPLET>
</CENTER>
</BODY>
</HTML>
e) Write a program to copy contents of one file to another. 4M

Ans import java.io.*; Correct


class copyf program- 4
{ M
public static void main(String args[]) throws IOException
{
BufferedReader in=null;
BufferedWriter out=null;
try
{
in=new BufferedReader(new FileReader("input.txt"));
out=new BufferedWriter(new FileWriter("output.txt"));
int c;
while((c=in.read())!=-1)
{
out.write(c);
}
System.out.println("File copied successfully");
}
finally
{
if(in!=null)
{
in.close();
}
if(out!=null)
{
out.close();
}
}
}
}

5. Attempt any TWO of the following: 12 M

a) Compare array and vector. Explain elementAT( ) and addElement( ) methods. 6M

Ans
Page No: 16 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Sr. Array Vector
No.

1 An array is a structure that holds The Vector is similar to array holds


4 M for
multiple values of the same type. multiple objects and like an array; it
any 4
contains components that can be
correct
accessed using an integer index.
points
2 An array is a homogeneous data type Vectors are heterogeneous. You can
1 M for
where it can hold only objects of one have objects of different data types
elementAt()
data type. inside a Vector.
1 M for
3 After creation, an array is a fixed- The size of a Vector can grow or shrink
addElement
length structure. as needed to accommodate adding and
()
removing items after the Vector has
been created.

4 Array can store primitive type data Vector are store non-primitive type data
element. element

5 Array is unsynchronized i.e. Vector is synchronized i.e. when the


automatically increase the size when size will be exceeding at the time;
the initialized size will be exceed. vector size will increase double of
initial size.

6 Declaration of an array : Declaration of Vector:

int arr[] = new int [10]; Vector list = new Vector(3);

7 Array is the static memory allocation. Vector is the dynamic memory


allocation

8 Array allocates the memory for the Vector allocates the memory
fixed size ,in array there is wastage of dynamically means according to the
memory. requirement no wastage of memory.

9 No methods are provided for adding Vector provides methods for adding and
and removing elements. removing elements.

10 In array wrapper classes are not used. Wrapper classes are used in vector

11 Array is not a class. Vector is a class.

elementAT( ):

The elementAt() method of Java Vector class is used to get the element at the specified
Page No: 17 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
index in the vector. Or The elementAt() method returns an element at the specified index.

addElement( ):

The addElement() method of Java Vector class is used to add the specified element to the
end of this vector. Adding an element increases the vector size by one.

b) Write a program to create a class 'salary with data members empid', ‘name' 6M
and ‘basicsalary'. Write an interface 'Allowance’ which stores rates of
calculation for da as 90% of basic salary, hra as 10% of basic salary and pf as
8.33% of basic salary. Include a method to calculate net salary and display it.
Ans interface allowance 6 M for
{ correct
double da=0.9*basicsalary; program
double hra=0.1*basicsalary;
double pf=0.0833*basicsalary;
void netSalary();
}

class Salary
{
int empid;
String name;
float basicsalary;
Salary(int i, String n, float b)
{
empid=I;
name=n;
basicsalary =b;
}
void display()
{
System.out.println("Empid of Emplyee="+empid);
System.out.println("Name of Employee="+name);
System.out.println("Basic Salary of Employee="+ basicsalary);
}
}

class net_salary extends salary implements allowance


{
float ta;
net_salary(int i, String n, float b, float t)
{
Page No: 18 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
super(i,n,b);
ta=t;
}
void disp()
{
display();
System.out.println("da of Employee="+da);
}
public void netsalary()
{
double net_sal=basicsalary+ta+hra+da;
System.out.println("netSalary of Employee="+net_sal);
}
}
class Empdetail
{
public static void main(String args[])
{
net_salary s=new net_salary(11, “abcd”, 50000);
s.disp();
s.netsalary();
}
}
c) Define an exception called 'No Match Exception' that is thrown when the 6M
passward accepted is not equal to "MSBTE'. Write the program.

Ans import java.io.*; 6 M for


class NoMatchException extends Exception correct
{ program
NoMatchException(String s)
{
super(s);
}
}
class test1
{
public static void main(String args[]) throws IOException
{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in) );
System.out.println("Enter a word:");
String str= br.readLine();
try
{
Page No: 19 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
if (str.compareTo("MSBTE")!=0) // can be done with equals()
throw new NoMatchException("Strings are not equal");
else
System.out.println("Strings are equal");
}
catch(NoMatchException e)
{
System.out.println(e.getMessage());
}
}
}

6. Attempt any TWO of the following: 12 M

a) Write a program to check whether the string provided by the user is palindrome 6M
or not.

Ans import java.lang.*; 6 M for


correct
import java.io.*; program
import java.util.*;

class palindrome

public static void main(String arg[ ]) throws IOException

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter String:");

String word=br.readLine( );

int len=word.length( )-1;

int l=0;

int flag=1;

int r=len;

while(l<=r)

Page No: 20 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
if(word.charAt(l)==word.charAt(r))

l++;

r--;

else

flag=0;

break;

if(flag==1)

System.out.println("palindrome");

else

System.out.println("not palindrome");

b) Define thread priority ? Write default priority values and the methods to set 6M
and change them.
Ans Thread Priority: 2 M for
define
In java each thread is assigned a priority which affects the order in which it is scheduled for Thread
running. Threads of same priority are given equal treatment by the java scheduler. priority
Default priority values as follows 2 M for

Page No: 21 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
The thread class defines several priority constants as: - default
priority
MIN_PRIORITY =1 values

NORM_PRIORITY = 5

MAX_PRIORITY = 10
2 M for
Thread priorities can take value from 1-10. method to
set and
getPriority(): The java.lang.Thread.getPriority() method returns the priority of the given change
thread.

setPriority(int newPriority): The java.lang.Thread.setPriority() method updates or assign


the priority of the thread to newPriority. The method throws IllegalArgumentException if
the value newPriority goes out of the range, which is 1 (minimum) to 10 (maximum).

import java.lang.*;

public class ThreadPriorityExample extends Thread


{
public void run()
{
System.out.println("Inside the run() method");
}
public static void main(String argvs[])
{
ThreadPriorityExample th1 = new ThreadPriorityExample();
ThreadPriorityExample th2 = new ThreadPriorityExample();
ThreadPriorityExample th3 = new ThreadPriorityExample();
System.out.println("Priority of the thread th1 is : " + th1.getPriority());
System.out.println("Priority of the thread th2 is : " + th2.getPriority());
System.out.println("Priority of the thread th2 is : " + th2.getPriority());
th1.setPriority(6);
th2.setPriority(3);
th3.setPriority(9);
System.out.println("Priority of the thread th1 is : " + th1.getPriority());
System.out.println("Priority of the thread th2 is : " + th2.getPriority());
System.out.println("Priority of the thread th3 is : " + th3.getPriority());
System.out.println("Currently Executing The Thread : " + Thread.currentThread().gtName());
System.out.println("Priority of the main thread is : " + Thread.currentThread().getPrority();
Thread.currentThread().setPriority(10);
System.out.println("Priority of the main thread is : " + Thread.currentThread().getPiority());
}
Page No: 22 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
}
c) Design an applet to perform all arithmetic operations and display the result by using 6M
labels. textboxes and buttons.
Ans import java.awt.*; 6 M for
import java.awt.event.*; correct
public class sample extends Frame implements ActionListener { program
Label l1, l2,l3;
TextField tf1, tf2, tf3;
Button b1, b2, b3, b4;
sample() {
l1=new Lable(“First No.”);
l1.setBounds(10, 10, 50, 20);
tf1 = new TextField();
tf1.setBounds(50, 50, 150, 20);
l2=new Lable(“Second No.”);
l2.setBounds(10, 60, 50, 20);
tf2 = new TextField();
tf2.setBounds(50, 100, 150, 20);
l3=new Lable(“Result”);
l3.setBounds(10, 110, 150, 20);
tf3 = new TextField();
tf3.setBounds(50, 150, 150, 20);
tf3.setEditable(false);
b1 = new Button("+");
b1.setBounds(50, 200, 50, 50);
b2 = new Button("-");
b2.setBounds(120,200,50,50);
b3 = new Button("*");
b3.setBounds(220, 200, 50, 50);
b4 = new Button("/");
b4.setBounds(320,200,50,50);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);

add(tf1);
add(tf2);
add(tf3);
add(b1);
add(b2);
add(b3);
add(b4);
Page No: 23 | 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

setSize(400,400);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String s1 = tf1.getText();
String s2 = tf2.getText();
int a = Integer.parseInt(s1);
int b = Integer.parseInt(s2);
int c = 0;
if (e.getSource() == b1){
c = a + b;
}
else if (e.getSource() == b2){
c = a - b;
else if (e.getSource() == b3){
c = a * b;
else if (e.getSource() == b4){
c = a / b;
}
String result = String.valueOf(c);
tf3.setText(result);
}
public static void main(String[] args) {
new sample();
}
}

Page No: 24 | 24

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy