Вы находитесь на странице: 1из 35

Command Line arguments

No Topics
Hands-on Assignment Status
. Covered

Write a Program that accepts two Strings as command line


arguments and generate the output in the required format.

Example1)
If the two command line arguments are Wipro and Bangalore then
the output generated should be Wipro Technologies Bangalore.
Command
1 Line
Argument
Example2)
If the command line arguments are ABC and Mumbai then the
output generated should be ABC Technologies Mumbai

[Note: It is mandatory to pass two arguments in command line]

Write a Program to accept a String as a command line argument


and print a Welcome message as given below.

Command
2 Example1) Line
Argument
C:\> java Sample John
O/P Expected : Welcome John

Write a Program to accept two integers as command line


arguments and print the sum of the two numbers

Command
3 Example1) Line
Argument
C:\>java Sample 10 20
O/P Expected : The sum of 10 and 20 is 30

Loops
No Topics
Hands-on Assignment Status
. Covered

Write a program to check if a given integer number is


1 Positive, Negative, or Zero. If Statement

Write a program to check if a given integer number is odd or


2 even. If Statement

Write a program to check if the program has received command


line arguments or not.

If the program has not received arguments then print "No


Values", else print all the values in a single line separated
by ,(comma)

Example1) java Example


3 If Statement
O/P: No values

Example2) java Example Mumbai Bangalore


O/P: Mumbai,Bangalore

[Hint: You can use length property of an array to check its


length]

Initialize two character variables in a program and display


the characters in alphabetical order.

Example1) if the first character is 's' and second character is


4 'e' then the output should be e,s If Statement

Example2) if the first character is 'a' and second character is


'e', then the output should be a,e

5 If Statement
Initialize a character variable in a program and
print 'Alphabhet' if the initialized value is an alphabhet,

print 'Digit' if the initialized value is a number, and

print 'Special Character', if the initialized value is anything


else.

Write a program to accept gender ("Male" or "Female") and age


from command line arguments and print the percentage of
interest based on the given conditions.

If the gender is 'Female' and age is between 1 and 58, the


percentage of interest is 8.2%.

6 If the gender is 'Female' and age is between 59 and 100, the If Statement
percentage of interest is 9.2%.

If the gender is 'Male' and age is between 1 and 58, the


percentage of interest is 8.4%.

If the gender is 'Male' and age is between 59 and 100, the


percentage of interest is 10.5%.

7 If Statement
Initialize a character variable with an alphabhet in a
program.

If the character value is in lowercase, the output should be


displayed in uppercase in the following format.

Example1)
i/p:a
o/p:a->A

If the character value is in uppercase, the output should be


displayed in lowercase in the following format.
Example2)
i/p:A
o/p:A->a

Write a program to receive a color code from the user (an


Alphabhet).

The program should then print the color name, based on the
color code given.

Switch
8
The following are the color codes and their corresponding color Statement
names.
R->Red, B->Blue, G->Green, O->Orange, Y->Yellow, W->White.

If color code provided by the user is not valid then print


"Invalid Code".

9 Switch
Write a program to receive a number and print the Statement
corresponding month name.

Example1)

C:\>java Sample 12

O/P Expected : December

Example2)

C:\>java Sample

O/P Expected : Please enter the month in numbers


Example3)

C:\>java Sample 15

O/P Expected : Invalid month

Write a program to print numbers from 1 to 10 in a single row


10 with one tab space. For Loop

Write a program to print even numbers between 23 and 57. Each


11 number should be printed in a separate row. For Loop

12 Write a program to check if a given number is prime or not. For Loop

13 Write a program to print prime numbers between 10 and 99. For Loop

14 For Loop
Write a Java program to find if the given number is prime or
not.

Example1)
C:\>java Sample
O/P: Please enter an integer number

Example2)
C:\>java Sample 1
O/P:1 is neither prime nor composite

Example3)
C:\>java Sample 0
O/P: 0 is neither prime nor composite

