Advanced JAVALabManual

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

AdvancedJAVA[BIS402] 1

JNN COLLEGE OF ENGINEERING, SHIVAMOGGA


DEPARTMENTOFINFORMATIONSCIENCE&ENGINEERING

AdvancedJAVA – BIS402

IS&EDept,JNNCE,Shivamogga.
AdvancedJAVA[BIS402] 2

SubjectCode:BIS402 CIEMarks:50
NumberofContactHours/Week:3:0:2:0 SEEMarks:50
Total Number of Lecture Hours: 40 – 08 – 10 Lab Slots ExamHours:03
CREDITS – 04

1. Implement a java program to demonstrate creating an ArrayList, adding elements,


removing elements, sorting elements of ArrayList. Also illustrate the use of toArray()
method.

2. Develop a program to read random numbers between a given range that are multiples of
2 and 5, sort the numbers according to tens place using comparator.

3. Implement a java program to illustrate storing used defined classes in collection.

4. Implement a java program to illustrate the use of different types of string class constructors.

5. Implement a java program to illustrate the use of different types of character extraction,
stringcomparison, string search and string modification methods.

6. Implement a java program to illustrate the use of different types of StringBuffer methods.

7.Demonstrate a swing event handling application that creates 2 buttons Alpha and Beta and
displays thetext “Alpha pressed” when alpha button is clicked and “Beta pressed” when beta
button is clicked.

8.A program to display greeting message on the browser “Hello UserName”, “How Are You?”,
acceptusername from the client using servlet.

9. A servlet program to display the name, USN, and total marks by accepting student detail.

10. A Java program to create and read the cookie for the given cookie name as “EMPID” and its
value as“AN2356”.

11. Write a JAVA Program to insert data into Student DATA BASE and retrieve info based on
queries(For example update, delete, search etc…).

12. A program to design the Login page and validating the USER_ID and PASSWORD using
JSP andDataBase.

IS&EDept,JNNCE,Shivamogga.
AdvancedJAVA[BIS402] 3

/*1.Implement a java program to demonstrate creating an ArrayList, adding


elements, removing elements,sorting elements of ArrayList. Also illustrate
the use of toArray() method.*/

packageJava4thSem;

importjava.util.ArrayList;
importjava.util.Collections;

