Exam1 Flashcards
(62 cards)
class header
public class C1 {
main method header
public static void main (String [] args) {
Random generator with seed
Random rand = new Random (seed);
random number from rand, to preset max
rand.nextInt(MAX+1)
create array myArr with howmany integers
int [] myArr = new int [howmany];
set up Scanner scnr
Scanner scnr = new Scanner (System.in);
for loop to howmany
for (int i = 0; i < howmany; i++) {
set x to next typed in integer input
x = scnr.nextInt();
package header
package P1;
import Scanner
import java.util.Scanner;
declare constant max and set as 2
final int MAX = 2;
for loop internal: print each
System.out.print(numbers[i])
if a method is not static…
it needs an object to call it, even in its own class.
e. g. c1 o1 = new c1();
o1. m1();
if a class is hidden public…
it can’t be accessed from a different package.
how to call a public static method in diff class, same package
e.g. class.method();
how to call a public static method in diff class, diff package
import package, call class.method
e. g. import package.class;
class. method();
how to call hidden public method in diff class, same package
create object, call object.
e. g. classname object=new classname();
object. method();
how to call hidden public method in diff class, diff package
import package, create object, call object. e.g. import package.class; classname object=new classname(); object.method();
private methods…
cannot be accessed outside their class.
UML normal arrow means
uses or imports, for example a Random class from Java library. Read from stem to tip.
UML diamond with line means
aggregates (read from diamond to line)
aggregates indicates
an object or reference variable has been used
deep copy function
a new (editable) copy, a separate object, does not continue to reference the original
deep copy constructor example
C1 obj1 = new C1(); C1 obj2 = new C1(obj1);