Java Terms

Ace your homework & exams now with Quizwiz!

Queue

* A linear collection * Data-item insertions are made at one end (the queue's rear) and data-item retrievals/deletions are made at the other end *FIFO * insert = storing a data item in a queue * isEmpty = determining if a queue is empty * isFull = determining if a queue is full *remove = retrieving/deleting a data item from a queue

private scope

* Methods and variables are accessible only from within the class in which they are defined * Not inherited by subclasses

DOUBLE data type

* afloat represented internally as eight bytes

FLOAT data type

* represents numbers with a fractional component * represented internally as four bytes * default number of digits of precision after decimal point: * may instruct program to increase precision using % * initialize with an f * i.e.float length = 3.9f

constants

* values that will not change throughout program execution * Typed in all caps for readability and maintainability

extends

* when a class extends another class, it inherits the behavior of that class * can use the methods of the super class as it's own

Stack

*A linear collection * Data-item insertions and retrievals/deletions are made at one end, which is known as the top of the stack * LIFO * Push() - insert on top of stack * Pop() = remove from top of stack * empty() = determines of stack is empty * peek() = peeks at top of stack without deleting anything

Array

*A sequence of elements, where each element associates with an index. First index is 0 * Each element occupies the same number of bytes *All elements share the same type. * size of the array is determined at compile time * contiguous memory loctions * int[] myArray = new[10]; //declares an array of 5 ints

inheritance

*allows one class to use functionality defined in another class * allows maximum re-use of existing code, which is written and tested, saving time * use the extends keyword to inherit from another class all non-private variables inherited * you cannot extend a final class

main() method

*public static void main(String [] args) * A built-in main method present in every java program *code inside this method gets executed

INT data type

*represents an integer (non-decimal) value of approximately -2.1 billion to +2.1 billion *represented internally as two bytes *may be specified as unsigned int: 0 to 4.2 billion does nor need quotes to be printed to screen

parameter

*values that can be specified when creating an object or calling a method * Parameters "pass" values to objects and methods

Arithmetic Operator Precedence

1. (* / %) 2. (+ -) Left to right

4 types of collections

1. Linear - ordered by position, with one predecessor and one successor 2. Heierarchal - tree structure, where a data item may have one parent and many children 3. Graphs - each data item may have many predecessors and many successors 4. Unordered - in no order, no meaningful way to attribute an item as a successor or pedecessor

8 main types of operations on collections

1. Search and retreival 2. Removal 3. Insertion 4. Replacement 5. Traversal 6. Test for equality 7. Determination of size 8. Cloning

Logical operator precedence

1.Parentheses 2. ! 3. && 4. ||

Relational operator precedence

< <= > >= Left to right

superclass

A class that is extended by a subclass. It's variables and methods become available to the subclasses below it on the hierarchy - they are inherited. constructors not inherited by subclasses (not member methods)

subclass

A class that will inherit the functionality of a superclass - and all superclasses in an inheritance tree via extends keyword: "class A extends class B". May access public and protected variables and methods Do not inherit superclass constructor Superclass constructor is called when subclass instantiated Can access superclass via super keyword A class has only one superclass

Set

A collection that cannot contain duplicate elememts Hashset: does not retain the order the elements are added LinkedHashSet: maintains a linked list of the set's elements in the order they were inserted

Control: for each lopps

A concise version of a for loop

Collection

A group of items that are to be treated as a conceptual unit. May be homogeneeous or heterogeneous Arrays, lists, stacks, queues, heaps, graphs, maps, trees, sets, and bags are all types of colletions

String

A linear collection Combines multiple characters into one object Immutable - recognize no mutator messages

BitSet

A linear collection Data restricted to 0s and 1s Support logical operations on strings of bits

StringBuffer

A linear collection Holds a copy of a String (which is immutable) to allow for manipulation

SortedCollection

A linear collection Items are sorted according to some criteria

List

A linear collection Items can be accessed at any position also called vectors or sequences

Constructor method

A method in every class that creates a blank template Instructs the class to set up the initial state of the object Same name as class May be overloaded Does not need to be declared public Does not need void keyword, even though constructors never return a value Java creates a default if constructor not in code may call other constructor methods

ArrayList<>

A pre-defined Java object to store a list of data of a specific type of Object (not primitive type) Like an array, but will change size automatically. Created with an initial size, but that can change. Both capacity and data type may be specified Syntax: ArrayList<variable type> ie Integer, String ArrayList<Integer> myList = new Arraylist<Integer>(); Good for storing and accessing data

Object

A run-time entity (instance of a class) with encapsulated variables and methods that allows interaction with the rest of the program through a restricted set of operations. Has behavior, state and identity.

information hiding

A server's ability to hide internal details from a client. The server is a black box.

Method

A set of instructions (collection of statements grouped together) that can be called on an object to perform a function. Parameters may be passed in using parentheses Names should start with a lowercase letter and use camel case

Class

A template that describes the characteristics of objects Might be pre-defined library class or new class Names should start with a capital letter

Advantages of encapsulation

Allows control of the way data is accessed More flexible, easily modified code Ability to change one part of code without affecting other parts

server

An object that RECEIVES a message. Like a bartender who hears a request and responds. AKA abstract data type - client only knows the interface

client

An object that SENDS a message. Like a customer asking for a drink

4 unordered collections

Collection, set, bag, map

abstract data type

Collections are abstract data types because they allow abstraction.

Hashing

Each value in a hash table is associated with a unique key. A key's informational content is used to determine a unique value called a hashcode

encapsulation

Ensures implementation details not visible to users Variables in one glass are hidden from other classes via keyword private Only getter/setter methods provide access to variables

abstraction

From a user's perspective, collections in Java may be utilized as a means of storing or accessing data without concern for the details of how the collections operate, and are therefore an abstraction. Achieved in java via abstract classes and interfaces

1 Graph collection

Graph

Whitespace

Ignored by compiler. Spaces, newlines, returns

Comments

Important to annotate code to describe what code is doing for readability and ease of re-use Ignored by compiler Multi line: /* ...*/ Single line: //

9 Linear collections

List, Stack, Queue, String, Heap, BitSet, StringBuffer, PriorityQueue, SortedCollection

Control: for loops

Loop a pre-determined number of times until a condition is met. Consists of initialization, test condition, increment for(int i = 0; i <10; i++)

polymorhism

One method, several implementations Different types of objects may understand the same message, but respond in their own way. A superclass may be extended by more than one subclass Each suclass may replace a public or protected method of superclass to customize that behavior

Package naming convention

Package names should be unique so distributed packages do not find conflicts with files the end user might already have. Convention: reverse the name of the website, ie. com.webitename.packageName

Control: do while loops

Runs code segment then evaluates if segment is to be run again after first loop Executed at least once

instantiation

Sets up the data space, via the constructor, using the "new" keyword

Documentation Comments

Special comments that have the appearance of multi-line comments Generate external documentation of source code /** Documentation Comment */ Javadoc will ignore all asterisks after the first two

variable

Stores a value of a specific data type variable declaration: naming the variable

2 Hierarchial Collections

Tree, Binary Tree

Equality operators (== and !=)

Used for comparison to determine if two values are identical Used on boolean, char, and int data types float?....

preconditions

What must be true before a method is invoked, if that method is to run correctly. State of parameters, instance variables to be accessed.

postcondition

What will be true after a method has finished execution. State of parameters, instance variables that were just changed.

Control: switch statements

Will execute a code block based on if a block is equal to a specific value (case) Keeps code organized and less wordy switch(condition) { case 1: action; // compares with switch condition break; // exits the switch statement default; // executed if no case conditions satisfied }

Method overriding

Writing a method in a subclass that will be used instead of the method in the superclass. Subclass contains an identical method as found in superclass, but has unique code to be executed. Needs same return type, and arguments Needs scope to be access identical or less restrictive than parent, ie. public must be public CANNOT override final methods or static methods or constructors

Heap

a collection in which the "largest" item is considered the "top". This item is usually the only item accessible. Size may be any attribute

package

a group of classes that are related in some way used to avoid name conflicts by separating the files into groups. used to control access to classes You can use as many packages as needed in a program the package name will appear at the top of program import package.className; // imports 1 class from pkg import package.*; //imports all classes from package IDE: classes should be saved in pkg folder Package names should be unique for distribution

void

a keyword that indicates no value is to be returned a method does not return a result

Control: ternary statements

a one-line if/else conditional statement comprising three parts (boolean statement) ? (exe. if true) : ( exe. if false)

containment hierarchy

a tree of components that has a top-level container as it's root Each top-level container has a content pane that contains visible components GUI components can be contained only once

Instance variable

a variable that belongs to an individual object private, not visible outside the class it is defined in exists as long as it is referenced

go to

bad programming practice to use this in Java

continue

causes the loop to skip to next iteration used to skip loop execution if a certain value is true

abstract classes

classes are defined as abstract via the abstract keyword abstract classes cannot be instantiated to use an abstract class, you must inherit it from another class via extends keyword - it is not implemented in the superclass A class containing at least one abstract method is an abstract class Useful when the method output is unique to each subclass but has no meaningful representation in superclass. i.e. Animal Class - makeSound() unique to each object An interface is a class that contains ONLY abstract methods

Hashmap<>

contains a set of keys and a value for each key like a dictionary Syntax: HashMap<keys, values> import java.uti.* modifies AbstractMap to use a hash table

method overloading

creating more than one method difference is in the list of parameters passed useful when two or more methods have nearly identical purposes when called, parameters are matched

break

exits a switch statement if no break appears, flow will fall through to subsequent cases until a break is reached in loops, terminates the loop execution transferred to next statement that follows

Control: if statements

for a block of code to be executed conditionally evaluates of a statement is true, executes if true Skips if false

Control: if/else if/else statemets

for a block of code to be executed conditionally evaluates of a statement is true, executes if true evaluates "else if" if false evaluates "else" if both preceding conditions false

Control: if/else statements

for a block of code to be executed conditionally evaluates of a statement is true, executes if true executes "else" if false ternary statements perform this same funtion

default statement

in a switch statement optional located at end of switch, after last case default action if none of the cases are matched no break needed

Concatenation

joining several strings together with the + operator

new

keyword that creates an object using this keyword calls the constructor of a class

returns

keyword that indicates a method will return a value of a specific type (the return value) after it runs.

this

keyword that references the current object itself ie. it is this particular object that should be told when an event happens

public scope

methods and variables are accessible from outside the class

protected scope

methods and variables are accessible from their own class and any subclasses

static

methods and variables that belong to the class as a whole, not any one object One variable is shared by all objects of a class Good practice to use all caps for naming static variables

abstract methods

methods not tied to any particular object declared without an implementation

mutator

methods that modify the data of an object

accessor

methods that return attributes of an object

array length

myArray.length() will return the number of elements

varaiable declaration

naming the variable so compiler may identify errors must start with a letter may contain letters, digits or underscores may be any length case sensitive cannot be a keyword

NOT (!) operator

negates the value of the operand

BOOLEAN data type

only evaluate to TRUE or FALSE represented internally as....

Control: while loops

repeats code segment as long as conditional statement remains true Conditional statement evaluated before first loop May never be executed Use if you don't know how many iterations to expect

CHAR data type

represents a single character to print to screen, enclose in single quotes ie. 'G' represented internally as one byte

random()

returns a number between 0.0 and 9.9999...

rand()

returns a random number, as seeded by the clock

array literal

shortcut for instantiating arrays of primitive types and Strings using a comma-separated list String[] names = {"sue", 'bill", "bob"};

instanceof

tests to see which event occurred ie. was that event a button push? -> (event.getSource() instanceof Button)

null

the absence of a reference

OR (||) operator

true if at least one of the operands is true

XOR () operator

true if only one of the operands is true

AND (&&) operator

true only if both operands evaluate to true

garbage collection

when objects "die" the memory space used to store them is de-allocated to a pool of free memory Automatic - Java tracks which objects are referenced Objects are considered garbage once nolonger referenced


Related study sets

Ecological Econ Final Example Questions

View Set

VTA130 Restraint for Sample Collection

View Set

fluid and electrolyte homeostasis and imbalances

View Set

Vet Science: Injection Techniques (questions)

View Set

Exam 3 (ch. 9,10,11) quiz questions

View Set

Chapter 71: Care of Pt with Gynecological Problems EAQ

View Set

CH 7: Organizational Factors: The Role Of Ethical Culture And Relationships

View Set

PF Semester 2 Proctor Objectives

View Set