Training Assignments
Training Assignments
0.1
Effective date
11/05/2011
Hanoi, 05/2011
Training Assignments
Java Basics
RECORD OF CHANGES
*A - Added M - Modified D - Deleted
Date
Changes
A*
M, D
Contents
Version
11/05/2011
Create new
All
0.1
79e-BM/NS/HDCV/FSOFT v1/0
Internal use
2/6
Training Assignments
Java Basics
Contents
Day 1: Assignments................................................................................................................ 4
Assignment 1:..................................................................................................................... 4
Assignment 2:..................................................................................................................... 4
Assignment 3:..................................................................................................................... 4
Assignment 4:..................................................................................................................... 5
Assignment 5:..................................................................................................................... 5
Assignment 6:..................................................................................................................... 5
Assignment 7:..................................................................................................................... 6
Assignment 8:..................................................................................................................... 6
79e-BM/NS/HDCV/FSOFT v1/0
Internal use
3/6
Training Assignments
Java Basics
Day 1: Assignments
Assignment 1:
Objective:
Problem Description:
Assignment 2:
Objective:
Problem Description:
Assumptions:
Questions to answer:
Estimated time: 5 mins
Assignment 3:
Objective:
Problem Description:
79e-BM/NS/HDCV/FSOFT v1/0
Internal use
4/6
Training Assignments
Java Basics
Assumptions:
Questions to answer:
Estimated time: 10 mins
Assignment 4:
Objective:
Problem Description:
1. Explain how the intern() method in java.lang.String can improve runtime performance
of a program.
Hint: see API documentation for String class, especially method intern()
Assumptions:
Questions to answer:
Estimated time: 10 mins
Assignment 5:
Objective:
Problem Description:
In some languages the operators "&&" (and) and "||" (or) are short circuited. That is
once the result of a boolean expression of &&s and ||s is known, the remainder of the
boolean expression will not be evaluated. For example in (( x > x ) && ( z == y) ) the
expression (z ==y) will not be evaluated. Write a Java method that will test if boolean
expressions in Java are short circuited. Explain how your program will determine if
boolean expressions are short circuited.
Assumptions:
Questions to answer:
Estimated time: 15 mins
Assignment 6:
Objective:
Problem Description:
In both parts of the problem do not perform any IO in the methods. Provide output to
show that your program runs.
a) Write a Java method that has a float parameter and returns the float
converted to a string.
79e-BM/NS/HDCV/FSOFT v1/0
Internal use
5/6
Training Assignments
Java Basics
b) Write a Java method that has a string parameter and returns the string
converted to an int. Assume that the string represents an integer base 10 in
the correct range for an int.
Assumptions:
Questions to answer:
Estimated time: 30 mins
Assignment 7:
Objective:
Problem Description:
Assignment 8:
Objective:
Problem Description:
2. Write a Java program to count the number of 1 bit in a binary string which was
gotten from a given int number. For example:
Give an int number 10, we got a binary 1010, then result will be 2.
Assumptions:
Questions to answer:
Estimated time: 30 mins
79e-BM/NS/HDCV/FSOFT v1/0
Internal use
6/6