CS 1331 Final Exam with precise |!! |!! |!! |!! |!! |!!
detailed solutions |!!
How does OOP model the real world? - correct answer✔✔Classes are the
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
model/blueprint or template from which specific objects are made. |!! |!! |!! |!! |!! |!! |!! |!!
Each class has state (attributes) and behaviors (methods).
|!! |!! |!! |!! |!! |!! |!!
Encpsulation - correct answer✔✔how each object manages its own data by |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
granting and restricting access of its instance variables and its methods
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
to other classes.
|!! |!!
Inheritance - correct answer✔✔Classes form a hierarchy where some |!! |!! |!! |!! |!! |!! |!! |!! |!!
classes inherit information or functionality from parent classes.
|!! |!! |!! |!! |!! |!! |!!
Interpreted vs. Compiled languages - correct answer✔✔Interprets code as |!! |!! |!! |!! |!! |!! |!! |!! |!!
it reads the code. Compiled languages read through the code and compile
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
it before excecuting
|!! |!!
What kind of language is Java? (interpreted or compiled) - correct
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
answer✔✔Java is a mixture of both. The compiler checks mostly for |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
correct syntax to see if the code can run and then compiles the code into
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
byte code. |!!
The byte code goes into the java interpreter in the Java virtual machine
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
where it is interpreted. This is why we can have compile-time errors as
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
well as runtime errors.
|!! |!! |!!
Syntax vs. Semantics - correct answer✔✔Syntax - What is legal in a
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
language (ie grammar and structure). What words and symbols are|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
allowed and how they are allowed to be arranged. |!! |!! |!! |!! |!! |!! |!! |!!
,Semantics - What the statements and symbols mean and do (what
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
happens when you run it). How the language gets interpreted.
|!! |!! |!! |!! |!! |!! |!! |!! |!!
JDK - correct answer✔✔Java Development Kit; compiler + interpreter
|!! |!! |!! |!! |!! |!! |!! |!!
Syntax - correct answer✔✔Grammar or rules; how di I write a valid
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
statement
Semantics - correct answer✔✔The meaning of the statement; ie what does
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
a for loop mean and do in a program when it is run.
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
Source Code - correct answer✔✔The program you write; collection of
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
statements in a file |!! |!! |!!
Byte Code - correct answer✔✔result of compiling source code into portable
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
code for the interpreter (java byte code)
|!! |!! |!! |!! |!! |!! |!!
(Java) Compiler - correct answer✔✔Converts source code into byte code
|!! |!! |!! |!! |!! |!! |!! |!! |!!
IDE - correct answer✔✔Integrated Development Environment
|!! |!! |!! |!! |!!
JDK vs JRE - correct answer✔✔JDK (Java Development Kit) is a set of tools
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
including the JRE used to develop and run apps in Java. The JRE (Java
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
Runtime Environment) is a package used to run apps in java.
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
Inline vs Block comments - correct answer✔✔// makes a line comment
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
/* Block Comment */ are the markers around a block comment.
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
,Can you change a variable type after it is decalred - correct answer✔✔You
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
cannot change the variable type after it is declared.
|!! |!! |!! |!! |!! |!! |!! |!! |!!
What do variables hold in java? - correct answer✔✔They either hold a
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
primitive data type or the location of an object |!! |!! |!! |!! |!! |!! |!! |!!
What does it mean that java is strongly typed? - correct answer✔✔You
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
cannot assign an inappropriate value to a variable
|!! |!! |!! |!! |!! |!! |!!
Primitive types of variables - correct answer✔✔Numbers: |!! |!! |!! |!! |!! |!!
-integers: byte, short, int, long (8, 16, 32, 64 bits respectively) |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
-decimals: float, double (32, 64 bits respectively) |!! |!! |!! |!! |!! |!!
Char: a single character |!! |!! |!!
Boolean: true or false |!! |!! |!!
What are literals in java? - correct answer✔✔Literals are the source code
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
representation of a fixed value. |!! |!! |!! |!!
Ie: int num = 20; char c = "a";
|!! |!! |!! |!! |!! |!! |!! |!!
In this case, 20 is the literal, that represents the value of 20, and "a" is
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
the literal that represents the character a.
|!! |!! |!! |!! |!! |!!
Ascii vs unicode. Which does java use? - correct answer✔✔Java uses ascii.
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
Ascii (8-bit) and unicode (16-bit) are both ways that character values get
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
converted (encoded) into binary for the computer to understand. |!! |!! |!! |!! |!! |!! |!! |!!
Expressions - correct answer✔✔Combination of 1 or more operators and |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
operands.
Ie: 3 + 4 * 5
|!! |!! |!! |!! |!!
, Operators - correct answer✔✔symbols that perform and actions or
|!! |!! |!! |!! |!! |!! |!! |!! |!!
operations and return a result |!! |!! |!! |!!
Operator precedence rules - correct answer✔✔Operators with the same
|!! |!! |!! |!! |!! |!! |!! |!! |!!
precedence next to each other determine order of evaluation by |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
associativity (left to right or right to left) |!! |!! |!! |!! |!! |!! |!!
1. var++ and var-- (postfix)
|!! |!! |!! |!!
2. +, -(unary plus minus ie -5, -num), ++var and --var (Prefix)
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
3. (type)(casting)
|!!
4. !
|!!
5. *,/,%
|!!
6. +, - (Binary addition and subtraction ie: 3 + var)
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
7. <, <=, >, >= (Relational)
|!! |!! |!! |!! |!!
8. ==, != (Equality)
|!! |!! |!!
9. ^(Exclusive OR)
|!! |!!
10. && |!!
11. || |!!
12. ?: (Ternary operator)
|!! |!! |!!
13. =, +=, -=, *=, /=, %= (Assignment operators)
|!! |!! |!! |!! |!! |!! |!! |!!
------------------
1) unary ops (right to left)
|!! |!! |!! |!! |!!
2) */% (left to right)
|!! |!! |!! |!!
3) binary (left to right)
|!! |!! |!! |!!
4) assignment (right to left)
|!! |!! |!! |!!
How are integers divided? - correct answer✔✔It throws away the
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
remainder.
detailed solutions |!!
How does OOP model the real world? - correct answer✔✔Classes are the
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
model/blueprint or template from which specific objects are made. |!! |!! |!! |!! |!! |!! |!! |!!
Each class has state (attributes) and behaviors (methods).
|!! |!! |!! |!! |!! |!! |!!
Encpsulation - correct answer✔✔how each object manages its own data by |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
granting and restricting access of its instance variables and its methods
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
to other classes.
|!! |!!
Inheritance - correct answer✔✔Classes form a hierarchy where some |!! |!! |!! |!! |!! |!! |!! |!! |!!
classes inherit information or functionality from parent classes.
|!! |!! |!! |!! |!! |!! |!!
Interpreted vs. Compiled languages - correct answer✔✔Interprets code as |!! |!! |!! |!! |!! |!! |!! |!! |!!
it reads the code. Compiled languages read through the code and compile
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
it before excecuting
|!! |!!
What kind of language is Java? (interpreted or compiled) - correct
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
answer✔✔Java is a mixture of both. The compiler checks mostly for |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
correct syntax to see if the code can run and then compiles the code into
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
byte code. |!!
The byte code goes into the java interpreter in the Java virtual machine
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
where it is interpreted. This is why we can have compile-time errors as
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
well as runtime errors.
|!! |!! |!!
Syntax vs. Semantics - correct answer✔✔Syntax - What is legal in a
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
language (ie grammar and structure). What words and symbols are|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
allowed and how they are allowed to be arranged. |!! |!! |!! |!! |!! |!! |!! |!!
,Semantics - What the statements and symbols mean and do (what
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
happens when you run it). How the language gets interpreted.
|!! |!! |!! |!! |!! |!! |!! |!! |!!
JDK - correct answer✔✔Java Development Kit; compiler + interpreter
|!! |!! |!! |!! |!! |!! |!! |!!
Syntax - correct answer✔✔Grammar or rules; how di I write a valid
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
statement
Semantics - correct answer✔✔The meaning of the statement; ie what does
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
a for loop mean and do in a program when it is run.
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
Source Code - correct answer✔✔The program you write; collection of
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
statements in a file |!! |!! |!!
Byte Code - correct answer✔✔result of compiling source code into portable
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
code for the interpreter (java byte code)
|!! |!! |!! |!! |!! |!! |!!
(Java) Compiler - correct answer✔✔Converts source code into byte code
|!! |!! |!! |!! |!! |!! |!! |!! |!!
IDE - correct answer✔✔Integrated Development Environment
|!! |!! |!! |!! |!!
JDK vs JRE - correct answer✔✔JDK (Java Development Kit) is a set of tools
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
including the JRE used to develop and run apps in Java. The JRE (Java
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
Runtime Environment) is a package used to run apps in java.
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
Inline vs Block comments - correct answer✔✔// makes a line comment
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
/* Block Comment */ are the markers around a block comment.
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
,Can you change a variable type after it is decalred - correct answer✔✔You
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
cannot change the variable type after it is declared.
|!! |!! |!! |!! |!! |!! |!! |!! |!!
What do variables hold in java? - correct answer✔✔They either hold a
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
primitive data type or the location of an object |!! |!! |!! |!! |!! |!! |!! |!!
What does it mean that java is strongly typed? - correct answer✔✔You
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
cannot assign an inappropriate value to a variable
|!! |!! |!! |!! |!! |!! |!!
Primitive types of variables - correct answer✔✔Numbers: |!! |!! |!! |!! |!! |!!
-integers: byte, short, int, long (8, 16, 32, 64 bits respectively) |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
-decimals: float, double (32, 64 bits respectively) |!! |!! |!! |!! |!! |!!
Char: a single character |!! |!! |!!
Boolean: true or false |!! |!! |!!
What are literals in java? - correct answer✔✔Literals are the source code
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
representation of a fixed value. |!! |!! |!! |!!
Ie: int num = 20; char c = "a";
|!! |!! |!! |!! |!! |!! |!! |!!
In this case, 20 is the literal, that represents the value of 20, and "a" is
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
the literal that represents the character a.
|!! |!! |!! |!! |!! |!!
Ascii vs unicode. Which does java use? - correct answer✔✔Java uses ascii.
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
Ascii (8-bit) and unicode (16-bit) are both ways that character values get
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
converted (encoded) into binary for the computer to understand. |!! |!! |!! |!! |!! |!! |!! |!!
Expressions - correct answer✔✔Combination of 1 or more operators and |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
operands.
Ie: 3 + 4 * 5
|!! |!! |!! |!! |!!
, Operators - correct answer✔✔symbols that perform and actions or
|!! |!! |!! |!! |!! |!! |!! |!! |!!
operations and return a result |!! |!! |!! |!!
Operator precedence rules - correct answer✔✔Operators with the same
|!! |!! |!! |!! |!! |!! |!! |!! |!!
precedence next to each other determine order of evaluation by |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
associativity (left to right or right to left) |!! |!! |!! |!! |!! |!! |!!
1. var++ and var-- (postfix)
|!! |!! |!! |!!
2. +, -(unary plus minus ie -5, -num), ++var and --var (Prefix)
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
3. (type)(casting)
|!!
4. !
|!!
5. *,/,%
|!!
6. +, - (Binary addition and subtraction ie: 3 + var)
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
7. <, <=, >, >= (Relational)
|!! |!! |!! |!! |!!
8. ==, != (Equality)
|!! |!! |!!
9. ^(Exclusive OR)
|!! |!!
10. && |!!
11. || |!!
12. ?: (Ternary operator)
|!! |!! |!!
13. =, +=, -=, *=, /=, %= (Assignment operators)
|!! |!! |!! |!! |!! |!! |!! |!!
------------------
1) unary ops (right to left)
|!! |!! |!! |!! |!!
2) */% (left to right)
|!! |!! |!! |!!
3) binary (left to right)
|!! |!! |!! |!!
4) assignment (right to left)
|!! |!! |!! |!!
How are integers divided? - correct answer✔✔It throws away the
|!! |!! |!! |!! |!! |!! |!! |!! |!! |!!
remainder.