Example4)
C:\>java Sample 10
O/P: 10 is not a prime number

Example5)
C:\>java Sample 7
O/P : 7 is a prime number

Write a program to print the sum of all the digits of a given


number.

15 Example1) For Loop

I/P:1234
O/P:10

Write a program to print * in Floyds format (using for and


while loop)
*
* *
* * *

Example1)
C:\>java Sample
16 O/P: Please enter an integer number For Loop

Example2)
C:\>java Sample 3
O/P :
*
* *
* * *

17 While Loop
Write a program to reverse a given number and print
Example1)
I/P: 1234
O/P:4321

Example2)
I/P:1004
O/P:4001

Write a Java program to find if the given number is palindrome


or not

Example1)
C:\>java Sample 110011
18 O/P: 110011 is a palindrome While Loop

Example2)
C:\>java Sample 1234
O/P: 1234 is not a palindrome

Write a program to print first 5 values which are divisible by


19 2, 3, and 5. While Loop
Arrays

Topics
No. Hands-on Assignment Status
Covered

Write a program to initialize an integer array and print the One


1 sum and average of the array. dimensional
Array

Write a program to initialize an integer array and find the One


2 maximum and minimum value of the array. dimensional
Array

Write a program to initialize an integer array with values


and check if a given number is present in the array or not.

If the number is not found, it will print -1 else it will


print the index value of the given number in the array.
One
3 dimensional
Example 1) If the Array elements are {1,4,34,56,7} and the Array
search element is 90, then the output expected is -1.

Example 2)If the Array elements are {1,4,34,56,7} and the


search element is 56, then the output expected is 3.

Initialize an integer array with ascii values and print the One
4 corresponding character values in a single row. dimensional
Array

Write a program to find the largest 2 numbers and the One


5 smallest 2 numbers in the given array. dimensional
Array

Write a program to initialize an array and print them in a One


6 sorted order. dimensional
Array
Write a program to remove the duplicate elements in an array
and print the same.
Example) One
7 dimensional
I/P:{12,34,12,45,67,89} Array
O/P:{12,34,45,67,89}

Write a program to print the sum of the elements of an array


following the given below condition.

If the array has 6 and 7 in succeeding orders, ignore the


numbers between 6 and 7 and consider the other numbers for
calculation of sum.

Eg1) Array Elements - 10,3,6,1,2,7,9


One
O/P: 22
8 dimensional
[i.e 10+3+9] Array

Eg2) Array Elements - 7,1,2,3,6


O/P:19

Eg3) Array Elements - 1,6,4,7,9


O/P:10

9 Two
Write a program to reverse the elements of a given 2*2 array. Dimensional
Four integer numbers needs to be passed as Command Line Array
arguments.

Example1)
C:\>java Sample 1 2 3
O/P: Please enter 4 integer numbers

Example2)
C:\>java Sample 1 2 3 4
O/P:
The given array is :
1 2
3 4
The reverse of the array is :
4 3
2 1

Write a program to find the biggest number in a 3*3 array.


The program is supposed to receive 9 integer numbers as
command line arguments.

Example1:
C:\>java Sample 1 2 3
O/P: Please enter 9 integer numbers
Two
10 Dimensional
Example2: Array
C:\>java Sample 1 23 45 55 121 222 56 77 89
O/P:
The given array is :
1 23 45
55 121 222
56 77 89
The biggest number in the given array is 222
Class and objects

No Topics
Hands-on Assignment Status
. Covered

Create a class Box that uses a parameterized constructor to


initialize the dimensions of a box.The dimensions of the Box Classes
are width, height, depth. The class should have a method that and
1
can return the volume of the box. Create an object of the Box Objects,
class and test the functionalities. Constructor

Create a new class called Calculator with the following


