22412
22412
22412
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Winter – 19 EXAMINATION
Types of constructors:
1. Default constructor
2. Parameterized constructor
3. Copy constructor
b Define Class and Object. 2M
1|24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Ans Class: A class is a user defined data type which groups data Definition 1
members and its associated functions together. Mark each
2. Runtime errors
e List any four Java API packages. 2M
Ans 1.java.lang 1/2 Marks for
2.java.util one Package
3.java.io
4.java.awt
5.java.net
6.ava.applet
2|24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
1)One-Dimensional
2)Two-Dimensional
g List access specifiers in Java. 2M
Ans 1)public Any 2, 1M for
each
2)private
3)friendly
4)protected
5)Private Protected
3|24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
float pi,radius;
abc(float p, float r)
pi=p;
radius=r;
void area()
float ar=pi*radius*radius;
System.out.println("Area="+ar);
void display()
System.out.println("Pi="+pi);
System.out.println("Radius="+radius);
}}
class area
a.display();
4|24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
a.area();
}
c Define exception. State built-in exceptions. 4M
Ans An exception is a problem that arises during the execution of a Definition 2
program. Marks, List: 2
Marks
Java exception handling is used to handle error conditions in a
program systematically by taking the necessary action
Built-in exceptions:
5|24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
1) drawRect()
2)drawOval()
Ans 1)drawRect() : drawRect:
2Marks,
drawRect () method display an outlined rectangle. drawOval: 2
Marks
Syntax: void drawRect(int top,int left, int width,int height)
Example: g.drawRect(10,10,60,50);
Syntax: void drawOval(int top, int left, int width, int height)
2) Use the byte stream classes when working with bytes or other
binary objects.
6|24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
2. start( )
3. paint( )
4. stop( )
5. destroy( )
7|24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
start( ):The start( ) method is called after init( ).It is also called
to restart an applet after it has Been stopped. Whereas init( ) is
called once—the first time an applet is loaded—start( )is called
each time an applet’s HTML document is displayed onscreen.
8|24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
7)syntax 7)syntax
Class classname Inteface Innterfacename
{ {
Variable declaration, Final Variable declaration,
Method declaration abstract Method declaration
} }
d Define type casting. Explain its types with syntax and example. 4M
Ans 1. The process of converting one data type to another is called 1M for
casting or type casting. definition,3M for
types explanation
2. If the two types are compatible, then java will perform the
conversion automatically.
3. It is possible to assign an int value to long variable.
4. However, if the two types of variables are not compatible, the
type conversions are not implicitly allowed, hence the need for
type casting.
1.Implicit type-casting:
2.Explicit type-casting:
1. Implicit type-casting:
Example:
int i = 3;
double f;
f = i;
9|24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
output:
f = 3.0
Widening Conversion:
2. Explicit type-casting:
Syntax:
newValue = (typecast)value;
Example:
double f = 3.5;
int i;
i = (int)f; // it cast double value 3.5 to int 3.
Narrowing Casting: Explicit type cast is requires to Narrowing
conversion to inform the compiler that you are aware of the
possible loss of precision.
10 | 2 4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Ans 2M for
diagram,2M for
explanation
Thread Life Cycle Thread has five different states throughout its
life.
1. Newborn State
2. Runnable State
3. Running State
4. Blocked State
5. Dead State
11 | 2 4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
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.
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.
1) suspend() : Thread can be suspended by this method. It
can be rescheduled by resume().
2) 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().
3) sleep(): We can put a thread to sleep for a specified time
period using sleep(time) where time is in ms. It re-enters
the runnable state as soon as period has elapsed /over
Dead State: Whenever we want to stop a thread form running
further we can call its stop().The statement 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.
b Describe final variable and final method. 4M
Ans Final method: making a method final ensures that the 2M for
functionality defined in this method will never be altered in any definition,2M for
way, ie a final method cannot be overridden. example
Syntax:
{
//implementation
}
Example of declaring a final method:
class A
{
12 | 2 4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Operator Meaning
&& Logical
AND
|| Logical
OR
! Logical
NOT
Program demonstrating logical Operators
13 | 2 4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
boolean a = true;
boolean b = false;
Output:
a && b = false
a || b = true
Array Vector
1) An array is a structure that 1)The Vector is similar to
holds multiple values of the array holds multiple objects
same type. and like an array; it contains
components that can be
accessed using an integer
index.
14 | 2 4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Syntax: s1.toLowerCase()
System.out.println(s.toLowerCase());
Output: sachin
15 | 2 4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
Syntax: s1.toUpperCase()
Example:
String s="Sachin";
System.out.println(s.toUpperCase());
Output: SACHIN
3) trim (): Returns a copy of the string, with leading and trailing
whitespace omitted.
Syntax: s1.trim()
Example:
System.out.println(s.trim());
Output:Sachin
Syntax: s1.replace(‘x’,’y’)
Example:
System.out.println(s2);
16 | 2 4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
17 | 2 4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
18 | 2 4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
19 | 2 4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
}
}
catch(InterruptedException e)
{System.out.println("odd thread interrupted");
}
}
}
class EvenOdd
{
public static void main(String args[])
{
new Even().start();
new Odd().start();
}
}
20 | 2 4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
21 | 2 4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
22 | 2 4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
}
c Implement the following inheritance 6M
23 | 2 4
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
TA=t;
DA=d; (Any other logic
} considered)
public void Basic_Sal()
{
System.out.println("Basic Salary
:"+Basic_Salary);
}
void Total_Sal()
{
Display();
Basic_Sal();
double Total_Sal=Basic_Salary + TA + DA +
HRA;
System.out.println("Total Salary :"+Total_Sal);
}
}
class EmpDetails
{ public static void main(String args[])
{ Gross_Salary s=new
Gross_Salary("Sachin",20,1000,2000,7000);
s.Total_Sal();
}
}
24 | 2 4