Module 1 (Prelim) Flashcards
1.1 Overview 1.2 Comparing Procedural and Object Oriented Programming Concepts 1.3 Creating Java 1.4 Using Data 1.5 Arithmetic Operators 1.6 Understanding Type Conversion
Sets of operations executed in sequence
Procedural programming
Named computer memory locations that hold values
Variables
Two popular approaches to writing computer programs are
- procedural programming
- object-oriented programming
Individual operations grouped into logical units
Procedures
is an extension of procedural programming in which you take a slightly different approach to writing computer programs.
Object-Oriented Programming
Writing object-oriented programs involves: (3)
- Creating classes, which are blueprints for objects
- Creating objects, which are specific instances of those classes
- Creating applications that manipulate or use those objects
Understanding object-oriented programming requires grasping three basic concepts:
- Encapsulation as it applies to classes as objects
- Inheritance
- Polymorphism
- Abstraction (just in case)
a term that describes a group or collection of objects with common properties.
Class
describes what attributes its objects will have and what those objects will be able to do.
class definition
are the characteristics that define an object; they are PROPERTIES of the object.
Attributes
An ___________ is a specific, concrete INSTANCE of a class.
object
Creating an instance is called _______
instantiation
is a set of written instructions that tells the computer what to do
Computer Program
Machine language is a ___________ programming language
low-level
allows you to use a vocabulary of reasonable terms
high-level programming language
set of rules for the language
syntax
translates language statements into machine code
compiler/interpreter
misuse / misspelled programming language
syntax error
freeing program from errors
debugging
Understanding Classes, Objects, and Encapsulation:
Which stands for class, object, and properties for the example below?
Dog:
Breed:
Gender and age:
Dog: class
Breed: object
Gender and age: properties
The values of the properties of an object are referred to as the object’s ___________
state
Besides defining properties, classes define ___________ their objects can use.
methods
is a self-contained block of program code that carries out some action, similar to a procedure in a procedural program.
method
if objects are similar to nouns, then methods are similar to verbs. (True or False)
T
In object-oriented classes, attributes and methods are encapsulated into _________
A) class
B) objects
C) properties
B) objects
Encapsulation refers to two closely related object-oriented notions:
- Encapsulation is the enclosure of data and methods within an object.
- Encapsulation also refers to the concealment of an object’s data and methods from outside sources.
is the enclosure of data and methods within an object.
Encapsulation
allows you to treat all of an object’s methods and data as a single entity. Just as an actual dog contains all of its attributes and abilities, so would a program’s Dog object.
Encapsulation
also refers to the concealment of an object’s data and methods from outside sources.
Encapsulation
lets you hide specific object attributes and methods from outside sources and provides the security that keeps data and methods safe from inadvertent changes.
Encapsulation
Concealing data is sometimes called _________, and concealing how methods work is _________
- information hiding
- implementation hiding.
the ability to create classes that share the attributes and methods of existing classes, but with more specific features.
inheritance
means “many forms”—it describes the feature of languages that allows the same word or symbol to be interpreted correctly in different situations based on the context.
polymorphism
In a GUI application, it is convenient to remember one method name, such as _________or _________, and have it work correctly no matter what type of object you are modifying.
setColor
setHeight
Define a Java class using any name or _________
identifier
Requirements for identifiers: (5)
- Must begin with one of the following:
* Letter of the English alphabet
* Non-English letter (such as α or π)
* Underscore
* Dollar sign - Cannot begin with a digit
Identifiers can only contain: (4)
Letters
Digits
Underscores
Dollar signs
Single-line comments in Java ________
A) starts with //
B) starts with /* and ends with */
C) starts with #
D) starts with // and ends with //
A) starts with //
Multi-line comments in Java ________
A) starts with //
B) starts with /* and ends with */
C) starts with #
D) starts with // and ends with //
B) starts with /* and ends with */
Identifiers can be a Java reserved keyword
(True or False)
F
Cannot be a Java reserved keyword
The line “public class ClassName” is the __________ in the program structure below:
public class ClassName
{
public static void main(String[] args)
{
Statement(s);
}
}
A) class definition/ class header
B) main method header
C) body of the main method
D) access specifier
E) keyword that defines ClassName as class
F) name of the class
A) class definition/ class header
The line “ public static void main(String[] args) “ is the __________ in the program structure below:
public class ClassName
{
public static void main(String[] args)
{
Statement(s);
}
}
A) class definition/ class header
B) main method header
C) body of the main method
D) access specifier
E) keyword that defines ClassName as class
F) name of the class
B) main method header
The line “ Statement(s); “ is the __________ in the program structure below:
public class ClassName
{
public static void main(String[] args)
{
Statement(s);
}
}
A) class definition/ class header
B) main method header
C) body of the main method
D) access specifier
E) keyword that defines ClassName as class
F) name of the class
C) body of the main method
defines the circumstances under which a class can be accessed and the other classes that have the right to use a class.
access specifier
is the most liberal type of access specifier.
Public access
The term “public” in “public class ClassName” is the __________ in the program structure below:
public class ClassName
{
public static void main(String[] args)
{
Statement(s);
}
}
A) class definition/ class header
B) main method header
C) body of the main method
D) access specifier
E) keyword that defines ClassName as class
F) name of the class
D) access specifier
The term “class” in “public class ClassName” is the __________ in the program structure below:
public class ClassName
{
public static void main(String[] args)
{
Statement(s);
}
}
A) class definition/ class header
B) main method header
C) body of the main method
D) access specifier
E) keyword that defines ClassName as class
F) name of the class
E) keyword that defines ClassName as class
The term “ClassName” in “public class ClassName” is the __________ in the program structure below:
public class ClassName
{
public static void main(String[] args)
{
Statement(s);
}
}
A) class definition/ class header
B) main method header
C) body of the main method
D) access specifier
E) keyword that defines ClassName as class
F) name of the class
F) name of the class
static is a reserved keyword (True of False)
T
Means the method is accessible and usable even though no objects of the class exist
static
void is used in the class header
(True of False)
F
void is used in the main() main method header
Does not indicate the main() method is empty
void
Indicates the main() method does not return a value when called
void
Does not mean that main() doesn’t produce output
void
The “First Java Application” in “System.out.println(“First Java Application”);” is the __________ in the program structure below:
public class ClassName
{
public static void main(String[] args)
{
System.out.println(“First Java Application”);
}
}
A) property of System class
B) class
C) literal string that is the argument to the method
D) method
C) literal string that is the argument to the method
Method names are always followed by:
A) ()
B) []
C) “”
A) ()
Every java statements ends with a ______
;
semi-colon
The term “System” in “System.out.println(“First Java Application”);” is the __________ in the program structure below:
public class ClassName
{
public static void main(String[] args)
{
System.out.println(“First Java Application”);
}
}
A) property of System class
B) class
C) literal string that is the argument to the method
D) method
B) class
The term “out” in “System.out.println(“First Java Application”);” is the __________ in the program structure below:
public class ClassName
{
public static void main(String[] args)
{
System.out.println(“First Java Application”);
}
}
A) property of System class
B) class
C) literal string that is the argument to the method
D) method
A) property of System class
The term “println” in “System.out.println(“First Java Application”);” is the __________ in the program structure below:
public class ClassName
{
public static void main(String[] args)
{
System.out.println(“First Java Application”);
}
}
A) property of System class
B) class
C) literal string that is the argument to the method
D) method
D) method
Save the java class in a file with exactly the same name and __________ extension
.java
Compiling a Java Class: (3)
- Compile the source code into bytecode
- Translate the bytecode into executable statements using a Java interpreter
- Type javac First.java
To run a java application from the command line, type __________
java FileName
when its value cannot be changed while a program is running.
constant
How to declare named constant:
final datatype NAME = value;
- is a named memory location
- Used to store a value
- Can hold only one value at a time
- Its value can change
Variable
How to declare a variable:
datatype varName = value;
What is the correct order of the java primitive data types:
short
char
long
float
byte
boolean
int
double
byte
short
int
long
float
double
char
boolean
Boolean values:
True or False
Which among these java primitive data types belongs to the integer data types:
byte
short
int
long
float
double
char
boolean
byte
short
int
long
What are the boolean data types: (6)
<
>
==
<=
>=
!=
Is a data type that holds any single character
char
are written between double quotation marks
String constants
- A built-in class
- Stores and manipulates character strings
String
Constant character values are placed within ________ quotation marks
single
Begins with a backslash followed by a character and represents a single nonprinting character
Escape sequence
Escape sequences: (7)
\b
\t
\n
\r
"
'
\
also called semantic errors
logical errors
Scanner class makes System.in more flexible (True or False)
T
Import statement for the Scanner class:
import java.util.Scanner;
or
import java.util.*;
How to create a Scanner object:
Scanner inputDevice = new Scanner(System.in);
Scanner breaks input into units called _______; a set of characters that is separated from the next set by whitespace.
tokens
Scanner class methods: (8)
nextDouble()
nextInt()
nextLine()
next()
nextShort()
nextByte()
nextFloat()
nextLong()
Arithmetic Operators: (5)
*
/
%
Two types of division:
Integer division
Floating-point division
Involves when either or both of the operands are floating-point values. The result is double.
A) Integer division
B) Division
C) Floating-point division
C) Floating-point division
Involves integer constants or integer variables. The result is an integer and any fractional part of the result is lost.
A) Integer division
B) Division
C) Floating-point division
A) Integer division
The _______ of an operator controls the order of evaluation of expressions involving the same operator, for example: 3 / 4 / 5
associativity
Associativity can be:
- left-to-right: the leftmost operator is applied first.
- Right-to-left: the rightmost operator is applied first.
A high precedence means an operator is evaluated (applied) before any lower precedence operators. (True or False)
T
Which among the choices are of higher precedence in java?
A) + -
B) * /
C) %
D) * / %
D) * / %
Which among the choices are of lower precedence in java?
A) + -
B) * /
C) %
D) * / %
A) + -
The type to which all operands in an expression are converted for compatibility
Unifying type
Order for establishing unifying types between two variables (highest to lowest):
long
double
int
float
double
float
long
int
Forces a value of one data type to be used as a value of another data type
Type casting
Using a cast operator is an _______
explicit conversion
Place desired result type in parentheses
Cast operator
allows programmers to write instructions in a language that is easier to understand than low-level languages.
High-level Programming Language
corresponds closely to a computer processor’s circuitry (0s and 1s) are used to write programs that relate to the specific architecture and hardware of a particular type of computer.
Low-level Programming Language
The program may run but provide inaccurate output
Logic errors