Save
Busy. Please wait.
Log in with Clever
or

show password
Forgot Password?

Don't have an account?  Sign up 
Sign up using Clever
or

Username is available taken
show password


Make sure to remember your password. If you forget it there is no way for StudyStack to send you a reset link. You would need to create a new account.
Your email address is only used to allow you to reset your password. See our Privacy Policy and Terms of Service.


Already a StudyStack user? Log In

Reset Password
Enter the associated with your account, and we'll email you a link to reset your password.
focusNode
Didn't know it?
click below
 
Knew it?
click below
Don't Know
Remaining cards (0)
Know
0:00
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how

Java_MidTerm

Java MidTerm Chp 1 to 5 and 7

QuestionAnswer
index/subscript the number corresponding to each position in the array.
array size size N is indexed from 0 to N-1.
height[8] refers to the single variable stored at that memory location.
array is an object. To create an array the reference variable for the array has to be declared and then instantiated using the new operator. An array can be set up to hold primitive types or object (class) types. all same type or compatible.
int[] height = new int[size]; variable height is declared to be an array of integers whose type is written as int[]. The new operator reserves the memory space to store size.
array element A value stored in an array.
element type Type of data that can be stored as an element in a particular array.
int[] list = new int[LIMIT]; for (int value : list) System.out.print(value + " "); this iterator version of the for loop is used to print all the values in the array.
bounds checking ensures that an index used to refer to an array element is in range. if index is not valid and ArrayIndexOutOfBoundsException is thrown. Automatic in Java.
off-by-one errors created by processing all but one element or by attempting to index one element too many.
arrayName.length attribute of array object and holds the size of the array. This is the size and the index is length - 1.
initializer list - int[] scores = {87,98,69,87}; A list of values delimited by braces and separated by commas, used to initialize the values stored in an array. The new operator does not need to be used to instantiate the array object.
array passed to a method An array is an object and the entire array can be passed as a parameter. A reference to the array is passed to the method. Any changes made to the array element will be reflected outside the method. The formal parameter is an alias to the original.
an element of an array passed to a method if the element type is a primitive type, a copy of the value is passed. if the element type is a reference to an object, a copy of the object reference is passed.
String[] words = new String[5]; array words holds references to String objects. The new operator instantiates the array object and reserves space for five string references. The objects that are stored in each element must be instantiated separately.
mean1 = average(42,69,37,10); public double average(int ... list) for(int num:list) list.length parameter list in a method header allows a variable number of parameters to be passed in, which are stored in an array for processing. int is the type of array element, ... indicates a variable number of parameters, list is the name of the array.
one dimensional arrays represents a simple list of values
two-dimensional array int[][] table = new int[5][10]; represents a simple list of values. thought of as rows and columns of a table. Array of arrays or one-dimensional array of references to one-dimensional integer arrays.
multi-dimensional array array with more than one dimension.
class a class is a blue-print of an object. The class represents the concept of an object. It defines the variables and methods that are part of every object instantiated from it.
objects objects have states defined by values of the attributes and behaviors defined by the operations/methods associated with that object. Objects are generally nouns the methods of the class are the verbs.
members of a class members are the data and methods of a class collectively. objects can invoke member methods.
toString method is a method of any object gets called automatically whenever you pass the object to a print or println method. the default toString defined for every object is generally not useful.
scope scope of the variable is the area within a program in which the variable can be referenced.
instance variable declared at the class level, can be referenced in any method of the class. Each instance of the class has its own version of the variable.
modifier private, protected, public.
public method service method for an object because it defines a service that the object provides.
private method support method it cannot be invoked from outside the object and is used to support the activities of other methods in the class
intialization of any variables declared at class level Java automatically initializes any variables declared at the class level.
UML Unified Modeling Language class diagrams to show the contents of classes and the relationships among them.
encapsulation guarding data from inappropriate access. Make it difficult or impossible for code outside a class to "reach in" and change values of a variable that is declared inside the class.
client code that uses an object
final - private final static int NUMBER = 10 constant. final modifier are often declared using the static modifier.only need one copy of the value across all objects of the class.
accessor methods a method that provides read-only access to a particular value. getters.
mutator methods a method that changes a particular value. setters.
method declaration specifies the code that is executed when the method is invoked. called method is the invoked method. the calling method invoked it.
driver programs drive the use of other more interesting parts of a program often for testing purposes.
return statement method that returns a value. when a return statement is executed the control is immediately returned to the statement in the calling method. and processing continues there. Not good practice to have more than one return statement.
Constructors no return type. it initializes the variables associated with each object. default constructor that take no parameters are automatically provided if no constructor is provided.
parameters provide data to a method that allow the method to do its job. when method is called the parameter is copied and stored in corresponding formal parameter. literals, variables, or full expressions.
parameter list provides the type of value that is passed into the method, and the name by which the called method will refer to each value.
formal parameter name of the parameters in the header of the method declaration
actual parameters or arguments values passed into a method declaration and invocation is enclosed in parentheses after the method name.
local data variable declared in a method is local to that method and cannot be used outside of it.
static variable and methods private static int count = 0; static variable aka class variable are shared among all instances of a class. Only one copy for all objects of the class. Memory space for static variables are established when the class that contains it is referenced for the first time in the program
static methods - public static int getCount() static methods aka class method can be invoked through the class name. Do not need to instantiate an object of the class in order to invoke the method. static and main methods can access only static and local variables.
has - a relationship aggregation-is composed, at least in part, of other objects. A class that is defined in part by another class is dependent on that class.
is - a relationship
uses - relationship one class relies on the functionality of the other. Dependency relationship.
this reference this reference can be used to refer to the currently executing object.this reference refers to the object through which the method was involked. Often used in constructors but sometimes in other methods.
algorithm step by step process for solving a problem. ie recipe.
pseudocode mixture of code statements and English phrases.
pass by value All parameters are passed by value. The current value of the actual parameter is copied into the formal parameter in the method header. separate copy of the value that is passed in, any changes made to it have no effect on the actual parameter.
method overloading same method name with different parameter lists for multiple methods.
signature Method's name along with the number, type and order of its parameters. Compiler uses the complete method signature to bind a method invocation to appropriate definition. Return type is not part of the signature.
regression testing running previously administered tests again to make sure all issues are resolved.
defect testing testing to find errors.
black box testing test cases are developed without regard to the internal workings. they are based on input and outputs
white box testing or glass box testing test case is based on logic of the code. Goal is to make sure that every path through the program is executed. aka statement coverage.
unit testing creates a test case for each module of code(method) that has been authored.
integration testing all modules that were individually tested during unit testing are now tested as a collection
system testing seeks to test the entire software system and how its implementation adheres to its reuirements.
test driven development test cases are developed for code before the code is written.
debugging correcting run-time and logic errors.
flow and control is the order in which statements are executed in a running program. program flow is usually linear. Invoking a method alters the flow of control.
conditional statement/ selection statement allows us to choose which statement will be executed next. if - else statements and switch, each decision is based on a boolean expression also called condition that evaluates to true or false.
loop or repetition statement allows a program to execute a statement multiple times. s loop is based on a boolean that determines how many times the statement is executed.
equality operators ==, !=
relational operators >, <, <=, >=
logical operator !, &&, ||. && and || short circuit.
block statement several statements can be grouped together into a block statement enclosed in braces. { }
conditional operator is a ternary operator requires three operands. (condition) ? true : false;
comparing floats floats equal only if the binary digits of the underlying representaions match. should rarely use == when comparing floating point values. Use Math.abs() of the difference between two numbers.
comparing objects Can not use equality or relational operators to compare object. for strings can use equal or equalsIgnoreCase(), compareTo().
switch switch (idChar){ case 'A': action break; default: action; } can only be of type char, byte, short, or int
sentinel indicates the end of the input.
control C interrupts an infinite loop
break statement is used to stops execution of a loop. break statements are avoided in a loop.
continue statement loop condition is evaluated again the loop body is executed again if it is still true. continue statements are voided in a loop
iterator is an object that has methods that allows you to process a collection of items one at a time. hasNext(), next
hasNext iterator object that returns a boolean value indicating whether there is at least one more item to process.
next iterator object that returns the next input token as a string.
import java.io.*; text file input Scanner fileScan, urlScan: fileScan = new Scanner(newFile("websites.inp"));
creating objects - String name; creates a String variable that has a reference to a String object. An object variable does not hold the object itself, it holds the address of an object.
creating objects someobject != null someobject = null; //make sure it is a valid object prior to using it.
new operator creates an object. it instantiates an object which returns the address of the new object. After the new operator creates the object, a constructor is invoked to help set it up initially.
dot operator is used to access the instantiated objects methods.
garbage collection The process of reclaiming memory space that can no longer be used by a program.
immutable An object whose data (state) cannot be modified once it is created.
String objects cannot be lengthened or shortened nor can any of its characters change. string has methods: char charAt(int index) part of the string class java.lang package
char charAt(int index) string class java.lang package returns char at specified index.
int compareTo(String str) string class java.lang package Returns neg number if this string is lexically before the string str,0 if equal, or positive number if after the string str. stringObjName.compareTo("compareString");
String concat(String str) string class java.lang package returns new concat string
boolean equals(String str) string class java.lang package true if contains same characters as str, false otherwise
boolean equalsIngnoreCase(String str) string class java.lang package true if same otherwise false.
int length() string class java.lang package returns the number of characters in this string
String replace(char oldChar, char newChar) string class java.lang package returns new string identical with this string except every occurrence of oldChar is replaced by newChar.
String substring(int offset, int endIndex) endIndex is total number including what you are offsetting, offset start cnt at 1 returns new string that is a subset of this string starting at index offset and extending through endIndex-1. Change is inevitable, except from vending machines. mute.substring(3,30) nge is inevitable, except f
String toLowerCase() String toUpperCase() string class returns lower or upper case.
class library a collection of classes that we can use when developing program.
JAVA API application programming interfaces standard class library that is part of any java development environment. ie System, Scanner, String.... are part of Java API
package language-level org mechanism for classes. Each class in Java API belongs to a particular package. ie String class is part of java.lang package, System class java.lang package, Scanner java.util
fully qualify reference import java.util.Scanner; - asserts Scanner class of java.util package may be used in the program.
import with asterisk(*) or wildcard indicates any class inside the package might be used in the program.good only if 2 or more class are used from same package. import java.util.*;
java.lang All classes of java.lang package are automatically imported for every program.
java.math math package. performs calculations with high precision
java.text format text for output
java.util General utilities.
Random class - java.util package random number generator picks a number out of a range of values.
Random() java.util.Random; Constructor: creates a new pseudo number generator
float nextFloat() java.util.Random; returns a random number between 0.0 and 1.0
int nextInt() java.util.Random; random number that ranges over all possible int values(pos or neg)
int nextInt(int num) java.util.Random; random number in the rang 0 to num-1. import java.util.Random; Random generator = new Random(); num = generator.nextInt(20) + 10; produces an int in 0-19 range and shift results by 10 to 10-29
Math class part of the java.lang package and contains all static methods aka class methods. only need class name to invoke. Math.abs(total);
static int abs(int num) returns absolute value of num. static math class method in java.lang
static double pow(double num, double power) returns the value num raised to the power. static math class method in java.lang
static double random() returns random number between 0.0 to 1.0. static math class method in java.lang
static double sqrt(double num) returns square root of num, which must be a pos. static math class method in java.lang
NumberFormat class java.text. package
DecimalFormat class java.text package
factory methods java.text. package static NumberFormat getCurrencyInstance and static NumberFormat getPercentInstance because they produce and return an instance of an object set up in a particular manner. NumberFormat fmt1 = NumberFormat.getCurrencyInstance(); fmt1.format(totalcost);
String format(double number) both java.text.NumberFormat and java.text.DecimalFormat returns a string with specific number formatting. DecimalFormat fmt - new DecimalFormat("0.###"); fmt.format(doublevariableName);
enumerated type enum Season {winter, spring, summer, fall}; Season time; time = Season.spring; time.ordinal(); time.name(); time // will return name
ordinal value enumerated type is stored as an integer which starts at 0. time.ordinal();
wrapper classes represent a particular primitive type. ie byte Byte, int Integer, boolean Boolean, char Character. Wrapper class contains static methods. - num = Integer.parseInt(str); - Integer class contains MIN_VALUE & MAX_VALUE.
Integer(int value) / wrapper method num = Integer.parseInt(str);
autoboxing auto conversion of a primitive type to a corresponding wrapper object. Integer obj1 int num1 = 69; obj1 = num1 // auto creates int object to reverse Integer obj2 = new Integer(69); int num2; num2 = obj2; // auto extracts int value
\b,\n, \t, \r, \", \\, \' escape sequences, is a series of characters that represents a special character.
variable is a name for a location in memory used to hold a value of a particular data type.
assignment operator =
strongly typed Java is strongly typed not allowed to assign a value to another data type.
primitive data types integers, floating points, char, boolean data types. floating points are float or a double. Integers are byte, short, int, or long. All numeric types are signed (-,+).
float ratio = 0.2363F literal
long countedStars = 86827263927L literal
precedence +, - RtoL *, /, % LtoR +, -, +concat LtoR = R to L
postfix prefix count++; //count = count +1; total = count++; total = 15 and count = 16; ++count; total = ++count; total = 16 and count = 16;
+= -= *= /= assignment operator. total = total +5;
conversion techniques float sum; int count; result = sum/count; result will be a float casting: (int) (double)
String next() java.util.Scanner returns next input token as a character string
String nextLine() java.util.Scanner. returns input remaining on the current line as a character string.
double nextDouble() float nextFloat() int nextInt() java.util.Scanner
boolean hasNext() scan.hasNext() java.util.Scanner returns true if the scanner has another token in its input.
// /* */ /** javadoc*/ Comments are ignored by the computer and do not affect how the program executes.javdoc generates external documentation from the comments.
Java is case sensitive
white space blanks, tabs, and newline characters used to separate words and symbols in a program. extra white space is ignored.
Java bytecode low-level representation of Java source code program. Java compiler translates source code into bytecode which can be executed using Java interpreter. bytecode is transportable across Web. java is architecture neutral.
Syntax rules define how symbols and words of a programming language can be put together.
4 basic activities in software development requirement analysis, design, implementation, and testing.
primary element that support object-oriented programming objects, classes, encapsulation, and inheritance.
errors compile-time error - no executable created run-time error - crash or term abnorm logical error - program compiles and executes but produces incorrect data
inheritance reuse. one class can be used to derive serveral new classes.
application program
software consist of programs and the data those programs use
program development writing, translating, investigating.
basic programming steps edit & save program, translated program executable, execute program.
IDE integrated development environment combines tools into one software program.
development environment set of tools used to create, test, and modify programs. NetBeans
aliases two or more references that refer to the same object are aliases of each other.
Created by: callum29
Popular Computers sets

 

 



Voices

Use these flashcards to help memorize information. Look at the large card and try to recall what is on the other side. Then click the card to flip it. If you knew the answer, click the green Know box. Otherwise, click the red Don't know box.

When you've placed seven or more cards in the Don't know box, click "retry" to try those cards again.

If you've accidentally put the card in the wrong box, just click on the card to take it out of the box.

You can also use your keyboard to move the cards as follows:

If you are logged in to your account, this website will remember which cards you know and don't know so that they are in the same box the next time you log in.

When you need a break, try one of the other activities listed below the flashcards like Matching, Snowman, or Hungry Bug. Although it may feel like you're playing a game, your brain is still making more connections with the information to help you out.

To see how well you know the information, try the Quiz or Test activity.

Pass complete!
"Know" box contains:
Time elapsed:
Retries:
restart all cards