CSCI 111 Ch. 1-2 Quiz Flashcards
a number system consists of (2 things)
- set of valid characters
2. place values
the base-10 number system is also known as
decimal
what are the valid characters in the base-10/decimal number system?
0-9
in the base-10/decimal number system, place values increase by orders of
10 (10^0, 10^1, 10^2 and so on in the left direction)
Why do we use base 2 (binary) instead of base 10 (decimal)? What does this mean?
Electrostatic Discharge (if electronics are exposed to ESD, voltage can spike -> in base 10, 1v to 8v is a jump of 8000)
the base-2 number system is also known as
binary
what are the valid characters in the binary number system?
0 and 1
in the base-2/binary number system, place values increase by orders of
2 (2^0, 2^1, 2^2 and so on in the left direction)
what is 1 byte equal to (in terms of bits)?
8 bits
what is 1 word equal to (in terms of bytes)?
2 bytes
what are the steps for converting from decimal to binary?
- identify the largest place value that is less than or equal to your number
- set the bit to 1 for that place value
- subtract the place value from your number
- repeat steps 1-3 until the number is zero
- set the remaining bits to zero
the base-16 number system is also known as
hexadecimal
what are the valid characters in the hexadecimal number system?
0-9, A-F
in the base-16/hexadecimal number system, place values increase by orders of
16 (16^0, 16^1, 16^2 and so on in the left direction)
in converting hexadecimal to binary, we have to look at it in terms of ? bits because 16 = 2^4
4
what are the place values for the binary > hexadecimal conversion chart?
8 4 2 1
Java is an ? and ? language that uses an ? / text editor such as Notepad ++
object oriented (OO), compiled, Integrated Development Environment (IDE)
what is the basic skeleton of a java code?
class name & main method
to invoke the java compiler, ? which creates MyProgram.class
javac MyProgram.java
to execute the program, ?
java MyProgram
what are computer programs (aka software)?
instructions to the computer/how we tell the computer what to do
programs are written using ?
programming languages (e.g. Java)
? is a set of primitive instructions built into every computer. it is in the form of ?
machine language; binary code
? were developed to make programming easy
assembly languages
a program called an ? is used to convert assembly language programs into machine code
assembler
? are English-like and easy to learn and program (e.g. Java, Python)
high-level languages
a program written in a high-level language is called a ?, which must be translated into ? for execution
source code; machine code
the translation from source to machine code can be done using an ? or a ?
interpreter, compiler
an interpreter reads ? from the source code, translates it to the machine code, and then executes it right away
one statement
a compiler translates ? into a machine-code file, and the machine-code file is then executed
the entire source code
? is a powerful and versatile programming language that enables users to develop and deploy applications on the Internet for servers, desktop computers, and mobile devices
Java
the ? converts the source code to bytecode (JVM - Java Virtual Machine) and then the Java ? converts and executes the byte code line by line
compiler; interpreter
every Java program must have at least one ?, which has a name that conventionally starts with an ? letter
class; uppercase
capitalize the first letter of each word in the ? name
class
in order to run a class, the class must contain a method named ?, which looks like ?. it is where the program begins execution
main; public static void main (String [ ] args)
a ? represents an action or a sequence of actions
statement
every statement in Java ends with a ?, which is known as the ? in Java
semicolon (;), statement terminator
? (also known as keywords) are words that have a specific meaning to the compiler and cannot be used for other purposed in the program
reserved words
a ? is a group of statements/components surrounded by braces { }
block
two popular block styles
next-line and end-of-line
{ }
denotes a block to enclose statements
( )
used with selection statements, loops, and methods
[ ]
denotes an array
//
precedes a comment line
” “
enclosing a string
’ ‘
enclosing a character
;
marks the end of a statement
proper indenation
at least two spaces
use a ? to separate segments of the code
blank line
syntax/compile error
detected by the compiler
runtime
causes the program to abort
logic
produces incorrect result
how to read input from the console
- create a scanner object Scanner input = new Scanner(System.in);
- use the method nextDouble( ) to obtain a double value
an identifier is a sequence of characters that consist of ?, ?, ? and ?
letters, digits, underscores, and dollar signs
an identifier must start with a ?, ?, or ? - it CANNOT start with a ?
letter, underscore, or dollar sign; digit
an identifier cannot be a ? and cannot be ?, ?, or ?
reserved word; true false, or null
variables and constants are examples of ?
identifiers
a ? represents a value stores in the computer’s memory. the value of it is changeable
variable
ex: declaring a variable
int x;
double radius;
char a;
ex: assigning values to a variable
x = 1; radius = 1.0; letter = 'A';
ex: declaring and variable AND assigning value in one step
int x = 1;
double radius = 1.0;
char a = ‘A’;
an ? designates a value for a variable and an ? is known as the assignment operator
assignment statement; equal sign =
a ? is an identifier that represents a permanent value
constant
general form of declaring constants
final datatype CONSTANTNAME = value;
in variable and method names, use ?. if the name consists of several words, concatenate all in one, using ? for the first word and ? the first letter of each subsequent word in the name
lowercase; lowercase, capitalize
in naming constants, ? all letters and use ? to connect words
capitalize; underscores
what are the 8 primitive data types? (which are the two we mainly use?)
byte short int long float double char boolean (we mainly use int and byte)
numeric operators
\+ addition - subtraction * multiplication / division % modulus (remainder)
calculations with integers yield a precise integer result (ex: 5/2 yields ? while 5.0/2 yields ?)
2; 2.5
you can use % to determine if a number is even or odd because an even number % 2 = ? and an odd number % 2 = ?
even % 2 = 0
odd % 2 = 1
a ? is a value that appears directly in the program (also referred to as ?)
literal; hard coding
an ? can be assigned to an integer variable as long as it can fit into the variable. a compilation error would occur if the literal were to large for the variable to hold
integer literal
an integer literal is assumed to be of the ? type, whose value is between -2^31 and 2^31-1
int
? literals are written with a decimal point. by default, a floating-point literal is treated as a ? type value
floating-point; double
the ? type values are more accurate than the float type values
double
operator precedence
( ) first, then *, /, % are applied, and then +, - (if multiple, go L to R)
augmented/compound assignment operators
\+= addition assignment -= subtraction assignment *= multiplication assignment /= division assignment %= modulus/remainder assignment
increment and decrement operators
++var preincrement
var++ postincrement
–var predecrement
var– postdecrement
when performing a binary operation involving two operands of different types, Java automatically converts the operand based on these rules:
- if one of the operands is double, the other is converted into double
- if one of the operands is float, the other is converted into float
- if one of the operands is long, the other is converted into long
- otherwise, both operands are converted into int
two types of type casting with examples
implicit: double d = 3; (type widening)
explicit: int i = (int)3.0; (type narrowing)
int i = (int)3.9; (fraction part is truncated)
common errors and pitfalls
error 1. undeclared/uninitialized variables and unused variables error 2. integer overflow error 3. round-off errors error 4. unintended integer division pitfall 1. redundant input objects
ASCII characters to know: A, a, space, carriage return, tab
A: 65 a: 97 space: 32 carriage return: 13 tab: 9
ASCII is an ?-bit calculation
8-bit
Unicode Text Format (UTF) has two bytes per character, but the first ? characters are ASCII
128 char
what is ASCII?
American standard code for information interchange (that crazy chart in your notes)