Docsity

CSCI 1301 EXAM 2 STUDY GUIDE, Exams of Social Sciences

Toggle sidebar
bg1
CSCI 1301 EXAM 2 STUDY GUIDE
While Loop - Answers - while (boolean_expression)
{
}
Do-While Loop - Answers - do
{
} while (boolean_expression);
//Semi-colon at the end of while expression is important
For Loop - Answers - for (set_variable; boolean_expression; update_expression)
{
}
For-Each Loop - Answers - for (data_type data_name; array_name)
{
}
Create an Array - Answers - Data_Type[] array_name = new data_type[array_size];
Access Array Elements - Answers - arrayName[index]
Determining an array's length - Answers - arrayName.length
//No parentheses at the end
Iterating over arrays using loops - Answers - for (int i = 0; i < arrayName.length; i++)
{
//Then something like arrayName[i] = i;
}
Define a Class - Answers - public class className
{
//Code here
}
Object - Answers - className objectName = new className();
//Similar to the scanner object
Variables of Class Type - Answers - Unlike primitive types, variables of class type store
the memory location of their information.
pf3

Partial preview of the text

Download CSCI 1301 EXAM 2 STUDY GUIDE and more Exams Social Sciences in PDF only on Docsity!

CSCI 1301 EXAM 2 STUDY GUIDE

While Loop - Answers - while (boolean_expression) { } Do-While Loop - Answers - do { } while (boolean_expression); //Semi-colon at the end of while expression is important For Loop - Answers - for (set_variable; boolean_expression; update_expression) { } For-Each Loop - Answers - for (data_type data_name; array_name) { } Create an Array - Answers - Data_Type[] array_name = new data_type[array_size]; Access Array Elements - Answers - arrayName[index] Determining an array's length - Answers - arrayName.length //No parentheses at the end Iterating over arrays using loops - Answers - for (int i = 0; i < arrayName.length; i++) { //Then something like arrayName[i] = i; } Define a Class - Answers - public class className { //Code here } Object - Answers - className objectName = new className(); //Similar to the scanner object Variables of Class Type - Answers - Unlike primitive types, variables of class type store the memory location of their information.

Instance Variables - Answers - Variables declared within a class that should always be private (specific to that class). These variables can only be accessed by methods within their class file. //You can specify that you're talking about an instance variable in a method by using this.varName Local Variables - Answers - Variables declared within a method that will disappear as soon as a method is finished running. Blocks - Answers - Blocks are chunks of code placed within a set of curly braces. Objects, variables, and such exist only within these braces. This is known as their "scope." Void Methods - Answers - Methods that are used for changing variables and such. They do not return a value back to the main method. Return Methods - Answers - Methods that return a value back to the main method. Parameters (Actual & Formal) - Answers - Formal Parameter - The identifier used in a method to stand for the value that's passed in by the caller Actual Parameter - The actual value passed into the method by the caller. Pass-by-value - Answers - A copy of the actual parameter is passed into the method to be manipulated and possibly returned to the main method. Public - Answers - An access modifier that allows an instance variable or class to be accessed by any other class within the same directory. Private - Answers - An access modifier that prevents an instance variable or class from being modified directly in other classes within the same directory. This (Keyword) - Answers - The keyword "this" allows the user to specify that they're talking about an attribute or action of the calling object. Accessors/Mutators - Answers - Methods created within a class that allow the user to set and get the values of instance variables that are defined there. Encapsulation - Answers - The user doesn't know how something is implemented, but they're able to see the interface (comments, headings, & public constants) UML Class Diagram - Answers -