methods:
1. A static method called powerInt(int num1,int num2)
Classes
This method should return num1 to the power num2.
and
2 2. A static method called powerDouble(double num1,int num2). Objects,
Constructor,
This method should return num1 to the power num2. static
3. Invoke both the methods and test the functionalities.
Hint: Use Math.pow(double,double) to calculate the power.

3 Classes
Design a class that can be used by a health care professional and
to keep track of a patient’s vital statistics. The following Objects,
are the details. Constructor,
Name of the class - Patient static

Member Variables -
patientName(String),height(double),width(double)
Member Function - double computeBMI()
The above method should compute the BMI and return the result.
The formula for computation of BMI is weight (in kg) ÷
height*height(in metres).
Create an object of the Patient class and check the results.

Encapusulation and Abstraction

No Topics
Hands-on Assignment Status
. Covered

Create a class Author with the following information.


Member variables : name (String), email (String), and gender
(char)
Parameterized Constructor: To initialize the variables

Create a class Book with the following information.


Member variables : name (String), author (of the class
Encapsulation
1 Author you have just created), price (double), and
/ Abstraction
qtyInStock (int)
[Assumption: Each book will be written by exactly one
Author]
Parameterized Constructor: To initialize the variables
Getters and Setters for all the member variables

In the main method, create a book object and print all


details of the book (including the author details)
No.Hands-on AssignmentTopics CoveredStatus1
Create a class named ‘Animal’ which includes methods like eat() and sleep().

Create a child class of Animal named ‘Bird’ and override the parent class methods.
Add a new method named fly().

Create an instance of Animal class and invoke the eat and sleep methods using this
object.

Create an instance of Bird class and invoke the eat, sleep and fly methods using this
object.

Inheritance 2
Create a class called Person with a member variable name. Save it in a file called
Person.java

Create a class called Employee that will inherit the Person class.The other data
members of the Employee class are annual salary (double), the year the employee
started to work, and the national insurance number which is a String.Save this in a
file called Employee.java

Your class should have the necessary constructors and getter/setter methods.
Write another class called TestEmployee, containing a main method to fully test your
class definition.

Inheritance 3
Create a school application with a class called Person. Create name and dateOfBirth
as member variables.

Create a class called Teacher that inherits from the Person class. The teacher will
have additional properties like salary, and the subject that the teacher teaches.

Create a class called Student that inherits from Person class. This class will have a
member variable called studentId.

Create a class called College Student that inherits from Student class. This class
will have collegeName, the year in which the student is studying
(first/second/third/fourth) etc.

Create objects of each of this classes, invoke and test the methods that are
available in these classes.

Inheritance

Overriding / Polymorphism

No Topics
Hands-on Assignment Status
. Covered

1 Inheritance
Create a base class Fruit with name ,taste and size as its / Overriding
attributes.

Create a method called eat() which describes the name of the


fruit and its taste.

Inherit the same in 2 other classes Apple and Orange and


override the eat() method to represent each fruit taste.

Write a program to create a class named shape. It should


contain 2 methods, draw() and erase() that prints “Drawing
Shape” and “Erasing Shape” respectively.

For this class, create three sub classes, Circle, Triangle and
Square and each class should override the parent class
functions - draw () and erase ().

The draw() method should print “Drawing Circle”, “Drawing


Triangle” and “Drawing Square” respectively.

2 The erase() method should print “Erasing Circle”, “Erasing


Triangle” and “Erasing Square” respectively.

Create objects of Circle, Triangle and Square in the following


way and observe the polymorphic nature of the class by calling
draw() and erase() method using each object.

Shape c=new Circle();


Shape t=new Triangle();
Shape s=new Square();

No
Hands-on Assignment Topics Covered Status
.

Write a Program to check whether a given String is


1 Palindrome or not. String/StringBuffer

2 String/StringBuffer
Write a java program that will concatenate 2 strings and
return the result. The result should be in lowercase.

Note:If the concatenation creates a double-char, then one


of the characters need to be omitted.