publicclassArrayListExample {
publicstaticvoidmain(String[] args) {
// Creating ArrayList
ArrayList<String>arrayList = newArrayList<>();

// Adding elements
arrayList.add("Apple");
arrayList.add("Banana");
arrayList.add("Orange");
arrayList.add("Mango");

System.out.println("ArrayList after adding elements: " +


arrayList);

// Removing element
arrayList.remove("Orange");
System.out.println("ArrayList after removing element: " +
arrayList);

// Sorting elements
Collections.sort(arrayList);
System.out.println("ArrayList after sorting: " + arrayList);

// Using toArray() method


String[] array = new String[arrayList.size()];
array = arrayList.toArray(array);

System.out.println("Array obtained from ArrayList using


toArray(): ");
for (Stringitem :array) {
System.out.println(item);
}
}
}

IS&EDept,JNNCE,Shivamogga.
AdvancedJAVA[BIS402] 4

Output:

ArrayList after adding elements: [Apple, Banana, Orange, Mango]

ArrayList after removing element: [Apple, Banana, Mango]

ArrayList after sorting: [Apple, Banana, Mango]

Array obtained from ArrayList using toArray():


Apple
Banana
Mango

IS&EDept,JNNCE,Shivamogga.
AdvancedJAVA[BIS402] 5

/*2.Develop a program to read random numbers between a given range that are
multiples of 2 and 5, sortthe numbers according to tens place using
comparator.*/

packageJava4thSem;

importjava.util.*;

classTensPlaceComparatorimplements Comparator<Integer> {
publicintcompare(Integer num1, Integer num2) {
inttensPlace1 = (num1 % 100) / 10;
inttensPlace2 = (num2 % 100) / 10;
returntensPlace1 - tensPlace2;
}
}

publicclassRandomNumbersSort {
publicstaticvoidmain(String[] args) {
try (Scanner scan = newScanner(System.in)) {
System.out.print("Enter the lower bound of the
range: ");
intlowerBound = scan.nextInt();

System.out.print("Enter the upper bound of the


range: ");
intupperBound = scan.nextInt();

// Generate random numbers within the given range


Random random = newRandom();
ArrayList<Integer>numbers = newArrayList<>();
for (inti = 0; i< 10; i++) {
intrandomNumber = lowerBound +
random.nextInt(upperBound - lowerBound + 1);
System.out.println(randomNumber);
numbers.add(randomNumber);
}

// Filter multiples of 2 and 5


numbers.removeIf(num ->num % 2 != 0 || num % 5 != 0);

System.out.println("Random numbers (multiples of 2 and


5) within the given range: " + numbers);

// Sort according to tens place using comparator


Collections.sort(numbers, newTensPlaceComparator());

System.out.println("Sorted numbers according to tens


place: " + numbers);
} } }
IS&EDept,JNNCE,Shivamogga.
AdvancedJAVA[BIS402] 6

Output:

Run 1: Enter the lower bound of the range: 10


Enter the upper bound of the range: 20
11101813151812131716
Random numbers (multiples of 2 and 5) within the given range: [10]
Sorted numbers according to tens place: [10]

Run 2: Enter the lower bound of the range: 20


Enter the upper bound of the range: 60
20212323425458232432
Random numbers (multiples of 2 and 5) within the given range: [20]
Sorted numbers according to tens place: [20]

IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 10

/* 3. Implement a java program to illustrate storing user defined classes


in collection.*/

packageJava4thSem;

importjava.util.ArrayList;
importjava.util.List;

class Person {
private String name;
privateintage;

publicPerson(String name, intage) {


this.name = name;
this.age = age;
}

public String getName() {


returnname;
}

publicintgetAge() {
returnage;
}

@Override
public String toString() {
return"Person{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}

publicclassPersonCollection {
publicstaticvoidmain(String[] args) {
// Create instances of Person class
Person person1 = newPerson("Alice", 30);
Person person2 = newPerson("Bob", 25);
Person person3 = newPerson("Charlie", 35);

// Create an ArrayList to store Person objects


List<Person>personList = newArrayList<>();

// Add Person objects to the ArrayList


personList.add(person1);
personList.add(person2);
personList.add(person3);
IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 10

// Print out the contents of the ArrayList


System.out.println("Contents of the ArrayList:");
for (Person person :personList) {
System.out.println(person);
}
}
}

Output:

Contents of the ArrayList:


Person{name='Alice', age=30}
Person{name='Bob', age=25}
Person{name='Charlie', age=35}

IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 1
9

/*4.Implement a java program to illustrate the use of different types of


string class constructors.*/

This program demonstrates the use of various constructors available in the String class:

1. Constructor using a string literal.


2. Constructor using a character array.
3. Constructor using a portion of a character array.
4. Copy constructor.
5. Constructor using bytes from a byte array.
6. Constructor using bytes from a portion of a byte array.

packageJava4thSem;

publicclassStringConstructorsExample {
publicstaticvoidmain(String[] args) {
// Constructor 1: Create a String using a string literal
String str1 = "Hello, World!";
System.out.println("String created using string literal:"+ str1);

// Constructor 2: Create a String using a character array


char[] charArray = {'H', 'e', 'l', 'l', 'o'};
String str2 = new String(charArray);
System.out.println("String created using character array:"+str2);

// Constructor 3: Create a String using a portion of a character


array
String str3 = newString(charArray, 0, 3); //Start from index 0,
//length 3
System.out.println("String created using portion of character
array: " + str3);

// Constructor 4: Create a String using the copy //constructor


String str4 = new String(str1);
System.out.println("String created using copy constructor: " +
str4);

// Constructor 5: Create a String using bytes from a byte //array


byte[] byteArray = {72, 101, 108, 108, 111}; // ASCII //values
for "Hello"
String str5 = new String(byteArray);
System.out.println("String created using byte array: " + str5);

IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 1
10
// Constructor 6: Create a String using bytes from a //portion of
a byte array
String str6 = newString(byteArray, 0, 3); // Start from
//index 0, length 3
System.out.println("String created using portion of byte array: "
+ str6);
}
}

Output:

String created using string literal: Hello, World!


String created using character array: Hello
String created using portion of character array: Hel
String created using copy constructor: Hello, World!
String created using byte array: Hello
String created using portion of byte array: Hel

IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 1
11

/* 5.Implement a java program to illustrate the use of different types of


character extraction, stringcomparison, string search and string
modification methods. */

Package Java4thSem;

public class StringMethodExamples {


public static void main(String[] args) {
// Character Extraction Methods
String str = "Hello, World!";
Char firstChar = str.charAt(0);
Char lastChar = str.charAt(str.length() - 1);
System.out.println("First character: " + firstChar);
System.out.println("Last character: " + lastChar);

// Substring Method
String substring = str.substring(7); // Start from index
//7 to end
System.out.println("Substring from index 7: " + substring);

// String Comparison Methods


String str1 = "hello";
String str2 = "HELLO";
System.out.println("Case-sensitive comparison: " +
str1.equals(str2));
System.out.println("Case-insensitive comparison: " +
str1.equalsIgnoreCase(str2));

// String Search Methods


Boolean containsWorld = str.contains("World");
Boolean startsWithHello = str.startsWith("Hello");
Boolean endsWithWorld = str.endsWith("World!");
System.out.println("Contains 'World': " + containsWorld);
System.out.println("Starts with 'Hello': " + startsWithHello);
System.out.println("Ends with 'World!': " + endsWithWorld);

// String Modification Methods


String replacedString = str.replace("World", "Java");
String upperCaseString = str.toUpperCase();
String lowerCaseString = str.toLowerCase();
String trimmedString = " Trimmed String ".trim();
System.out.println("Replaced 'World' with 'Java': " +
replacedString);
System.out.println("Uppercase string: " + upperCaseString);
System.out.println("Lowercase string: " + lowerCaseString);
System.out.println("Trimmed string: '" + trimmedString + "'");
}
}
IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 1
12

Output:

First character: H
Last character: !
Substring from index 7: World!
Case-sensitive Comparison: false
Case-insensitive comparison: true
Contains 'World': true
Starts with 'Hello': true
Ends with 'World!': true
Replaced 'World' with 'Java': Hello, Java!
Uppercase string: HELLO, WORLD!
Lowercase string: hello, world!
Trimmed string: 'Trimmed String'

IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 1
13

/* 6. Implement a java program to illustrate


the use of different types of StringBuffer
methods*/

This program demonstrates the usage of various methods available in the StringBuffer class:

• append(String str): Appends the specified string to the end of the buffer.
• insert(int offset, String str): Inserts the specified string into the buffer at the specified
offset.
• delete(int start, int end): Deletes characters from the buffer between the specified start
and end indices.
• deleteCharAt(int index): Deletes the character at the specified index.
• replace(int start, int end, String str): Replaces characters in the buffer between the
specified start and end indices with the specified string.
• reverse(): Reverses the characters in the buffer.
• capacity(): Returns the current capacity of the buffer.
• length(): Returns the length (character count) of the buffer.
• setLength(int newLength): Sets the length of the buffer to the specified value.
• ensureCapacity(int minimumCapacity): Ensures that the capacity of the buffer is at least
equal to the specified minimum capacity.
• trimToSize(): Reduces the capacity of the buffer to match its length.
• toString(): Converts the buffer to a string.

Package Java4thSem;

public class StringBufferMethodsExample {


public static void main(String[] args) {
// Create a StringBuffer
StringBuffer stringBuffer = new StringBuffer("Hello");

// Append method
stringBuffer.append(" World");
System.out.println("After append: " + stringBuffer);
System.out.println("hashcode of string buffer at first
stage:"+ stringBuffer.hashCode());

// Insert method
stringBuffer.insert(5, ", Java");
System.out.println("After insert: " + stringBuffer);

IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 1
14
// Delete method
stringBuffer.delete(5, 11); // Deletes ", Java"
System.out.println("After delete: " + stringBuffer);

// DeleteCharAt method
stringBuffer.deleteCharAt(0); // Deletes 'H'
System.out.println("After deleteCharAt: " + stringBuffer);

// Replace method
stringBuffer.replace(0, 5, "Hi ");
System.out.println("After replace: " + stringBuffer);

// Reverse method
stringBuffer.reverse();
System.out.println("After reverse: " + stringBuffer);

// Capacity and Length methods


System.out.println("Capacity: " + stringBuffer.capacity());
System.out.println("Length: " + stringBuffer.length());

// SetLength method
stringBuffer.setLength(5);
System.out.println("After setLength: " + stringBuffer);

// EnsureCapacity method
stringBuffer.ensureCapacity(18);
System.out.println("After ensureCapacity: " +
stringBuffer.capacity());

// TrimToSize method
stringBuffer.trimToSize();
System.out.println("After trimToSize: " +
stringBuffer.capacity());
System.out.println("hashcode of string buffer: "+
stringBuffer.hashCode() );

// toString method
String str = stringBuffer.toString();
System.out.println("String representation: " + str);
System.out.println("hashcode of string: "+ str.hashCode() );
}
}

Output:
IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 1
15

After append: Hello World


hashcode of string buffer at first stage:1365202186
After insert: Hello, Java World
After delete: Hello World
After deleteCharAt: ello World
After replace: Hi World
After reverse: dlroW iH
Capacity: 21
Length: 8
After setLength: dlroW
After ensureCapacity: 21
After trimToSize: 5
hashcode of string buffer: 1365202186
String representation: dlroW
hashcode of string: 95682610

IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 2
1

/* 7. Demonstrate a swing event handling application that creates 2 buttons


Alpha and Beta and displays thetext “Alpha pressed” when alpha button is
clicked and “Beta pressed” when beta button is clicked.*/

In this Swing application:

1. We create a JFrame to hold the components.


2. We create a JPanel to contain the buttons.
3. We create two JButton s: one for "Alpha" and one for "Beta", and add them to the panel.
4. We add action listeners to each button using anonymous inner classes. When a button is
clicked, a message dialog is shown with the corresponding message.
5. Finally, we make the frame visible.

packageJava4thSem;

importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;

publicclassButtonEventHandlingExample {
publicstaticvoidmain(String[] args) {
// Create a JFrame
JFrameframe = newJFrame("Button Event Handling Example");
frame.setSize(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Create a JPanel
JPanelpanel = newJPanel();
frame.add(panel);

// Set panel layout


panel.setLayout(newFlowLayout());

// Create Alpha button


JButtonalphaButton = newJButton("Alpha");
panel.add(alphaButton);

// Create Beta button


JButtonbetaButton = newJButton("Beta");
panel.add(betaButton);

// Add action listener to Alpha button


alphaButton.addActionListener(newActionListener() {
publicvoidactionPerformed(ActionEvente) {
JOptionPane.showMessageDialog(frame, "Alpha pressed");
}
});
IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 2
2

// Add action listener to Beta button


betaButton.addActionListener(newActionListener() {
publicvoidactionPerformed(ActionEvente) {
JOptionPane.showMessageDialog(frame, "Beta pressed");
}
});

// Set frame visibility


frame.setVisible(true);
}
}

Output:

Initial Window:

When “Alpha” Button Pressed

IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 2
3

When “Beta” Button is pressed

IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 2
4

/* 8. A program to display greeting message on the browser “Hello


UserName”, “How Are You?”, acceptusername from the client using servlet.*/

packageJava3rdSem;
//Outerclass
classOuterClass{
//Displayfunctionintheouterclass
voiddisplay(){
System.out.println("OuterClassdisplaymethod");
}

//Innerclass
classInner{
//Displayfunctionintheinnerclass
voiddisplay(){
System.out.println("Innerdisplaymethod");
}
}//InnerClassEnds..
}//OuterClassEnds..

//Mainclass
publicclassMainClass{
publicstaticvoidmain(String[] args){
//Createaninstanceoftheouterclass
OuterClassouter = new OuterClass();
//Callthedisplaymethodoftheouterclass outer.display();
// Create an instance of the inner class
OuterClass.Innerinner=outer.newInner();
//Callthedisplaymethodoftheinnerclass inner.display();
}
}

Output:

OuterClassdisplaymethod

Inner display method

IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 2
5

/*9.DevelopaJAVAprogramtoraiseacustomexception(userdefined exception) for


DivisionByZero using try, catch, throw and finally.*/

Inthisexample,the divide methodattemptsdivisionandthrowsthe DivisionByZeroException


ifthedenominatoriszero.The main methodthentriestoperformthedivisionandcatchesthecustom block
exception if it occurs. The finally is used to ensure that the code inside it is executed

regardlessofwhetheranexceptionisthrownor not.

packageJava3rdSem;

//CustomexceptionforDivisionByZero
classDivisionByZeroExceptionextendsException{
publicDivisionByZeroException(Stringmessage){
super(message);
}
}

//Mainclass
publicclassDisionByZeroExample{
//Methodthatperformsdivisionandthrowsthecustom exception
if division by zero is attempted
staticdoubledivide(intnumerator,intdenominator)
throwsDivisionByZeroException{
if(denominator==0){
thrownewDivisionByZeroException("Divisionby zero
is not allowed");
}
return(double)numerator/denominator;
}

publicstaticvoidmain(String[] args){
intnumerator =10;
intdenominator=0;

try{
//Attemptthedivisionthatmaythrowthecustom
exception
doubleresult=divide(numerator,denominator);
System.out.println("Resultofdivision:"+
result);
}catch(DivisionByZeroExceptione){
// Catch the custom exception and handle it
System.err.println("Error:"+e.getMessage());
}finally {
IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 2
6
//Codethatwillbeexecutedwhetheran
exception is thrown or not
System.out.println("Finallyblockexecuted");
}
}
}

Output:

Error: Division by zero is not allowed


Finally block executed

IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 2
7

/*10.DevelopaJAVAprogramtocreateapackagenamedmypackandimport& implement it
in a suitable class. */

1. Createthe package: Createafoldernamedmypack.Insidethisfolder,createaJavafile with


named MyPackageClass.java the following content:

packagemypack;

publicclassMyPackageClass{
public void displayMessage() {
System.out.println("HellofromMyPackageClass!");
}
}

2. Createaclassoutsidethepackage: CreateanotherJavafilenamed
outsidethe mypack package. This class will import and use MyPackageClass: MainClass.java

packageJava3rdSem;

importmypack.MyPackageClass;

publicclassMainClass_1{
publicstaticvoidmain(String[] args){
//CreateaninstanceofMyPackageClassMyPackageClassmyP
ackageObject= new
MyPackageClass();

//CallthedisplayMessagemethodfrom MyPackageClass
myPackageObject.displayMessage();
}
}

Output:

HellofromMyPackageClass!

IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 2
8

/* 11. Write a program to illustrate creation of threads using runnable


class.(startmethodstarteachofthenewlycreatedthread.Insidetherun method there
is sleep() for suspend the thread for 500 milliseconds).
*/

Inthisexample,the classimplementsthe interface,andits


methodcontainsthelogictobeexecutedbyeachthread.The some Thread.sleep(500) simulates
work being done by the thread for 500 milliseconds.

The methodinthe classcreatestwoinstancesof and


associatesthemwithtwoseparatethreads(Thread1andThread2).The start methodisthen
called on each thread to begin their execution.

Whenyourunthisprogram,you'lllikelyseeinterleavedoutputfromboththreads,asthey run
concurrentlyand independently. Keep in mind that the actual order of execution may vary
due to the nature of thread scheduling.

packageJava3rdSem;

classMyRunnableimplementsRunnable{
publicvoidrun(){
try{

System.out.println(Thread.currentThread().getName()+"is
running.");

//Sleepfor500milliseconds Thread.sleep(500);

System.out.println(Thread.currentThread().getName()+"is
done.");
}catch(InterruptedExceptione){

System.out.println(Thread.currentThread().getName()+"
was interrupted.");
}
}
}

publicclassRunnableThreadExample{
publicstaticvoidmain(String[] args){
//CreatetwoinstancesofMyRunnable

IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 2
9
MyRunnablemyRunnable1=newMyRunnable();
MyRunnablemyRunnable2 =newMyRunnable();

//Createtwothreadsandassociatethemwiththe
MyRunnable instances
Threadthread1=newThread(myRunnable1,"Thread
1");
Threadthread2=newThread(myRunnable2,"Thread
2");

//Startthethreads
thread1.start();
thread2.start();
}

Output:

Thread 1 is running.
Thread2isrunning.

Thread 1 is done.
Thread2isdone.

//CanincreasetheTimeDelay,toslowexecutionofThread.

IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 2
10

/* 12. Develop a program to create a class MyThread in this class a


constructor, call the base class constructor, using super and start the
thread.Therunmethodoftheclassstartsafterthis.Itcanbeobserved
thatbothmainthreadandcreatedchildthreadareexecutedconcurrently.
*/

Inthisexample,the MyThread classextends Thread andhasaconstructorthattakesa


threadName.Insidetheconstructor,thebaseclassconstructoriscalledusing super(threadName), and
then the thread is started using start().

Inthe run method,thereisaloopthatprintsmessagestotheconsoleandsleepsfor500


millisecondsineachiteration.

Inthe main methodofthe ThreadExample class,aninstanceof MyThread iscreated,andthemain


threadcontinuesitsexecutionconcurrentlywiththechildthread.Themessagesfromboth
threads may be interleaved due to their concurrent execution.

packageJava3rdSem;

classMyThreadextendsThread{
//ConstructorofMyThreadclass
publicMyThread(StringthreadName){
//Callthebaseclassconstructorusingsuper
super(threadName);

//Startthethread
start();
}

//Therunmethodcontainsthecodetobeexecutedby the thread


publicvoidrun(){
try{
for(inti=0; i<5; i++){

System.out.println(Thread.currentThread().getName()+"-
Count: " + i);
Thread.sleep(500);//Sleepfor500
milliseconds
}
}catch(InterruptedExceptione){

IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 2
11

System.out.println(Thread.currentThread().getName()+"
was interrupted.");
}
}
}

publicclassThreadExample{
publicstaticvoidmain(String[] args){
//CreateaninstanceofMyThread
MyThreadmyThread=newMyThread("Child Thread");

//Themainthreadcontinuesitsexecution concurrently
with the child thread
try{
for(inti=0; i<5; i++){

System.out.println(Thread.currentThread().getName()+"-
Count: " + i);
Thread.sleep(1000);//Sleepfor1000
milliseconds
}
}catch(InterruptedExceptione){

System.out.println(Thread.currentThread().getName()+"
was interrupted.");
}

//Themainthreadcompletes,butthechildthread may
still be running
}
}

Output:

main-Count:0
Child Thread - Count: 0
Child Thread - Count: 1
main - Count: 1
Child Thread - Count: 2
Child Thread - Count: 3
main - Count: 2
Child Thread - Count: 4
main - Count: 3
main-Count:4

IS&EDept,JNNCE,Shivamogga.
ObjectOrientedProgrammingwithJAVA[BCSL305] 2
12

1. Write a program to show how capacity of stringBuffer


is related to number of characters?

IS&EDept,JNNCE,Shivamogga.

You might also like