Model Question Paper-Solutions
Model Question Paper-Solutions
Scheme) - BCS306A
Keywords - There are 61 keywords currently defined in the Java language. These
keywords, combined with the syntax of the operators and separators, form the
foundation of the Java language.
1b Define Array. Write a Java program to implement the addition of two matrixes.
(7M)
Arrays in Java
An array is a collection of similar type of elements which has contiguous memory
location. Java array is an object which contains elements of a similar data type.
Additionally, the elements of an array are stored in a contiguous memory location.
It is a data structure where we store similar elements
• <<, Left shift operator: shifts the bits of the number to the left and fills 0 on
voids left as a result. Similar effect as multiplying the number with some
power of two.
• >>, Signed Right shift operator: shifts the bits of the number to the right
and fills 0 on voids left as a result. The leftmost bit depends on the sign of
the initial number. Similar effect to dividing the number with some power
of two.
• >>>, Unsigned Right shift operator: shifts the bits of the number to the
right and fills 0 on voids left as a result. The leftmost bit is set to 0.
Example program snippet:
int d = 0b1010;
int e = 0b1100;
System.out.println("d << 2: " + (d << 2));
System.out.println("e >> 1: " + (e >> 1));
System.out.println("e >>> 1: " + (e >>> 1));
Output:
d << 2: 40
e >> 1: 6
e >>> 1: 6
2b Write a Java program to sort the elements using a for loop. (7M)
public class Sorting {
public static void main(String[] args) {
int[] array = {2, 3, 8, -4, -3}; // Example array to be sorted
// Bubble Sort Algorithm
for (int i = 0; i < array.length - 1; i++) {
for (int j = 0; j < array.length - 1 - i; j++) {
if (array[j] > array[j + 1]) {
// Swap array[j] and array[j + 1]
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
// Print the sorted array
System.out.println("Sorted array:");
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + " ");
}
}
}
2c Explain different types of if statements in JAVA (6M)
1. If Statement in Java
Java if statement is the simplest decision making statement. It encompasses a boolean
condition followed by a scope of code which is executed only when the condition
evaluates to true. However if there are no curly braces to limit the scope of sentences
to be executed if the condition evaluates to true, then only the first line is executed.
Syntax:
if(condition)
{
//code to be executed
}
Default constructors are provided by compiler only when programmer has not
declared any other constructor. It will be a zero argument empty body constructor.
Programmers can declare their own version of no-argument constructors and fill some
initialization code. Parameterized constructors have constructors with parameters.
Invoking constructors:
Box b1=new Box(7.1,4,2);
3b Define recursion. Write a recursive program to find nth Fibonacci number (7M)
Recursion is the technique of making a function call itself. This technique provides a
way to break complicated problems down into simple problems which are easier to
solve. Just as loops can run into the problem of infinite looping, recursive functions
can run into the problem of infinite recursion. Infinite recursion is when the function
never stops calling itself. Every recursive function should have a halting condition,
which is the condition where the function stops calling itself.
}
class Access
{
public static void main(String[] any)
{
A a=new A();
a.x=10;
a.y=5;
System.out.println(a.x);
}
}
In this example, x is accessible and y cannot be accessed.
4a Explain call by value and call by reference with an example program (7M)
There are two methods to pass the data into the method, i.e., call by value and call by
reference.
In call by value method, the value of the actual parameters is copied into the
formal parameters.
In call by value method, we can not modify the value of the actual parameter
by the formal parameter.
In call by value, different memory is allocated for actual and formal
parameters since the value of the actual parameter is copied into the formal
parameter.
The actual parameter is the argument which is used in the method call whereas
formal parameter is the argument which is used in the function definition.
Eg program
class Swap
{
static void swap(int a,int b)
{
int temp= a;
a=b;
b=temp;
}
public static void main(String any[])
{
int a=5,b=6;
System.out.println("Before:"+a+","+b);
swap(a,b);
System.out.println("After:"+a+","+b);
}
}
Memory allocation
Call by reference
In call by reference, the address of the variable is passed into the method as
the actual parameter.
The value of the actual parameters can be modified by changing the formal
parameters since the address of the actual parameters is passed.
Objects are passed by reference and can be used to wrap variables and provide
call by reference in Java.
Eg program
class Swap
{
static void swap(Obj o1)
{
int temp=o1.a;
o1.a=o1.b;
o1.b=temp;
}
public static void main(String any[])
{
Obj o1=new Obj();
o1.a=5;
o1.b=6;
System.out.println("Before:"+o1.a+","+o1.b);
swap(o1);
System.out.println("After:"+o1.a+","+o1.b);
}
}
4b Write a program to perform Stack operations using proper class and Methods. (7M)
class Stack
{
int max;
int top;
int data[];
Stack(int max)
{
this.max=max;
top=-1;
data=new int[max];
}
void push(int ele)
{
if(top==max-1)
{
System.out.println("Stack Overflow");
return;
}
data[++top]=ele;
}
void pop()
{
if(top==-1)
{
System.out.println("Stack Overflow");
return;
}
System.out.println("Popped Element="+data[top--]);
}
void display()
{
for(int i=top;i>=0;i--)
{
System.out.println(data[i]);
}
}
}
}
class WeightBox extends Box
{
double weight;
int x=3;
WeightBox(double width,double height,double depth,double weight)
{
super(width,height,depth);
this.weight=weight;
}
void disp()
{
System.out.println("WeightBox...");
super.disp();
}
}
class ColorBox extends Box
{
int color;
ColorBox(double width,double height,double depth,int color)
{
super(width,height,depth);
this.color=color;
}
}
class Shipment extends WeightBox
{
int cost;
Shipment(double width,double height,double depth,double weight,int
cost)
{
super(width,height,depth,weight);
this.cost=cost;
}
}
class Inheritance2
{
public static void main(String[] any)
{
WeightBox w1=new WeightBox(1.2,3.4,1.1,20.0);
w1.disp();
ColorBox c1=new ColorBox(1.2,3.4,1.1,2000);
}
}
Example code:
// First interface
interface Animal {
void eat();
void sleep();
}
// Second interface
interface Pet {
void play();
void beFriendly();
}
class Override
{
public static void main(String any[])
{
B b=new B();
b.disp(5);
}
}
class AB
{
public static void main(String[] any)
{
B b=new B();
}
}
}
class TestSuper1{
public static void main(String args[]){
Dog d=new Dog();
d.printColor();
}}
6c What is abstract class and abstract method? Explain with an example (6M)
A method which is declared as abstract and does not have implementation is known
as an abstract method.
Eg: abstract void printStatus();//no method body and abstract
A class which is declared as abstract is known as an abstract class. It can have abstract
and non-abstract methods. It needs to be extended and its method implemented. It
cannot be instantiated. An abstract class must be declared with an abstract keyword.
o It can have abstract and non-abstract methods.
o It cannot be instantiated.
o It can have constructors and static methods also.
o It can have final methods which will force the subclass not to change the body
of the method.
Eg: abstract class A{}
Example code for Abstract classes and methods
abstract class A
{
abstract void disp1();
void disp2()
{
System.out.println("D2");
}
void disp3()
{
System.out.println("D3");
}
}
class B extends A
{
void disp1()
{
System.out.println("D1");
}
class Abs
{
public static void main(String[] any)
{
B b=new B();
b.disp2();
}
}
7a Define package. Explain the steps involved in creating a user-defined package with
an example. (7M)
A java package is a group of similar types of classes, interfaces and sub-packages.
Package in java can be categorized in two form, built-in package and user-defined
package. There are many built-in packages such as java, lang, awt, javax, swing, net,
io, util, sql etc.
Subpackages: Packages that are inside another package are the subpackages. These
are not imported by default, they have to imported explicitly. Also, members of a
subpackage have no access privileges, i.e., they are considered as different package
for protected and default access specifiers.
Example :
import java.util.*;
util is a subpackage created inside java package.
Keyword Description
try The "try" keyword is used to specify a block where we should place
an exception code. It means we can't use try block alone. The try
block must be followed by either catch or finally.
finally The "finally" block is used to execute the necessary code of the
program. It is executed whether an exception is handled or not.
Subpackages: Packages that are inside another package are the subpackages. These
are not imported by default, they have to imported explicitly. Also, members of a
subpackage have no access privileges, i.e., they are considered as different package
for protected and default access specifiers.
Example :
import java.util.*;
util is a subpackage created inside java package.
8b How do you create your own exception class? Explain with a program. (7M)
User-defined exceptions in Java allow developers to create custom exception classes
that are specific to their application's needs. These custom exceptions can be used to
provide more meaningful error messages and handle specific error conditions more
gracefully.
class DivideByZero extends Exception
{
String message;
DivideByZero(String message)
{
this.message=message;
}
public String toString()
{
return "USer attempted "+message;
}
}
class DZ
{
static int compute(int a,int b) throws DivideByZero
{
if(b==0)
throw new DivideByZero("Divide By Zero...");
return a/b;
}
public static void main(String args[])
{
int a=Integer.parseInt(args[0]);
int b=Integer.parseInt(args[1]);
try{
System.out.println(compute(a,b));
}
catch(DivideByZero z)
{
System.out.println(z);
}
finally{
System.out.println("I am always der...");
}
}
}
9a What do you mean by a thread? Explain the different ways of creating threads (7M)
Multithreading in Java is a process of executing multiple threads simultaneously. A
thread is a lightweight sub-process, the smallest unit of processing. Multiprocessing
and multithreading, both are used to achieve multitasking. However, we use
multithreading than multiprocessing because threads use a shared memory area.
They don't allocate separate memory area so saves memory, and context-switching
between the threads takes less time than process. Java Multithreading is mostly used
in games, animation, etc.
Two ways to implement Thread in Java is to use (i) Inheritance channel where
extends Thread class is used and (ii) Interface channel where implements Runnable
interface is used.
}
}
class SynT
{
public static void main(String any[]) throws InterruptedException
{
Callme c=new Callme();
9c Discuss values() and value Of() methods in Enumerations with suitable examples
(6M)
values() Method
The values() method returns an array containing all the constants of the enum in the
order they were declared. This method is implicitly declared by the compiler for all
enums.
10a What is multithreading? Write a program to create multiple threads in JAVA (7M)
Multithreading in Java is a process of executing multiple threads simultaneously. A
thread is a lightweight sub-process, the smallest unit of processing. Multiprocessing
and multithreading, both are used to achieve multitasking. However, we use
multithreading than multiprocessing because threads use a shared memory area.
They don't allocate separate memory area so saves memory, and context-switching
between the threads takes less time than process. Java Multithreading is mostly used
in games, animation, etc.
class NT1 implements Runnable
{
Thread t;
String tname;
NT1(String tname)
{
this.tname=tname;
t=new Thread(this,"my thread");
}
public void run()
{
for(int i=0;i<5;i++)
{
System.out.println(tname+":"+i);
try{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
}
class MThread
{
public static void main(String any[]) throws InterruptedException
{
NT1 n1=new NT1("Thread1");
NT1 n2=new NT1("Thread2");
NT1 n3=new NT1("Thread3");
n1.t.start();
n2.t.start();
n3.t.start();
n1.t.join();
n2.t.join();
n3.t.join();
System.out.println(n1.t.isAlive());
System.out.println(n2.t.isAlive());
System.out.println(n3.t.isAlive());
}
}
class Item
{
int data;
boolean lock=false;
synchronized void put(int data)
{
while(lock){
try{ wait();}
catch(InterruptedException e){ };
}
lock=true;
notify();
this.data=data;
}
synchronized void get()
{
while(!lock)
{
try{ wait();}
catch(InterruptedException e){ };
}
lock=false;
notify();
System.out.println(data);
}
}
class Producer implements Runnable
{
Item i;
Thread t;
Producer(Item i)
{
this.i=i;
t=new Thread(this,"Producer");
}
public void run()
{
int j=0;
while(true)
{
i.put(j);
j++;
}
}
}
class Consumer implements Runnable
{
Item i;
Thread t;
Consumer(Item i)
{
this.i=i;
t=new Thread(this,"Consumer");
}
public void run()
{
while(true)
{
i.get();
}
}
}
class PCS
{
public static void main(String any[]) throws InterruptedException
{
Item i=new Item();
Producer p=new Producer(i);
Consumer c= new Consumer(i);
p.t.start();
c.t.start();
p.t.join();
c.t.join();
}
}
1a Discuss the different data types supported by Java along with default values
and literals (8M)
In Java language, primitive data types are the building blocks of data manipulation.
These are the most basic data types available in Java language. ava provides a rich
set of data types that can be broadly categorized into primitive and reference types.
Primitive data types, such as byte, short, int, long, float, double, char, and boolean,
are the basic building blocks for data representation. They store simple values like
integers, floating-point numbers, characters, and boolean values. For instance, int
stores integers, double stores decimal values, boolean stores true or false, and char
stores a single character. These types are highly efficient and directly mapped to
memory. On the other hand, reference data types represent more complex data
structures and include objects, arrays, and user-defined classes or interfaces. For
example, a String is a reference type that holds sequences of characters, while arrays
allow storing multiple elements of the same type. While primitive types are faster and
use less memory, reference types provide flexibility and are used to model real-world
objects in a program.
byte 0 1 byte
short 0 2 byte
int 0 4 byte
long 0L 8 byte
2a List the various operators supported by Java. Illustrate the working of >> and
>>> with an example (8M)
Java provides many types of operators which can be used according to the need.
They are classified based on the functionality they provide. In this article, we will learn
about Java Operators and learn all their types. Operators in Java are the symbols
used for performing specific operations in Java. Operators make tasks like addition,
multiplication, etc which look easy although the implementation of these tasks is quite
complex.
Types of Operators in Java
There are multiple types of operators in Java all are mentioned below:
1. Arithmetic Operators
2. Unary Operators
3. Assignment Operator
4. Relational Operators
5. Logical Operators
6. Ternary Operator
7. Bitwise Operators
8. Shift Operators
9. instance of operator
>>, Signed Right shift operator: shifts the bits of the number to the right and fills 0 on
voids left as a result. The leftmost bit depends on the sign of the initial number. Similar
effect to dividing the number with some power of two.
>>>, Unsigned Right shift operator: shifts the bits of the number to the right and fills 0
on voids left as a result. The leftmost bit is set to 0.
class BithShift
{
public static void main(String[] any)
{
int i=-1;
int res1=i>>24;
int res2=i>>>24;
System.out.println(res1);
System.out.println(res2);
}
}
2b Develop a Java program to add two matrices using command line arguments
(10M)
import java.util.*;
class Matrix
{
public static void readMatrix(int[][] A,int N)
{
Scanner kb=new Scanner(System.in);
for(int i=0;i<=N-1;i++)
{
for(int j=0;j<=N-1;j++)
{
A[i][j]=kb.nextInt();
}
}
}
public static void addMatrix(int[][] A, int[][] B, int[][] C,int N)
{
for(int i=0;i<=N-1;i++)
{
for(int j=0;j<=N-1;j++)
{
C[i][j]=A[i][j]+B[i][j];
}
}
}
public static void printMatrix(int[][] A,int N)
{
for(int i=0;i<=N-1;i++)
{
for(int j=0;j<=N-1;j++)
{
System.out.print(A[i][j]+" ");
}
System.out.println();
}
}
Java uses a generational garbage collection strategy, which divides the heap memory
into several generations based on the lifespan of objects.
1. Young Generation
• Purpose: This area stores new objects that are likely to have a short lifespan.
• Subdivisions:
o Eden Space: Most objects are initially allocated in this space. When
objects are created, they are placed in the Eden space.
o Survivor Spaces (S0 and S1): After the first garbage collection event
(minor GC), objects that survive are moved to one of the survivor
spaces. These spaces help in further promoting objects that live longer.
• Collection: Garbage collection in the young generation is frequent and is
known as Minor GC. It is relatively fast because the young generation usually
contains a small number of objects, most of which are short-lived.
3b Develop a Java program to find area of rectangle, area of circle and area of
triangle using method overloading concept. Call these methods from main
method with suitable inputs (10M)
public class AreaCalculator {
4a Outline the following keywords with example (i) this and (ii) static (6M)
The this keyword refers to the current object in a method or constructor. The most
common use of the this keyword is to eliminate the confusion between class attributes
and parameters with the same name (because a class attribute is shadowed by a
method or constructor parameter). This scenario is called “Instance variable hiding”.
this can also be used to:
• Invoke current class constructor
• Invoke current class method
• Return the current class object
• Pass an argument in the method call
• Pass an argument in the constructor call
The static keyword in Java is used for memory management mainly. We can apply
static keyword with variables, methods, blocks and nested classes. The static
keyword belongs to the class than an instance of the class.
The static can be:
1. Variable (also known as a class variable)
2. Method (also known as a class method)
3. Block
4. Nested class
Static variables:
o The static variable can be used to refer to the common property of all objects
(which is not unique for each object), for example, the company name of
employees, college name of students, etc.
o The static variable gets memory only once in the class area at the time of class
loading.
o static variables are like global variables in Java
Static methods
If you apply static keyword with any method, it is known as static method.
o A static method belongs to the class rather than the object of a class.
o A static method can be invoked without the need for creating an instance of a
class.
o A static method can access static data member and can change the value of
it.
Static block
o Is used to initialize the static data member.
o It is executed before the main method at the time of classloading.
Static class
We can declare a class static by using the static keyword. A class can be declared
static only if it is a nested class. It does not require any reference of the outer class.
The property of the static class is that it does not allows us to access the non-static
members of the outer class.
}
}
class Employee {
// Instance variables
String name;
String designation;
int empId;
double basicSalary;
Default constructors are provided by compiler only when programmer has not
declared any other constructor. It will be a zero argument empty body constructor.
Programmers can declare their own version of no-argument constructors and fill some
initialization code. Parameterized constructors have constructors with parameters.
Invoking constructors:
Box b1=new Box(7.1,4,2);
5a Illustrate the use of super keyword in Java with suitable example. Also explain
dynamic method dispatch (10M)
The super keyword in Java is a reference variable which is used to refer immediate
parent class object. Whenever you create the instance of subclass, an instance of
parent class is created implicitly which is referred by super reference variable.
Usage of Java super Keyword
1. super can be used to refer immediate parent class instance variable.
2. super can be used to invoke immediate parent class method.
3. super() can be used to invoke immediate parent class constructor.
Eg:
class Animal{
String color="white";
Animal(){System.out.println("animal is created");}
void eat(){System.out.println("eating...");}
}
class Dog extends Animal{
String color="black";
Dog()
{
super(); //Superclass constructor invoked
}
void printColor(){
System.out.println(color);//prints color of Dog class
System.out.println(super.color);//superclass variable
}
void eat(){System.out.println("eating bread...");}
void bark(){System.out.println("barking...");}
void work(){
super.eat(); //call superclass methods
bark();
}
}
class TestSuper1{
public static void main(String args[]){
Dog d=new Dog();
d.printColor();
}}
6a Compare and contrast method overloading and method overriding with suitable
example (8M)
The differences between Method Overloading and Method Overriding in Java are
as follows:
Program example to demonstrate both:
// Superclass
class Animal {
// Overriding method (method in superclass)
public void sound() {
System.out.println("Animal makes a sound");
}
// Subclass
class Dog extends Animal {
// Overriding method (method in subclass)
public void sound() {
System.out.println("Dog barks");
}
}
class Triangle extends Shape
{
int x1,y1,x2,y2,x3,y3;
Triangle(int x1,int y1, int x2,int y2,int x3,int y3)
{
this.x1=x1;
this.y1=y1;
this.x2=x2;
this.y2=y2;
this.x3=x3;
this.y3=y3;
}
void draw()
{
System.out.println("Triangle drawn");
}
void erase()
{
x1=x2=x3=y1=y2=y3=0;
System.out.println("Triangle erased");
}
}
class Circle extends Shape
{
int x,y;
double radius;
Circle(int x,int y, double radius)
{
this.x=x;
this.y=y;
this.radius=radius;
}
void draw()
{
System.out.println("Circle drawn");
}
void erase()
{
radius=0;
System.out.println("Circle erased");
}
}
class Square extends Shape
{
int x,y;
int side;
Square(int x,int y, int side)
{
this.x=x;
this.y=y;
this.side=side;
}
void draw()
{
System.out.println("Square drawn");
}
void erase()
{
side=0;
System.out.println("Square erased");
}
7a Explain various levels of access protections available for packages and their
implications with suitable examples. (10M)
Member access and packages in Java
public keyword
If a class member is “public” then it can be accessed from anywhere. The member
variable or method is accessed globally. This is the simplest way to provide access to
class members. However, we should take care of using this keyword with class
variables otherwise anybody can change the values. Usually, class variables are kept
as private and getter-setter methods are provided to work with them.
private keyword
If a class member is “private” then it will be accessible only inside the same class. This
is the most restricted access and the class member will not be visible to the outer
world. Usually, we keep class variables as private and methods that are intended to
be used only inside the class as private.
protected keyword
If class member is “protected” then it will be accessible only to the classes in the same
package and to the subclasses. This modifier is less restricted from private but more
restricted from public access. Usually, we use this keyword to make sure the class
variables are accessible only to the subclasses.
default access
If a class member doesn’t have any access modifier specified, then it’s treated with
default access. The access rules are similar to classes and the class member with
default access will be accessible to the classes in the same package only. This access
is more restricted than public and protected but less restricted than private.
Example code:
package mypackage;
// private member
private int empId;
// protected member
protected double salary;
// File: TestEmployee.java
package mypackage;
// Deposit method
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
System.out.println("Deposited: " + amount);
} else {
System.out.println("Invalid deposit amount.");
}
}
// Withdrawal method with exception handling
public void withdraw(double amount) throws InsufficientBalanceException {
if (amount > 0) {
if (balance - amount < MIN_BALANCE) {
throw new BankingException("Withdrawal denied. Insufficient balance to
maintain minimum required balance of " + MIN_BALANCE);
} else {
balance -= amount;
System.out.println("Withdrawn: " + amount);
}
} else {
System.out.println("Invalid withdrawal amount.");
}
}
// Deposit money
account.deposit(2000.0);
account.checkBalance();
Keyword Description
try The "try" keyword is used to specify a block where we should place
an exception code. It means we can't use try block alone. The try
block must be followed by either catch or finally.
finally The "finally" block is used to execute the necessary code of the
program. It is executed whether an exception is handled or not.
catch(ArithmeticException e)
{
System.out.println("specific");
e.printStackTrace();
}
catch(ArrayIndexOutOfBoundsException e)
{
e.printStackTrace();
}
catch(Exception e)
{
System.out.println("generic");
e.printStackTrace(); //Display exception details
}
System.out.println("I continue");
}
}
8b Create a package called balance containing class AccountBalance with method
displayBalance(). Import this class in another package to access method of
Account class. (10M)
package balance;
public class AccountBalance
{
double bal;
String name;
String accno;
public AccountBalance(String accno, String name,double bal)
{
this.accno=accno;
this.bal=bal;
this.name=name;
}
public void displayBalance()
{
System.out.println(“Account Number=”+accno+"Account
Name="+name+", Balance="+bal);
}
}
Two ways to implement Thread in Java is to use (i) Inheritance channel where
extends Thread class is used and (ii) Interface channel where implements Runnable
interface is used.
}
}
class SynT
{
public static void main(String any[]) throws InterruptedException
{
Callme c=new Callme();
9c Develop a Java program for automatic conversion of wrapper class type into
corresponding primitive type that demonstrates unboxing (8M)
The automatic conversion of primitive data types into its equivalent Wrapper type is
known as boxing and opposite operation is known as unboxing. This is the new feature
of Java5. So java programmer doesn't need to write the conversion code
class ABU
{
static int m(Integer i)
{
return i;
}
public static void main(String any[])
{
Integer iob;
int i=10;
iob=i; //Autoboxing
Integer iob1=m(30); //1. Autboxing, 2.Autounboxing and 3. Autoboxing
System.out.println(i+iob);
System.out.println(iob1);
}
}
10a Summarize the type wrappers supported in Java (6M)
Wrapper classes in Java
The wrapper class in Java provides the mechanism to convert primitive into
object and object into primitive.
Since J2SE 5.0, autoboxing and unboxing feature convert primitives into
objects and objects into primitives automatically. The automatic conversion of
primitive into an object is known as autoboxing and vice-versa unboxing.
Use of Wrapper classes in Java
Java is an object-oriented programming language, so we need to deal with
objects many times like in Collections, Serialization, Synchronization, etc. Let
us see the different scenarios, where we need to use the wrapper classes.
Change the value in Method: Java supports only call by value. So, if we pass
a primitive value, it will not change the original value. But, if we convert the
primitive value in an object, it will change the original value.
Serialization: We need to convert the objects into streams to perform the
serialization. If we have a primitive value, we can convert it in objects through
the wrapper classes.
Synchronization: Java synchronization works with objects in Multithreading.
java.util package: The java.util package provides the utility classes to deal with
objects.
Collection Framework: Java collection framework works with objects only. All
classes of the collection framework (ArrayList, LinkedList, Vector, HashSet,
LinkedHashSet, TreeSet, PriorityQueue, ArrayDeque, etc.) deal with objects
only.
boolean Boolean
char Character
byte Byte
short Short
int Integer
long Long
float Float
double Double
10c Develop a program to create a class MyThread in this class a constructor, call
the base class constructor, using super and start the thread. The run method of
the class starts after this. It can be observed that both main thread and created
child thread are executed concurrently (8M)
public class Thread2 extends Thread
{
String name;
Thread2(String name)
{
super(name);
}
public void run()
{
System.out.println(getName()+" started");
try{Thread.sleep(500);}
catch(InterruptedException e){ };
System.out.println(getName()+" ended");
}
public static void main(String args[]) throws InterruptedException{
Thread2 t1=new Thread2("first");
t1.start();
System.out.println("Main started..");
t1.join();
System.out.println("Main ended..");
}
}