Example1)
i/p:Sachin,Tendulkar
o/p:sachin tendulkar

Example2)
i/p:Mark,kate
o/p:markate

Given a string, return a new string made of 'n' copies of


the first 2 chars of the original string where 'n' is the
length of the string.

3 String/StringBuffer
Example1)
i/p:Wipro
o/p:WiWiWiWiWi

Write a java program that will return the first half of


the string, if the length of the string is even. It should
return null for odd length string.

Example1)
i/p:TomCat
4 String/StringBuffer
o/p:Tom

Example2)
i/p:Apron
o/p:null
Write a java program that accepts a string and returns a
new string without the first and last character of the
input string.

5 String/StringBuffer
Example1)
i/p:Suman
o/p:uma

Given 2 strings, a and b, return a new string of the form


short+long+short, with the shorter string on the outside
and the longer string on the inside.

6 The strings will not be the same length, but they may be String/StringBuffer
empty (length 0).

If input is "hi" and "hello", then output will be


"hihellohi".

Given a string, if the first or last chars are 'x',


return the string without those 'x' chars, otherwise
return the string unchanged.

7 String/StringBuffer
If the input is "xHix", then output is "Hi".
If the input is "America", then the output is "America".

Write a Java program that accepts a string (with * in


it). The program should return a new string in which the
following characters are removed-*,the characters that are
to the left and right of *

8 String/StringBuffer
Example1)
i/p:ab*cd
o/p:ad

9 String/StringBuffer
Given two strings, a and b, print a new string which is
made of the following combination-first character of a,
the first character of b, second character of a, second
character of b and so on.
Any characters left, will go to the end of the result.

Example1)
i/p:Hello,World
o/p:HWeolrllod

Given a string and an integer n, print a new string made


of n repetitions of the last n characters of the string.
You may assume that n is between 0 and the length of the
string, inclusive.

10 String/StringBuffer
Example1)
i/p:Wipro,3
o/p:propropro

11 String/StringBuffer
Given two strings a and b, return a new string, following
the rules given below.
If string b occurs in string a, then the new string should
concatenate the characters that appear before and after of
String b.
Ignore cases where there is no character before or after
the word, and a character may be included twice if it is
in between two string b's.

Example1)
i/p:abcXY123XYijk,XY
o/p:c13i

Example2)
i/p:XY123XY,XY
o/p:13

Example3)
i/p:XY1XY,XY
o/p:11

No Topics
Hands-on Assignment Status
. Covered

1 Abstract
Create a class called GeneralBank that acts as base class for Classes
all banks. This class has getSavingsInterestRate and
getFixedDepositInterestRate methods, which returns the savings
account interest rate and fixed deposit account interest rate
that the specific bank gives. Since GeneralBank cannot say what
percentage which bank would give, make these methods abstract.

Create two subclasses of GeneralBank called ICICIBank and


KotMBank. Override the inherited methods from the base class.
The following are the interest rates of these banks.
ICICIBank - Savings 4% Fixed 8.5% and
KotMBank - Savings 6% Fixed 9%.

Create a main method to test the above classes and their


methods. Try one by one and observe your findings

a) ICICIBank i=new ICICIBank();


b) KotMBank k=new KotMBank();

c) GeneralBank g=new KotMBank();

d) GeneralBank g=new ICICIBank();

Create an abstract class Compartment to represent a rail


coach. Provide an abstract function notice in this class.

public abstract String notice();

Derive FirstClass, Ladies, General, Luggage classes from the


compartment class. Override the notice function in each of them
to print notice message that is suitable to the specific type
of compartment.
Abstract
2
Classes
Create a class TestCompartment.Write main function to do the
following:
Declare an array of Compartment of size 10.
Create a compartment of a type as decided by a randomly
generated integer in the range 1 to 4.
Check the polymorphic behavior of the notice method.
[i.e based on the random number genererated, the first
compartment can be Luggage, the second one could be Ladies and
so on..]

