Lompat ke konten Lompat ke sidebar Lompat ke footer

JFo Java Foundations Midterm Exam

1. Which two are the correct syntax for adding comments?

(Pilih semua jawaban yang benar)

Start with two slashes and a star (//*). End with a star-slash (*/).

Start with two slashes (//). End when the line ends. (*)

Start with a slash-star (/*). End with a star-slash (*/). (*)

Start with two slashes (//). End with two slashes (//).

Start with a slash- star (/*). End with slash-star (/*).

Correct

(1/1) Point

2. Which of the following are considered Whitespace?

(Pilih semua jawaban yang benar)

Blank lines in the code. (*)

Space between the [ ] braces.

Space in the print statements.

Indentation before the code. (*)

Space between words. (*)

Incorrect. Refer to Section 2 Lesson 2.

(0/1) Point

3. Java mostly reads code line-by-line.

benar (*)

Palsu

Correct

(1/1) Point

4. During the Testing phase of software development, which of the following are the tasks undertaken by the programmer?

(Pilih semua jawaban yang benar)

Fixing the bugs. (*)

Finding the bugs. (*)

Listing required features.

Planning the order to implement features.

Correct

(1/1) Point

5. What is the correct order of steps in the Spiral Model of Development?

Requirements, Design, Test, Develop

Requirements, Design, Develop, Test (*)

Design, Requirements, Develop, Test

Design, Develop , Requirements, Test

Correct

6. You’d like to see a movie with a few friends. You write an email to confirm plans.


Hi Friends,

There’s a new movie “Attack of the Duke!” premiering this Friday at Oracle Cinema at 4:30 PM. The cinema is at the corner of South Street and Walnut Ave. Subway would be the best way to get there.


Would any of you be interested in going?


Which of the following are requirements for this plan?

Reach the cinema by 4:00 PM.

Watch “Attack of the Duke!” on Friday at Oracle Cinema at 4:30 PM. (*)

Double check the location by verifying you’re on South Street and Walnut Ave.

Travel via subway.

Correct

(1/1) Point

7. In the code example below, identify any methods:


public class Employee {

public String name = " Duke";

public int empId = 12105;

public float salary;


public void displaySalary(){

System.out.println("Employee Salary: "+salary);

}

}

displaySalary() (*)

salary

empId

name

Correct

(1/1) Point

8. There are several fields and methods in a Shirt class. Which of the following could be a method in the Shirt class?

price

getShirtSize() (*)

size

color

Correct

(1/1) Point

9. An object may interact with another object by invoking methods.

benar (*)

Palsu

Correct

(1/1) Point

Section 3

(Jawab semua pertanyaan di bagian ini)

10. Automatic promotion from smaller data type to a larger data type is not allowed in Java.

benar

Palsu (*)

Correct

11. Which exception occurs because a String cannot be parsed as an int?

NumberFormatException (*)

ArithmeticException

NullPointerException

ValueNotFoundException

Correct

(1/1) Point

12. Which two statements are correct about the usage of an underscore?

(Pilih semua jawaban yang benar)

Underscores help the compiler interpret large numbers.

Underscores do not affect the value of the variable. (*)

Underscores change the value of the number.

Underscores help make large numbers more readable. (*)

Correct

(1/1) Point

13. What is the output?


public class Person {

  public static void main(String args[]) {

  int age = 20;

  System.out.println("Value of age: " +age);

  age = 5 + 3;

  System.out.println("Value of age: " +age);

  age = age + 1;

  age++;

  System.out.println("Value of age: " +age);

  }

}

Value of age: 20

Value of age: 8

Value of age: 10 (*)

Value of age: 20

Value of age: 28

Value of age: 38

Value of age: 20

Value of age: 208

Value of age: 20810

Value of age: 20

Value of age: 8

Value of age: 9

Correct

(1/1) Point

14. Which of the following data types is the largest?

byte

short

int

long (*)

Correct

(1/1) Point

15. Which two are mathematical operators?

(Pilih semua jawaban yang benar)

+ (*)

– (*)

#

@

Correct

16. A String can be created by combining multiple String Literals.

benar (*)

Palsu

Correct

(1/1) Point

17. In Java, char is a primitive data type, while String is an object data type.

benar (*)

Palsu

Correct

(1/1) Point

18. The print() method prints to the console and automatically creates a line.

benar

Palsu (*)

Incorrect. Refer to Section 3 Lesson 3.

(0/1) Point

19. Which two statements will not compile?

(Pilih semua jawaban yang benar)

int break=10; (*)

double salary = 20000.34;

double double=10; (*)

int age=20;

int abc = 10;

Correct

(1/1) Point

20. Assigning a value to the variable is called "initialization".

benar (*)

Palsu

Correct

21. Which of the following two statements are true about variables?

(Pilih semua jawaban yang benar)

They make code more flexible. (*)

The value assigned to a variable may never change.

Variables will be ignored by compiler.

The allow code to be edited more efficiently. (*)

Correct

(1/1) Point

22. It's best-practice to close the Scanner stream when finished

benar (*)

Palsu

Correct

(1/1) Point

23. System.in readies Scanner to collect input from the console.

benar (*)

Palsu

Correct

(1/1) Point

24. Which two statements are true about the Scanner class?

(Pilih semua jawaban yang benar)

A Scanner object doesn’t have fields and methods.

A Scanner’s delimiter can be changed. (*)

A Scanner object opens a stream for collecting input. (*)

Scanners cannot read text files.

Correct

(1/1) Point

Section 4

(Jawab semua pertanyaan di bagian ini)

25. What is the output of the following code?


public static void main(String args[]) {

   String firstString = "Java";

   firstString = firstString.concat("World");

   System.out.println(firstString);

}

Java World

World

JavaWorld (*)

Java

Correct

26. What is the output?


public static void main(String args[]) {

   String greeting = "Java World!";

   String w = greeting.substring(7, 11);

   System.out.println(w);

}

rld! (*)

orld!

ld!

rld

Correct

(1/1) Point

27. The String class must be imported using java.lang.String;

benar

Palsu (*)

Correct

(1/1) Point

28. What is the output?


public static void main(String args[]) {

   String greeting = "Java World!";

   String w = greeting.replace("a", "A");

   System.out.println(w);

}

JavA World!

Java World!

JAva World!

JAvA World! (*)

Incorrect. Refer to Section 4 Lesson 3.

(0/1) Point

29. Which two are valid import statements of the Scanner class?

(Pilih semua jawaban yang benar)

import java.*;

import java.util;

import java.util.*; (*)

import java.util.Scanner; (*)

Correct

(1/1) Point

30. Given the import statement:

import java.awt.font.TextLayout;

which is the package name?

awt.font

java.awt

java.awt.font (*)

java

Correct

31. Which is a risk of using fully qualified class names when importing?

Code readability is reduced. (*)

Memory usage is increased.

Performance of the code is reduced.

The compiler runs longer.

Correct

(1/1) Point

32. The classes of the Java class library are organized into packages.

benar (*)

Palsu

Correct

(1/1) Point

33. You need to generate random integer values between 0 and 80 (inclusive). Which statement should you use?

nextInt(0-79);

nextInt(81); (*)

nextInt();

nextInt(80);

Correct

(1/1) Point

34. Which values are returned by the method nextBoolean();

Nothing is returned.

Returns the next value.

Either a true or false. (*)

An integer value.

Incorrect. Refer to Section 4 Lesson 4.

(0/1) Point

35. Using the Random class requires an import statement.

benar (*)

Palsu

Correct

36. Methods allow all instance of a class to share same behaviors.

benar (*)

Palsu

Correct

(1/1) Point

37. void type methods don’t return any values

benar (*)

Palsu

Correct

(1/1) Point

38. Which of the following are the arguments in the following method?


Employee emp = new Employee();

emp.calculateSalary(100000, 3.2, 15);

emp.calculateSalary(100000, 3.2, 15);

emp

calculateSalary(100000, 3.2, 15);

100000, 3.2, 15 (*)

Correct

(1/1) Point

39. You’re designing banking software and need to store 10000 customer accounts with information on the accountholder’s name, balance, and interest rate. The best approach is store 30000 separate variables in the main method.

benar

Palsu (*)

Correct

(1/1) Point

40. What is the approximate value of PI?

The value varies.

3.141 (*)

0

2.718

Correct

41. What is the package name which contains Math class?

java.net

java.lang (*)

java.awt

java.io

Correct

(1/1) Point

Section 5

(Jawab semua pertanyaan di bagian ini)

42. The switch statement is a more efficient way to write code when dealing with a large range of unknown values.

benar

Palsu (*)

Correct

(1/1) Point

43. What is the output?


public static void main(String args[]) {

   char ch ='c';

   switch(ch) {

     case 'a':

     case 'e':

     case 'i':

     case 'o':

     case 'u':

       System.out.println("Vowels");

       break;

     default:

       System.out.println("Consonants");

   }

}

Compilation error

Consonants (*)

Vowels

Vowels

Correct

(1/1) Point

44. A customer is eligible for a discount based on certain criteria. Under what conditions does "You qualify for a discount" print? (Hint: There may be more than one correct answer)


int purchase;

int rewardPoints;

if (purchase >= 2000 || rewardPoints >= 4000) {

   System.out.println("You qualify for discount");

}

(Pilih semua jawaban yang benar)

When purchase is 2000 regardless of the value of rewardPoints (*)

When rewardPoints is more than 2000 or purchase greater than 1000

When purchase is 4000 and rewardPoints is 2000 (*)

When rewardPoints is more than 1000 and purchase is 1000

Correct

(1/1) Point

45. An employee is eligible for a bonus based on certain criteria.

Under what conditions does "Eligible for a bonus" print?


int rating;

int experience;

if (rating > 1 && experience == 5) {

   System.out.println ("Eligible for a bonus");

}

5 experience and 1 rating

5 experience and 2 or more rating (*)

5 rating and 1 experience

Less than 5 experience and 1 rating.

Correct

46. What is the result?


public static void main(String[] args) {

   int point = 10;

   String s = (point == 1 ? "point" : "points");

   System.out.println("I scored " +point +" " +s );

}

I scored 1 point 10 points

I scored 10 points (*)

I scored 1 point

Compilation error

Correct

(1/1) Point

47. How should Strings be compared?

The equals() method (*)

~=

==

=

Correct

(1/1) Point

48. Which are used in a boolean expression?

(Pilih semua jawaban yang benar)

Operators (*)

Loops

Variables (*)

Errors

Correct

(1/1) Point

49. Which three are conditional statements?

(Pilih semua jawaban yang benar)

if statement (*)

if/else statement (*)

for loop

do while loop

switch statement (*)

Correct

(1/1) Point

50. A String comparison with == compares the Strings’ locations in memory and not the content of the String.

benar (*)

Palsu

Correct

Posting Komentar untuk "JFo Java Foundations Midterm Exam"