Java Programming Fundamentals, Exams of Java Programming

The basic concepts and principles of java programming, including data types, variables, operators, control structures, and input/output. It provides an overview of the java programming language, explaining how java programs are structured, how to declare and use variables, how to perform arithmetic and logical operations, and how to control the flow of execution using conditional statements and loops. The document also introduces the concept of methods and discusses how to create and call them. Additionally, it covers the basics of input/output in java, including how to read user input and display output to the console. This document serves as a comprehensive introduction to the fundamental building blocks of java programming and would be useful for students learning java for the first time or as a refresher for those already familiar with the language.

Typology: Exams

2023/2024

Available from 08/03/2024

Classrep02
Classrep02 🇺🇸

3

(2)

2.9K documents

1 / 19

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Starting out with Java Exam 1 (ch. 1 - 4) 100%
Solved!!
0.0 - ANSWERWhat would be the value of discountRate after the following statements are executed?
double discountRate = 0.00;
int purchase = 100;
if( purchase > 1000 )
discountRate = .05;
else if ( purchase > 750 )
discountRate = .03;
else if ( purchase > 500 )
discountRate = .01;
.01
.05
0.0
.03
Read and interpreted by the JVM - ANSWERByte code instructions are:
Syntax errors
Another name for source code
Machine code instructions
Read and interpreted by the JVM
Correct A logical error - ANSWERA runtime error is usually the result of:
A compilation error
Bad data
A logical error
A syntax error
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download Java Programming Fundamentals and more Exams Java Programming in PDF only on Docsity!

Starting out with Java Exam 1 (ch. 1 - 4) 100%

Solved!!

0.0 - ANSWERWhat would be the value of discountRate after the following statements are executed? double discountRate = 0.00; int purchase = 100; if( purchase > 1000 ) discountRate = .05; else if ( purchase > 750 ) discountRate = .03; else if ( purchase > 500 ) discountRate = .01; . .

. Read and interpreted by the JVM - ANSWERByte code instructions are: Syntax errors Another name for source code Machine code instructions Read and interpreted by the JVM Correct A logical error - ANSWERA runtime error is usually the result of: A compilation error Bad data A logical error A syntax error

All of these - ANSWERWhich of the following professions use the computer as a tool? Accountants Engineers Mechanics Nurses All of these A set of instructions that enable the computer to solve a problem or perform a task - ANSWERA computer program is: A. Main memory B. Pseudocode C. A flow chart D. A set of instructions that enable the computer to solve a problem or perform a task Words that have a special meaning in the programming language - ANSWERKey words are: A. The data names in your program B. Words that have a special meaning in the programming language C. Symbols or words that perform operations on one or more operands D. Words or names defined by the programmer True - ANSWERApplication software refers to programs that make the computer useful to the user. True False / comment 3 / - ANSWERWhich of the following is NOT a valid comment statement? /* comment 4 / / comment 2 */ // comment 1 */ comment 3 / The memory address where "John Doe" is located - ANSWERIn the following Java statement what value is stored in the variable name?

Symbolic names made up by the programmer that represents locations in the computer's RAM - ANSWERVariables are: A. Operators that perform operations on one or more operands B. Symbolic names made up by the programmer that represents locations in the computer's RAM C. Symbolic names made up by the programmer whose values cannot be changed D. Reserved words All these are parts of the programming process. - ANSWERWhich of the following is NOT part of the programming process? Design Testing Debugging All these are parts of the programming process. variable - ANSWERThe primitive data types only allow a(n) ________ to hold a single value. literal variable object class Multi-line comments, start with / and end with / - ANSWERWhich of the following does not describe a valid comment in Java? A. Single line comments, two forward slashes - // B. Multi-line comments, start with / and end with / C. Multi-line comments, start with /* and end with / D. Documentation comments, any comments starting with /* and ending with */ 7 - ANSWERWhat is the result of the following expression?

Scanner keyboard = new Scanner(System.in); - ANSWERWhich of the following statements correctly creates a Scanner object for keyboard input? Scanner keyboard(System.in); Keyboard scanner = new Keyboard(System.in); Scanner keyboard = new Scanner(System.in); Scanner kbd = new Scanner(System.keyboard); data type - ANSWERVariables are classified according to their: value data type location in the program names True - ANSWERA variable's scope is the part of the program that has access to the variable. True False x = 1,000; - ANSWERIf x has been declared an int, which of the following statements is invalid? x = 592; x = -58932; x = 0; x = 1,000;