3 Abstract
Create an abstract class Instrument which is having the Classes
abstract function play.

Create three more sub classes from Instrument which is Piano,


Flute, Guitar. Override the play method inside all three
classes printing a message
“Piano is playing tan tan tan tan ” for Piano class
“Flute is playing toot toot toot toot” for Flute class
“Guitar is playing tin tin tin ” for Guitar class
Create an array of 10 Instruments.
Assign different type of instrument to Instrument reference.
Check for the polymorphic behavior of play method.
Use the instanceof operator to print which object is stored at
which index of instrument array.

No Topics
Hands-on Assignment Status
. Covered

Create a package called test package.


Define a class called foundation inside the test package.
Inside the class, you need to define 4 integer variables:
var1 with private access modifier
var2 with default access modifier Packages
Access
1 var3 with protected access modifier control
Using
var4 with public access modifier package

Import this class and packages in another class.


Try to access all 4 variables of the foundation class and see
what variables are accessible and what are not accessible.
Create a class called compartment which represents the ship
compartments with attributes like height, width and breadth.

Packages
Take care it should not conflict with the compartment class User
2 you have created in Abstract class exercise 2. defined
packages

To avoid conflict create this class in a new package called


com.wipro.automobile.ship

Create a package called com.automobile. Define an abstract


class called Vehicle.
Vehicle class has the following abstract methods:
public String getModelName()
public String getRegistrationNumber()
public String getOwnerName()

Create twowheeler subpackage under automobile package


Hero class extends automobile.vehicle class with the
following methods
public int getSpeed()
– returns the current speed of the vehicle. Packages
User
3 public void radio()
defined
– provides facility to control the radio device packages

Honda class extends com.automobile.vehicle class with the


following methods
public int getSpeed()
– Returns the current speed of the vehicle.
public void cdplayer()
– provides facility to control the cd player device which is
available in the car.

Create a test class to test the methods available in all these


child class.
Add the following ideas to the previous hands on:
Create FourWheeler subpackage under automobile package
Logan class extends com.automobile.Vehicle class
public int speed()
– Returns the current speed of the vehicle.
public int gps()
– provides facility to control the gps device
Packages
User
4
defined
Ford class extends com.automobile.Vehicle class packages
public int speed()
– Returns the current speed of the vehicle.
public int tempControl()
– provides facility to control the air conditioning device
which is available in the car
Create objects of the relevant classes and test the various
functionalities of the class.

No Topics
Hands-on Assignment Status
. Covered

1 Interfaces
An online library application need to be created for two types
of users/roles-Adults and children. Both of these users should
be able to register an account.

Any user who is less than 12 years of age will be registered as


a child and they can borrow a “Kids” category book for 10 days,
whereas an adult can borrow “Fiction” category books which need
to be returned within 7 days.

Note: In future, more users/roles might be added to the library


where similar rules will be enforced.
Develop Interfaces and classes for the categories mentioned
above.

1. Create an interface LibraryUser with the following methods


void registerAccount()

void requestBook
()

2. Create 2 classes “KidUsers” and “AdultUser” which implements


the LibraryUser interface.

3. Both the classes should have two instance variables -


age(int),bookType(String)

4. The methods in the KidUser class should perform the


following logic.

registerAccount():

if age < 12, a message displaying “You have successfully


registered under a Kids Account” should be displayed in the
console.

If(age>12), a message displaying, “Sorry, Age must be less than


12 to register as a kid” should be displayed in the console.

requestBook():

if bookType is “Kids”, a message displaying “Book Issued


successfully, please return the book within 10 days” should be
displayed in the console,else, a message displaying, “Oops, you
are allowed to take only kids books” should be displayed in the
console.

5. The methods in the AdultUser class should perform the


following logic.

registerAccount():

if age > 12, a message displaying “You have successfully


registered under an Adult Account” should be displayed in the
console.

If age<12, a message displaying, “Sorry, Age must be greater


