Java Unit 3-

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Given the code snippet: String s1 = "Silicon"; String s2 = "Valley"; String s3 = "High"; String s4 = "School"; System.out.println(s1.indexOf('o') + s2.indexOf('a') + s3.indexOf('h') + s4.indexOf('c')); What will be the output of the given code snippet?

10

What is wrong with the Java code snippet below? double mySVHSMethod(){ double mySVHSNumber = 84.1; return mySVHSNumber; }

? There must be a value inside the parenthesis after the method's name. Nothing is wrong with the code.

Given the code snippet below, what will be the output? public static void main(String args[]) { method1(); System.out.println("main"); } public static void method1() { System.out.println("One"); method2(); } public static void method2() { System.out.println("Two"); }

? a. One Two main b. One main Two

What is the correct sequence of the contents of a Java Source File?

The PACKAGE DECLARATION should come first followed by IMPORT STATEMENTS and lastly the CLASS DECLARATIONS

Inside jshell you can also see that java- documentation of a certain class.

True

We can do a lot of commands inside jshell. Which of the following choices cannot be executed inside jshell?

b. compiling your java source code into a byte code

Given the declaration: String s = "java"; How do we get the first character of a String s?

b. s.charAt(0)

As with any application, you need to be sure that _________ is properly installed on your computer.

c. Java

Which of these is a Primitive Data Type?

c. boolean

In Java, the data type float is a Reference Data Type.

False

What is wrong with this line of Java code? double myDouble = 12.34;

There is nothing wrong with the Java code.

Given the Java code snippet of comments: /* // */ Are these legal, when placed inside a Java Code will they compile properly? Answer: True if Yes, or False if No.

True