I am enjoying this class. I AM ENJOYING THIS CLASS. i am enjoying this class. Character at index x = e msg has 24 characters. B. I am enjoying this class. I AM ENJOYING THIS CLASS. i am enjoying this class. Character at index x = n msg has 24 characters. C. I am enjoying this class. I AM ENJOYING THIS CLASS. i am enjoying this class. Character at index x = e msg has 25 characters. D. I am enjoying this class. I AM ENJOYING THIS CLASS. i am enjoying this class. Character at index x = n msg has 25characters. Nothing, this is an error. - ANSWERWhat will be displayed as a result of executing the following code? public class test { public static void main( String[] args ) { int value1 = 9;

System.out.println( value1 ); int value2 = 45; System.out.println( value2 ); System.out.println( value3 ); value = 16; } } 9 45 16 94516 9 45 16 Nothing, this is an error. Demo.class - ANSWERWhich one of the following would contain the translated Java byte code for a program named Demo? Demo.code Demo.class Demo.java Demo.byte 7 - ANSWERWhat is the result of the following expression? 17 % 3 * 2 - 12 + 15 7 105 12 8 String concatenation operator - ANSWERWhen the + operator is used with strings, it is known as the:

comments False - ANSWERJava is a case-insensitive language. True False Variable - ANSWERThis is a named storage location in the computer's memory. Variable Literal Operator Constant javac First.java - ANSWERTo compile a program named First, use the following command: java First.java compile First.javac javac First javac First.java literal - ANSWERThis is a value that is written into the code of a program. operator assignment statement variable literal named constant - ANSWERThis is a variable whose content is read only and cannot be changed during the program's execution. reserved word literal named constant

operator if (chr == 'a') - ANSWERIf chr is a character variable, which of the following if statements is written correctly? if (chr == "a") if (chr = "a") if (chr = 'a') if (chr == 'a') True - ANSWERThe System.out.printf method formats a string and displays it in the console window. True False 1000 - ANSWERWhat would be the value of bonus after the following statements are executed? int bonus, sales = 85000; char dept = 'S'; if( sales > 100000 ) if( dept == 'R' ) bonus = 2000; else bonus = 1500; else if( sales > 75000 ) if( dept == 'R' ) bonus = 1250; else bonus = 1000; else bonus = 0; 1500

True False 2 and 3 - ANSWERIf str1 and str2 are both Strings, which of the following expressions will correctly determine whether they are equal? (1)(str1 == str2) (2) str1.equals(str2) (3)(str1.compareTo(str2) == 0) 1 and 3 1, 2, and 3 will all work 1 and 2 2 and 3 (str1.equalsIgnoreCase(str2)) and (str1.compareToIgnoreCase(str2) == 0) - ANSWERTo do a case insensitive compare which of the following could be used to test the equality of two strings, str1 and str2? A. (str1.equalsIgnoreCase(str2)) B. (str1.compareToIgnoreCase(str2) == 0) C. Only (str1.equalsIgnoreCase(str2)) D. (str1.equalsIgnoreCase(str2)) and (str1.compareToIgnoreCase(str2) == 0) Binary - ANSWERThese operators use two operands: Unary Binary Tertiary None of these

(( x > 500 && x < 650 ) || ( y != 1000 )) - ANSWERWhich of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000? (( x > 500 AND x < 650) OR !( y.equal(1000)) (( x < 500 && x > 650 ) || !( y == 1000 )) (( x > 500 && x < 650 ) || ( y != 1000 )) (( x >= 500 && x <= 650 ) && ( y != 1000 )) 165 - ANSWERWhat is the value of x after the following code has been executed? int x = 75; int y = 90; if( x != y ) x += y; 90 15 165 75 Multiple alternative decision structure - ANSWERThe switch statement is a: Sequence structure Nested decision structure Multiple alternative decision structure Test expression No value, this is a syntax error. - ANSWERWhat is the value of ans after the following code has been executed? int x = 40; int y = 40; int ans = 0; if( x == y )

45,678.26 - ANSWERWhat will be printed when the following code is executed? double x = 45678.259; System.out.printf("%,.2f", x);

0,045,678. 45,678. 45,678. true or false - ANSWERA flag may have the values: 0 or 1 true or false of any character +1 or - != - ANSWERWhich one of the following is the not equal operator? <> *& NOT != 3 - ANSWERIf str1 and str2 are both Strings, which of the following will correctly test to determine whether str1 is less than str2?

(1) (str1 < str2) (2) (str1.equals(str2) < 0) (3) (str1.compareTo(str2) < 0) 2 2 and 3 1, 2, and 3 will all work 3 .04 - ANSWERWhat would be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 1250; char cust = 'N'; if( purchase > 1000 ) if( cust == 'Y' ) discountRate = .05; else discountRate = .04; else if( purchase > 750 ) if( cust == 'Y' ) discountRate = .04; else discountRate = .03; else discountRate = 0; . .

x = 20 x is unknown when the last statement is executed. 15 - ANSWERWhat will be the value of x after the following code is executed? int x = 75; int y = 60; if (x > y) x = x - y; 15 135 60 75