than 12 to register as an adult” should be displayed in the
console.

requestBook function:

if bookType is “Fiction”, a message displaying “Book Issued


successfully, please return the book within 7 days” should be
displayed in the console., else, a message displaying, “Oops,
you are allowed to take only adult Fiction books” should be
displayed in the console.

6. Create a class “LibraryInterfaceDemo.java” with a main


method and test the functionalities by creating objects of
KidUser and AdultUser classes.

2 Interfaces
Write an interface called Playable, with a method
void play();
Let this interface be placed in a package called music.

Write a class called Veena which implements Playable interface.


Let this class be placed in a package music.string

Write a class called Saxophone which implements Playable


interface. Let this class be placed in a package music.wind

Write another class Test in a package called live. Then,


a. Create an instance of Veena and call play() method
b. Create an instance of Saxophone and call play() method
c. Place the above instances in a variable of type Playable and
then call play()

No Topics
Hands-on Assignment Status
. Covered

1 Exception
Get an input String from user and parse it to integer, if it Handling
is not a number it will throw number format exception Catch it
and print "Entered input is not a valid format for an integer."
or else print the square of that number. (Refer Sample Input
and Output).

Sample input and output 1:


Enter an integer: 12
The square value is 144
The work has been done successfully

Sample input and output 2:


Enter an integer: Java
Entered input is not a valid format for an integer.

Write a program that takes as input the size of the array and
the elements in the array. The program then asks the user to
enter a particular index and prints the element at that index.

This program may generate Array Index Out Of Bounds Exception.


Use exception handling mechanisms to handle this exception. In
the catch block, print the class name of the exception thrown.

Sample Input and Output 1:


Enter the number of elements in the array
3
Enter the elements in the array
20
90
4
Enter the index of the array element you want to access Exception
2 Handling:
2 Try-catch
The array element at index 2 = 4
The array element successfully accessed

Sample Input and Output 2:


Enter the number of elements in the array
3
Enter the elements in the array
20
90
4
Enter the index of the array element you want to access
6
java.lang.ArrayIndexOutOfBoundsException
3 Exception
Handling:
Try-catch
Use
multiple
catch block
Write a program that takes as input the size of the array and
the elements in the array. The program then asks the user to
enter a particular index and prints the element at that index.
Index starts from zero.

This program may generate Array Index Out Of Bounds Exception


or NumberFormatException . Use exception handling mechanisms
to handle this exception.

Sample Input and Output 1:


Enter the number of elements in the array
2
Enter the elements in the array
50
80
Enter the index of the array element you want to access
1
The array element at index 1 = 80
The array element successfully accessed

Sample Input and Output 2:


Enter the number of elements in the array
2
Enter the elements in the array
50
80
Enter the index of the array element you want to access
9
java.lang.ArrayIndexOutOfBoundsException
Sample Input and Output 3:
Enter the number of elements in the array
2
Enter the elements in the array
30
j
java.lang.NumberFormatException

Write a class MathOperation which accepts 5 integers through


command line. Create an array using these parameters. Loop
through the array and obtain the sum and average of all the
elements and display the result. Exception
4 handling:
throws
Various exceptions that may arise like ArithmeticException,
NumberFormatException, and so on should be handled.

Write a Program with a division method which receives two


integer numbers and performs the division operation.

5 throws
The method should declare that it throws ArithmeticException.
This exception should be handled in the main method.

Write a Program to take care of Number Format Exception if


user enters values other than integer for calculating average Exception
marks of 2 students. The name of the students and marks in 3 Handling:
subjects are taken from the user while executing the program. Throw &
6
Used
In the same Program write your own Exception classes to take
Defined
care of Negative values and values out of range (i.e. other
Exception
than in the range of 0-100)

7 Exception
A student portal provides user to register their profile. Handling:
During registration the system needs to validate the user User
should be located in India. If not the system should throw an Defined
Exception &
throw
exception.