Given the Java code snippet: public static void main(String[] args){ int num = 12; //num = 20; System.out.println(num); } The output of this code is: 12

True

In the Java code snippet: public static void main(String[] args) { printMe(); } public static void printMe() { System.out.println("Hello Silicon Valley Highschool!"); } The output will be: Hello Silicon Valley Highschool!

True

When creating a method in Java, it must be located within a class but not within an existing method.

True

In the Java code snippet: int myMethod(){ int myNumber = 12; return myNumber; } What is the return type of the method

a. int

Given the Java code snippet: public static void main(String[] args){ int number1 = 24; int number2 = 12; // addNumbers(number1,number2); } static void addNumbers(int num1, int num2){ int sum = num1 + num2; }

d. The code will compile and run properly but with no output.

What is the output of the Java code below? public static void main(String args[]) { helloSVHS(); } static void helloSVHS() { // System.out.print("Hello"); // System.out.print("S"); // System.out.print("V"); // System.out.print("H"); // System.out.print("S"); }

d. The code will run just fine with a blank output

Given the following code snippet: String str1, str2, str3; str1 = "Hello"; str2 = "Goodbye"; Which of the following statements are TRUE? Choose two.

a. There are three String objects declared b. There are two String objects initialized.

What is the purpose of comments in Java?

a. To describe the functions and purpose of the Java code.

If in your jshell you've created several classes, interfaces and enum types, what jshell command should you use to display all classes, interfaces and enum types?

c. /types

In Java, the symbol = is also called:

c. Assignment Operator

What JDK version can jshell run? Choose two.

c. JDK9 d. JDK10

If a method does not return any value, its return type is:

void

What is the notation used for writing a single-line comment?

//

In the Eclipse workspace environment, the Java Source (*.java) files are placed in the /src folder while the compiled codes (*.class) are placed in the /bin folder.

/scr /bin

Given the String declaration: String str = "Java"; What method should we use to print the output: JAVA

? System.out.println(str.toUpperCase()); System.out.println(s.toUpperCase());

What are parameters and arguments?

A way to pass information to your method

Given the Java code snippet: public static void main(String[] args) { System.out.print("Hello Silicon Valley High School!"); // } What would be the appropriate comment or code description after the // symbol?

Displays the text "Hello Silicon Valley High School!"

In Java, all methods must have some sort of parameter established in order to function.

False

In the Java code snippet: public static void main(String[] args) { hello(); hi(); } static void hello() { System.out.println("Hello!"); } static void hi() { System.out.println("Hi!"); } What will be the output?

Hello! Hi!

Given the snippet below, what will happen to the code when compiled and run? public static void main(String[] args) { displayMessage("Hello Silicon Valley Highschool!"); } static void displayMessage(String s) { System.out.println("Hello World!"); }

It will display "Hello World!"

Given the Java code snippet: public static void main(String[] args){ System.out.print("Silicon "); System.out.print("Valley "); System.out.print("High "); System.out.print("School"); } Determine the lines to comment so that the output of the program is: Silicon Valley

System.out.print("School");

Given the snippet below: public static void main(String[] args) { int num = 100; } static void displayMessage(int x) { // put code here; } Which statement below when placed in the // put code here comment will print the value 100?

System.out.println(x);

Given the code snippet: public static void main(String[] args) { displayMessage(); } static void displayMessage(String stringParameter) { System.out.println(stringParameter); } What will happen to the code if it runs?

The code will cause a compilation error.

Which of the following statements is NOT TRUE about comments?

Too much comments on your code slows down the runtime process.

All variables of primitive data types once passed to a method will pass an actual primitive copy of its value.

True

Given the directory structure: \-MyProject | |-\myFolder |-MySource.java |-MyCode.java | --\mySubFolder |-AnotherSourceCode.java |-MySource.java And the code: MySource.java, what should be the package declaration of MySource.java?

a. package myFolder;

Which of these is a group that contains ALL valid Identifiers?

age, lastName, FIRST_NAME

Which of the following options contains an INVALID Java Keyword?

c. instanceOf, synchronize, null

JShell can be launched using your installed IDE.

False

To comment a line of code in Eclipse, the short cut key you can use is:

Ctrl + /

Given the code snippet: public static void main(String args[]) { int x = 10; System.out.println(addTwo(x));}public static int addTwo(int num) { num = num + 2; return num;} What will be the output?

12

Given the code snippet: public static void main(String args[]) { int x = 10; addTwo(x); System.out.println(x); } public static void addTwo(int num) { num = num + 2; }

10

Which of these Data Types is stored in the Heap Memory?

Arrays

What is wrong with the Java code snippet below? /* *A Java Program that displays "Hello Silicon Valley High School!" to the screen *Created by SVHS public static void main(String[] args){ */ System.out.print("Hello Silicon Valley High School!"); }

Declaration of the main method is included within the comment.

>In the Java code snippet: int myMethod(){ int myNumber = 12; System.out.println(myNumber); }

False

A Java program can run without any methods.

False

A method can be inside another method

False

Comments will also be compiled by the compiler, thus affect your Java code.

False

Given the code snippet: public static void main(String args[]) { String str = "Silicon Valley"; System.out.println(doStuff(str)); } public static String doStuff(String s) { s = "High School"; return s; } What will be the output?

High School

Which of the following statements is NOT TRUE?

If the method's return type is an int, the values that you pass to a method's parameter MUST also be an int.

If I were to declare this line of Java code in the main method: int $variable = 21; No errors would appear.

True Rules for creating identifier in Java: Each identifier must have at least one character. The first character must be picked from: alpha, underscore, or dollar sign. The first character can not be a digit. The rest of the characters (besides the first) can be from: alpha, digit, underscore, or dollar sign. In other words, it can be any valid identifier character.

What is the output of the Java code snippet below? public class Example{ public static void main(String[] args){ double tuna;tuna = 5.28; System.out.println("tuna"); } }

Tuna

Which of these is not a type of Java comment?

Virtual Machine Comment

What is the size(in bytes) of an integer value (int)?

b. 4

In the Java code snippet: static void displayMessage(String stringParameter) { System.out.println(stringParameter); } The expected data type of the argument when method displayMessage is invoked is:

b. String

Which of these is not a Primitive Data Type?

b. String

Given the code snippet below: public static void main(String[] args) { displayMessage("Hello Silicon Valley Highschool!"); } static void displayMessage(String s) {// put code here} Which of the following statement should be placed in the comment: // put code here so that the output of the given snippet would be: Hello Silicon Valley Highschool!

b. System.out.println(s);

In the Java code snippet: int numberMethod(int z) { int x = 12; y = 13; return y; } What will happen if this code was placed inside a valid Java class?

b. The code will have a compilation error.

What is the correct syntax to pass in "john" to a method called "setName"?

b. setName("john");

Which operator comes first in operator precedence?

d. ()

Which of the following statements is NOT true?

e. A Java source code should always have the main method in it.

If we were to store a value of 1.12 in a variable named x with a data type of float, which of the following are the correct declaration? Choose two.

float x = 1.12f; float x = 1.12F;

What is the notation used for writing a multiple-line comment?

not- ###

What is wrong with this line of Java code? int your age = 17;

b. whitespace must be removed between your and age. The variable name should have been yourage. -or- c. 17 must be replaced with 17.000.

What symbol do you use to concatenate String values?

+

Give the correct syntax to store the String "I love coding" in a variable called str? Choose two.

Both- a. String str = "I love coding"; b. String str = new String("I love coding");

Which of the following options shows the reason why methods in Java are essential.

To reuse code throughout our program without rewriting it

Java identifiers are case-sensitive.

True

What symbol do you put at the end of a number if you want to assign it to a variable of type long?

L

Given a display() method written using jshell: public void display() { System.out.println("inside the jshell--display method"); } How will I execute the display() method inside jshell so that I can get the output "inside the jshell--display method"?

. display()

A PRIMATIVE DATA TYPE is a data type which is defined by Java itself. It is the most basic of all data types and commonly used values such as numbers, letters, and logic values are assigned to it.

A PRIMATIVE DATA TYPE

A REFREANCE DATA TYPE is a data type which is defined with reference to other data types. They are made by developers to store uncommon types of data. The developer typically imports the corresponding library before they can use the data type.

A REFREANCE DATA TYPE

Constants declared on one part of the programs can be changed or updated on the other parts of the same program.

False

Given the code snippet: String str1 = new String("JAVA"); String str2 = new String("JAVA"); System.out.println(str1 == str2); What will be the output?

False

If I were to assign a value of 32 to variable called age, then the correct way to implement this in Java would be:age integer = 32.000; Select one:

False

The statement: System.out.println("5" + "10"); Will display an output of: 15

False

To check the active Java version, we need to type the command: Java-version in the terminal window (if your using Mac / Unix) or in the command prompt (if your using Windows) of your Operating System.

Java-version

What is wrong with the Java code snippet below? double mySVHSMethod{ double mySVHSNumber = 24.21; return mySVHSNumber; }

Missing '()' after method name mySVHSMethod.

I want to create a Java Code that will display the following text with the following format? SILICON VALLEY HIGH SCHOOL

System.out.println("SILICON\nVALLEY\nHIGH\nSCHOOL");

What is the difference between the four integral data types (byte, short, int and long)?

They occupy different amount of memory space (bit). Which means they have different ranges of values that they can represent.

Aside from Java, REPL is also available in other programming languages like Python.

True

Given a file named "Empty.java", we can compile the file and it will NOT produce a compilation error.

True

f we were to store the letter 'C' in a variable in Java, the correct data type to use would be:

b. char

What is wrong with this line of Java code? int my-Score = 87;

b. my-Score is not a valid Java identifier. We cannot use the minus (-) symbol as a part of the identifier name.

Which of these is not a valid identifier?

basic Pay

In the Java code snippet: public class Example{ public static void main(String args[]){ double tuna; } } What is the value of tuna?

c. None. The variable tuna was not initialized.

In the Java code snippet: int age = 19; String mySchool = "SVHS"; boolean doWeHaveClassesToday = "true"; double my java grade = 1.25; Which of the following variable declaration will cause a compilation error?

double my java grade = 1.25;

Match the correct description for each data type. int: Whole number value, either negative or positive values double: fractional values, with decimal points char: a value inside a single pair of quotes (' ') boolean: either true or false value

int: Whole number value, either negative or positive values double: fractional values, with decimal points char: a value inside a single pair of quotes (' ') boolean: either true or false value

It is a set of code which is referred to by name and can be called (invoked) at any point in a program simply by utilising the method's name. It is sometimes called a sub-routine.

method

Given the Java code snippet: void mySVHSMethod() { int myNumber = 12; System.out.println("Silicon Valley Highschool"); } The correct syntax for calling/invoking this method would be:

? mySVHSMethod(); mySVHSMethod;

Given two Strings: String s1 = new String("Silicon Valley "); String s2 = new String("High School"); Which statement below will produce an output of: Silicon Valley High School Choose three correct answers.

All- System.out.println(s1.concat(s2)); System.out.println(s1 + s2); System.out.println(s1 + "" + s2);

Given the String declarations: String s1 = new String("SVHS"); String s2 = new String("svhs"); Which of the following statements below will give an output of true? Choose two.

Both- a. System.out.println(s1.equals(s2.toUpperCase())); c. System.out.println(s1.equalsIgnoreCase(s2));

What is the output of the Java code snippet below? public class Example{ public static void main(String[] args){ System.out.println("Silicon "); System.out.println("Valley "); System.out.print("High "); System.out.println("School "); } }

Silicon Valley High School

Why do we use constants?

So that we can declare and initialize an identifier that will NOT change its value during a normal program execution.

You just bought a new laptop and you need to set up JDK on your new machine. Give the correct sequence on how to set them up so you can start working. Step1: Download the correct JDK. Step2: Install the JDK on your computer. Step3: Configure the JDK so it runs on your Computer. Step4: Start Coding.

Step1: Download the correct JDK. Step2: Install the JDK on your computer. Step3: Configure the JDK so it runs on your Computer. Step4: Start Coding.

In the import statement, we can use the wildcard symbol -- asterisk (*) to represent all classes inside an imported package.

True

Keywords are predefined, reserved words used in Java programming that have special meanings to the compiler.

True

The underscore (_) can be a part of the literal value in Java. This means that the following code snippets are all legal: int a = 5_2; int b = 5_______2; int c = 0x5_2; long d = 999_99_9999L;

True

The underscore (_) can be a part of the literal value in Java. This means that the following code snippets are all legal: int a = 5_2;int b = 5_______2;int c = 0x5_2;long d = 999_99_9999L;

True

The value of a constant cannot be changed during the execution of a program

True

To display an output, the System.out.println() method is used.

True

Using the compareTo() or the equals() methods are the correct way to compare the equality of the String objects.

True

What makes a double different from an int?

a. A double can have decimals values

What is wrong with this line of Java code? int float = 144;

a. Java keyword float is not a valid identifier.

What is a Java Keyword?

a. Keywords have special meaning to the Java compiler. They help in identifying a data type name or program construct name.

After successfully installing your JDK on your machine, which environment variable do you need to update on your Operating System?

a. Path

Which is the correct way to initialize a double called "number" with a value of 0?

a. double number = 0;

Given the directory structure: \-MyProject | |-\myFolder |-MySource.java |-MyCode.java | --\mySubFolder |-AnotherSourceCode.java |-MySouce.java Which of the following is the fully qualified name of the class AnotherSourceCode.java?

a. myFolder.mySubFolder.AnotherSourceCode

In Java, what are the acceptable coding conventions for packages? Choose two.

a. packages are usually the reverse URL c. packages are written using small letters

Which of the following main method will not cause any compile time or runtime errors? Choose 3.

a. public static void main(String[] args) c. public static void main(String[] argv) f. public static void main(String args[])

In the Java code snippet: int age = 19; Which is the Java keyword?

a. there are no java keywords. or c. int

I have this directory declaration: \-MyProject | |-\myFolder |-MySource.java |-MyCode.java | |--\mySubFolder |-AnotherSourceCode.java In the source code: AnotherSourceCode.java, which of the following import statements, once inserted correctly and separately, can we use in order for it to gain access to both MySource.java and MyCode.java? Choose two.

a.import myFolder.MyCode; import myFolder.MySource; b.import myFolder.*;

Your company's website is: www.xyz.com, and you are creating a payroll application for the company. You are writing a Java Source code that will generate reports. Knowing your company's URL, the name of your application and the importance of packages, which is the best package statement you need to use for the class GenerateReport.java?

b. package com.xyz.payroll;

What are the four (4) Integral Primitive Data Types that can store whole number values of both negative and positive numbers? Select one or more:

c. byte h. int i. long h. short

In jshell, you can declare and create variables, methods and even classes. Which jshell command will allow you to display all the methods declared?

d. /methods

The Java Development Kit, once installed will automatically contain the following EXCEPT?

d. Eclipse IDE

JShell is REPL for Java. REPL stands for?

d. Read-Eval-Print Loo

Which of the following is NOT TRUE about a String?

d. Strings are sequence of characters enclosed in a pair of single quotes (' ').

What can you do to change the order that operations are executed in your code?

d. Use parentheses to force certain parts of the expression to run first

Which is the correct syntax to call a method called "getName()"?

d. getName();

In order for us to write a HelloWorld Program, an IDE (Integrated Development Environment) "must" be installed on your machine aside from your JDK.

False

Methods are subroutines that can be placed anywhere in your Java source code. It can be placed inside or outside the class declaration.

False

The value of variables cannot be changed during the execution of a program

False

Variables CANNOT be used to store and represent String objects.

False

We can reuse and redefine Java keywords. e.g. setting a Java keyword as an Identifier

False

Whitespaces are allowed when creating a Java identifier.

False

Given a line of code: import myFolder.*; Which of the following choices is the same as the given line of code?

d. import myFolder.javaSourceCode1; import myFolder.javaSourceCode2; import myFolder.javaSourceCode3;

What jshell command should we use to display all the executed jshell commands within the current jshell session?

d. /history

What is the maximum value that a short data type can store?

d. 32767

What are the two (2) data types that store fractional values (numbers with decimal values)? Select one or more:

f. double g. float


संबंधित स्टडी सेट्स

Bonds, Loans, and Interest Rates

View Set

Chapter 11- Metal Casting Process

View Set

Suicide & Non-Suicide Self-Injury

View Set

forelimb muscles origin, insertion, action, innervation

View Set

POL 101: Chapter 11: Congress: Balancing National Goals and Local Interests: SmartBook

View Set