You are on page 1of 5

JAVA / SQL Written Questions (4 Hours)

Name :

I. Single answer question


(3 points for each question, 15 points in total)

1. The following options are not part of the underlying data type()
A. boolean C. double
B. char D. String

2. Which of the following constructors of the Account class is correct?


A. Account(String name) {} C. Account(name) ()
B. Account(String name) D. NewAccount(String name) {}

3. The result of the following program is


class TestApp {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
if (i == 3)
break;
System.out.print(i);
}
}
}
A. 0123 C. 0123456789
B. 012456789 D. 012
4. Assuming that there is a custom exception class ServiceException, which is the correct
statement to throw the exception?
A. raise ServiceException C. throw ServiceException
B. throw new D. throws ServiceException
ServiceException()

5. The result of the following program is


class Test4 {
public static void main(String[] args) {
boolean x = true;
boolean y = false;
short z = 42;
if ((z++ == 42) && (y = true)) z++;
if ((x = false) || (++z == 45)) z++;
System.out.println("z=" + z);
}
}
A. z=42 C. z=45
B. z=44 D. z=46

II. True or False


(3 points for each question, 15 points in total)

1. The values of boolean data are only true and false.


A. TRUE B. FALSE

2. When manufacturing (new) an array, specify the length of the array in order to allocate
memory for the array.
A. TRUE B. FALSE

3. In Java, when a high-precision data type is assigned a value to a low-precision data type
through forced type conversion, its value remains unchanged.
A. TRUE B. FALSE

4. (x > 0 || x < 10 && y < 0) and ((x > 0 || x < 10) && y < 0) value is same
A. TRUE B. FALSE

5. The elements of an array in Java can be quantities of simple data types or objects of a certain
class.
A. TRUE B. FALSE
III. Java
(20 points)

1. Make a simple program that can Input three integers x, y, z and output these three numbers
sorted from small to large. Put the source code and the output with 2 different input below.
(10 points)
2. Write a nested loop program to calculate from integer 1 to 100, print output of every number
addition and the final result! Put the source code and the output below. (10 points)

IV. SQL
(50 points)

1. Write a statement to create Table which has 2 Primary Key column, the first one is DESC
ordered and the second PK is ASC ordered (7 points)

2. There are the following data tables in the database, please complete the following operations
student

Field name Type Length Required Default value Description

Studentid Varchar 10 PK

Name Varchar 10

Sex Varchar 2
course

Field name Type Length Required Default value Description

CourseID Varchar 10 PK

CourseName Varchar 40

Teacher Varchar 10

sc

Field name Type Length Required Default value Description

Studentid Varchar 10 PK

CourseID Varchar 40

Grade Float

(1) Query the names, course numbers and grades of students whose scores are greater than
85, and follow the ascending order of course numbers (4 points)
(2) Update the score of the computer subject of the student named "Michael Jordan" to 90
points (3 points)
(3) Please write down the statement that creates the "Student" table Student (3 points)
(4) In the student table, query all the information of the students in ascending order of
student ID whose names do not start with "Diana", "Sam", and "David". (10 points)
(5) Delete the course data whose teacher is "Justin Br" in the course table (3 points)
(6) Add 3 more data in the sc table with one query (5 points)
(7) Query the information of students who do not study all courses, but at least take one
course (10 points)
Sample output:

Studentid Name Sex Courses Taken

2 David Brown M 4

4 Diana Rose F 1

5 David Harley M 2

(8) Find out the student numbers and names with only two courses (5 points)

You might also like