Step 1: Create a user defined exception class named


“InvalidCountryException”.
Step 2: Overload the respective constructors.
Step 3: Create a main class “UserRegistration”, add the
following method,
void registerUser(String username,String userCountry) with the
below implementation
• if userCountry is not equal to “India” throw a
InvalidCountryException with the message “User Outside India
cannot be registered”
• if userCountry is equal to “India”, print the message “User
registration done successfully”

Invoke the method registerUser from the main method with the
data specified and see how the program behaves.
Example1)
i/p:Mickey,US
o/p:InvalidCountryException should be thrown.
The message should be “User Outside India cannot be
registered”

Example2)
i/p:Mini,India
o/p:User registration done successfully

8 Exception
handling:
User
Write a program to accept name and age of a person from the
Defined
command prompt(passed as arguments when you execute the class)
Exception &
and ensure that the age entered is >=18 and < 60.
throw
Display proper error messages.

The program must exit gracefully after displaying the error


message in case the arguments passed are not proper.
(Hint : Create a user defined exception class for handling
errors.)

Write a program that accepts 2 integers a and b as input and


finds the quotient of a/b.

This program may generate an Arithmetic Exception. Use


exception handling mechanisms to handle this exception.

In the catch block, print the message as shown in the sample


output.
Also illustrate the use of finally block. Print the message
“Inside finally block”.

Example1) Exception
Handling:
9 Enter the 2 numbers
Finally
5 block

2
The quotient of 5/2 = 2
Inside finally block

Example2)
Enter the 2 numbers
5
DivideByZeroException caught
Inside finally block

No Topics
Hands-on Assignment Status
. Covered

1 I/O Streams
Write a program to count the number of times a character
appears in a File.

[Note : The character check is case insensitive... i.e, 'a'


and 'A' are considered to be the same]
Sample Input and Output:
Enter the file name
Input.txt
Enter the character to be counted
r
File 'Input.txt' has 99 instances of letter 'r'.

Write a program to copy contents from one file to another and


check the output.

Sample Input and Output:


Enter the input file name
2 I/O Streams
Input.txt
Enter the output file name
Output.txt
File is copied.

3 I/O

Write a program to count the occurrences of each word in an


input file and write the word along with its corresponding
count in an output file.

[Note: The words should be sorted alphabetically in the output


file]

(Hint : Consider using Map Collection)

For Example, let's assume the following are the contents of


inputFile.txt

Manoj works at Wipro


Katari works at Wipro
Sureka works at Wipro
Harish works at Wipro
Anitha works at Wipro
Janani works at Wipro

D:\>Java FileWordCount inputFile.txt outputFile.txt

After Execution of the program the contents of outputFile.txt


should be as below

Anitha : 1
Harish : 1
Janani : 1
Katari : 1
Manoj : 1
Sureka : 1
Wipro : 6
at : 6
works : 6

No Topics
Hands-on Assignment Status
. Covered
Create a thread which prints 1 to 10. After printing 5, there Thread
1 should be a delay of 5000 milliseconds before printing 6 Control
Mechanism

Create two threads, one thread to display all even numbers


Use of join
between 1 & 20, another to display odd numbers between 1 & 20.
method and
2 Note: Display all even numbers followed by odd numbers thread
control
Hint: use join mechanism

Create three threads- with different priorities – MAX, MIN,


NORM- and start the threads at the same time. Observe the Thread
3
completion of the threads. Priorities

No Topics
Hands-on Assignment Status
. Covered

Create two threads and assign names ‘Scooby’ and ‘Shaggy’ to Setting the
1 the two threads. Display both thread names. name of the
thread.

store colours in the form of an array


ex: String
colours[]={"white","blue","black","green","red","yellow"};
Thread
2 display all colours repeatedly by generating colour index from
creation
Random class. If the random colour index matches to red stop
display.
Note: perform this task by implementing Runnabe interface

Вам также может понравиться