1/62
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
CPU
central processing unit
process a programs instructions
cam only process very simple instructions
Main Memory
working memory used to store current program, data the program is using, results of intermediate calulations
RAM (random access memory)
Auxiliary Memory
aka secondary memory
HHD, SSD, CD, DVD, Blu-Ray, USB
nonvolatile memory
Program
a finite sequence of instructions for a computer to follow written in a programming language
Operating System
OS
a supervisory program that oversees the operation of the computer
the main job of an OS is to manage process and hardware resources
eg retrieving and starting a program for you and manages resources like memory
Windows Commands
interact with the Windows OS via Command Prompt
Commons commands: dir, cd, cls, mkdir, tree, exit
Compile a Java File
javac MyProgram.java
Run a Java File
java MyProgram
Compiler
translates a program from a high level langauge to a low level language the computer can run
you enter source code into a compiler
compilers produce machine or assembly language programs called object programs
most high level languages need a different compiler for each type of computer and operating system
translates the entire source code into machine code before execution
Java Byte Code
the java compiler doesn’t translate a Java program into assembly language or machine language for a particular computer
instead, it translates a Java prpgram into byte-code
byte-code is the machine language for a hypothetical computer (or interpreter) called the Java Virtual Machine
a byte-code program is easy to translate into machine language for any particular computer
after compile a Java program into byte-code, tat byte-code can be used on any computer with a byte-code interpreter and without a need to recompile
Interpreter
translates source code into machine code line by line during runtime
Package
a library of classes that have been defined already
IDE
intregrated development environment
combines a text editor with commands for compiling and running Java programs
3 features of eclipse: tells you where errors are, control f (find), convenient project management
Object-oriented programming (OOP)
our world consists of objects (people, trees, cars, etc)
objects can perform actions which affect themselves and other objects in the world
Object-oriented programming (OOP) treats a program as a colleciton of objects that intereact by means of actions
objects are called objects
actions are called methods
objects of the same kind have the same type and are objects of the same class
objects of the same class have a common set of methods and same the kinds of data but each object can have its own data values
classes reflect concepts, objects refelct instances that embody those concepts
Algorithm
finite sequence of instructions for solving a problem or performing some task
Types of Errors
syntax error
runtime error
logic error
Syntax Errors
grammatical mistakes in a program
ex. not ending a statement with a semicolon
Runtime Errors
errors that are detected when your program is running, but not during compilation
ex. attempting to divide by 0
Logic/Semantic Errors
errors that are not detected during compilation or while running, but which cause the program to produce incorrect results
Variables
stores data
value can be changed
int styleChoice, numberOfChecks
double balance, interestRate
char jointOrIndividual
Data Types
Primitive Type
byte, short, int, long, float, double, char, boolean
Class/Object Type
String
Java Identifier
an identifer is a name, such as the name of variable
indentifiers may contain only: letters digits 0-9, the underscore character, the dollar sign symbol (we don’t use in the class)
first character cannot be a digit
can’t contain spaces, dots, astericks, or other characters
if-else statement
Tautology
a boolean expression is a tautology if and only if it is always true regardless of the values of its variables
Contradiction
a boolean expression is a contradiction if and only if it is always false regardless of the values of its variables
Contingency
a boolean expression that is neither a tautology nor a contradiction is called contingency
==
use for determining if two ints (or any primitive integer types), booleans, or chars have the same value
don’t use for floating points
don’t use for objects
compareTo()
returns 0 if both are equal
returns -1 if the first is lexigraphically greater than the second
returns 1 if the first is lexigraphically lesser than the second
Ternary Operator/Conditional Operator
useful with print and println statements
A program can be terminated normally by
System.exit(0);
Enumerations
consider a need to restrict contents of a variable to certain values
an enumeration lists the values a variable can have
The while Statement
The do-while Statement
The for Statement
The for-each Statement
Sentinel Value
for large input lists, a sentinel value can be used to signal the end of the list
ex. a negative number following a long list of nonnegative exam scores
The break Statement
can be used to end a loop immediately
the break statement end only the innermost loop or switch statement that contains the break statement
we will not be using break statements in loops in this class
The continue Statement
ends current loop iteration
begins the next one
we will not be using continue statements in loops in this class
Data Structures
a particular way of storing and organizing data in a computer so it can be used effectively
ex. array
Arrays
an array is a special kind of Java object
It is a collection of variables of the same type
fized size
double[] temperature = new double [7];
new Operator
the new operator allocates memory for an object like an array on the program’s heap (as opposed the program’s stack)
Creating Arrays
type[] name;
name = new type[]{value1, value2, value3, …};
type[] name = {value1, value2, value3, …};
type[] name = new type[num];
Class definition
Constructor
a constructor is a special method that intilizes objects of a class
it shares the same name as the class and lacks a return type
Instance Variable
a variable declared within class, but outside of any specific method or constructor
static
signifies that a variable or method is associated with the class itself, rather than with any specific instance
static variables are shared by all objects of a class
static variables are also called class variables
static varaibles belong to the class not to an individual object
a single copy shared by all instances of the class
final
ensures variables cannot be changed
methods cannot be overridden by subclasses
classes cannot be subclassed
The Keyword this
inside the class the unnamed object can be referred to with the name this
the keyword this stands for the current instance of the object
it can be used to call methods or access instance variables in this object
Information Hiding
programmer using a class method need not know details of implementation
designing a method so it can be used without knowing details
also refered to as abstraction
Pre- and Postcondition Comments
Precondition Comment:
states condtion that must be true before method is invoked
Postcondition Comment:
tells what will be true after method execution
public and private modifiers
public:
any other class can directly access that object by name
classes generally specified as public
instance variables usually not public
Encapsulation
consider example of driving a car:
we see and use the break pedal, accelerator pedal, and steering wheel - know what they di
we do not see mechanical details of how they do their jobs
Encapsulation divides class definition into:
class interface (tells what the class does, gives headings for public methods)
class implementation (contains private variables, includes definitions and bodies of public and private methods)
A well encapsulated class:
all classes, methods, instance variables, class variables, and significant portions of code are commenyed in plain, easy to understand, english
well named variables and indentifiers
UML Class Diagrams
contains an outline of a class
Primitive type vs class type variables
Value of primitive type stored in the memory location assigned to the variable
Variable of class type contains memory address (references) of object named by the variable
null
null is a special predefined constant that represents a memory address that does not point anywhere
Math.random()
returns a pseudorandom double that is greater than or equal to 0 and less than 1
6 sided die:
int die = (int) (6.0 * Math.random()) + 1;
Wrapper Classes
allows programmer to have an object that corresponds to value of primitive type
contain useful predefined constants and methods
ex. toUpperCase
Overloading Basics
when two or more methods have the same name within the same class
Java distinguishes the methods by number and types or parameters
a method’s name and number and type of parameters is called its signature
if it cannot match a call with a defintion, then it will attempt a type conversion
you must not overload a method where the only difference is the type of value returned
Create 2d Array
Bubble Sort
comparing and/or swapping each element until it is sorted
Selection Sort
look for smallest value, place it at the first index, then find the smallest value from the second spot to the end of the list, and place it at the second spot, continue to sorted
Insertion Sort