Syntax/grammer Flashcards

The way byte code understands code (47 cards)

1
Q

Assignment Statement

A

::===

ex balance= nuBalance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Message Statement

A

.([actual parameter]);

ex. myaccount.setBalance(1234)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Return statement

A

::== return[];

ex. return balance;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
What does () mean?
ex. account();
A

“This”

ex This account.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a class?

A

Template of an object (cookie cutter, press)

contains methods and variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a variable?

A

Variable contains information

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a Method?

A

Perform actions, Allows classes to do things.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

primitives in Java:

A
byte (number, 1 byte)
    short (number, 2 bytes)
    int (number, 4 bytes)
    long (number, 8 bytes)
    float (float number, 4 bytes)
    double (float number, 8 bytes)
    char (a character, 2 bytes)
    boolean (true or false, 1 byte)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

To declare and assign a number

A

int myNumber;
myNumber = 5;
or
int myNumber = 5;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

To define a floating point number,

A

float f = (float) 4.5;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

syntax for chars

A

char c = ‘g’;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

ways to use a string

A
// Create a string with a constructor
String s1 = new String("Who let the dogs out?");
// Just using "" creates a string, so no need to write it the previous way.
String s2 = "Who who who who!";
// Java defined the operator + on strings
String s3 = s1 + s2;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Boolean

A

boolean b = false;
b = true;

boolean toBe = false;
b = toBe || !toBe;
if (b) {
    System.out.println(toBe);
}
int children = 0;
b = children; // Will not work
if (children) { // Will not work
    // Will not work
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The Arithmetic Operators (5)

A
\+       additive operator (also used for 
        String concatenation)
-       subtraction operator
*       multiplication operator
/       division operator
%       remainder operator
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The Unary Operators(5)

A
\+       Unary plus operator; indicates 
        positive value (numbers are 
        positive without this, however)
-       Unary minus operator; negates
        an expression
\++      Increment operator; increments
        a value by 1
--      Decrement operator; decrements
        a value by 1
!       Logical complement operator; 
        inverts the value of a boolean
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The Equality and Relational Operators(6)

A
==      equal to
!=      not equal to
>       greater than
>=      greater than or equal to
<       less than
<=      less than or equal to
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

The Conditional Operators(2)

A

&& Conditional-AND

|| Conditional-OR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

instanceof <—-what does it do?

A

The instanceof operator compares an object to a specified type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Field declarations are composed of three components, in order?

A

Zero or more modifiers, such as public or private.
The field’s type.
The field’s name.

20
Q

Defining Methods

A

1 Modifiers—such as public, private, and others you will learn about later.
2 The return type—the data type of the value returned by the method, or void if the method does not return a value.
3 The method name—the rules for field names apply to method names as well, but the convention is a little different.
4 The parameter list in parenthesis—a comma-delimited list of input parameters, preceded by their data types, enclosed by parentheses, (). If there are no parameters, you must use empty parentheses.
5 An exception list—to be discussed later.
6 The method body, enclosed between braces—the method’s code, including the declaration of local variables, goes here.

21
Q

method Explanation “Public”

A

Specifies that the method is accessible from outside a class

22
Q

method Explanation “Static”

A

Specifies that the method is a class method that is to be executable.even though no class objects have been created.

23
Q

method Explanation “Void”

A

Specifies that the method does not return a value

24
Q

Create an object syntax

A

ex. Point originOne = new Point(23, 94);

Declaration: The code originOne are all variable declarations that associate a variable name with an object type.
Instantiation: The new keyword is a Java operator that creates the object.
Initialization: The new operator is followed by a call to a constructor, which initializes the new object.
25
Constructor syntax
A class contains constructors that are invoked to create objects from the class blueprint. Constructor declarations look like method declarations—except that they use the name of the class and have no return type. For example, Bicycle has one constructor: ``` public Bicycle(int startCadence, int startSpeed, int startGear) { gear = startGear; cadence = startCadence; speed = startSpeed; } ```
26
WHat is an Accessor?
``` The methods that give other objects ac- cess to variables inside an object are called “accessors.” ex: 1 public int getBalance() { 2 3} 4 5 public String getName() { 6 7} return name; // return the name ```
27
Converting a String to an int
int guess= Integer.parseInt(stringGuess); | turns a number 2 into string "2".
28
Syntax for a cast Operator(change it from long to int)
long y = 42 | int x = (int) y
29
Name of pre build classes in Java
API or Java Library
30
Arraylist: Adds the object parameter to the list
add(Object elem)
31
Arraylist: removes the object at the index parameter
remove(int index)
32
Arraylist: removes this object(if its in the arraylist).
remove(Object elem)
33
Arraylist:returns "true" if theres a match for the object parameter
contains(Object elem)
34
Arraylist: returns true if the list has no Elements
isEmpty()
35
Arraylist:Returns either the index of the object parameter,or-1
indexOf(Object elem)
36
Arraylist: Returns the number of elements currently in the list
size()
37
Arraylist: Returns the object currently at the index parameter
get(in index)
38
Define Arguments
Arguments are the things pass into the methods. ex d.bark(3) 3=argument/settings
39
Define constructor
``` Constructor is an object with arguments in them. Must be the same as the class name it is in. ex: public class TUNA{ public TUNA(String Name){ girlname=name;} ``` ``` main class tuna tunaobject=new tuna(NAME) ```
40
Rules for Getters and Setter
Mark instance variables private | Mark getters and setter public.
41
What is a Instance Variable?
Instance Variable gets declared inside a class but not within a method.
42
What is a local Variable?
Local variables are declared within a method. LOCAL VARIABLES do Not get default values. wrong = int b; right= int b=12
43
How do you save a file(4 steps)
``` 1. Make a FileOutputStream FileOutputStream fileStream = new FileOutputStream(“MyGame.ser”); ``` ``` 2.Make an ObjectOutputStream ObjectOutputStream os = new ObjectOutputStream(fileStream); ``` 3. Write the object os. writeObject(characterOne); os.writeObject(characterTwo); os.writeObject(characterThree); 4. Close the ObjectOutputStream os. close();
44
What is overloading Method
Several methods same name different arguments
45
Api for buttons
Import Javax.swing.*;
46
API for listeners
java.awt.event.*;
47
How do you read files.(5 steps)
``` 1. Make a FileInputStream FileInputStream fileStream = new FileInputStream(“MyGame.ser”); ``` ``` 2.Make an ObjectInputStream ObjectInputStream os = new ObjectInputStream(fileStream); ``` 3.read the objects Object one = os.readObject(); Object two = os.readObject(); Object three = os.readObject(); 4.Cast the objects GameCharacter elf = (GameCharacter) one; GameCharacter troll = (GameCharacter) two; GameCharacter magician = (GameCharacter) three; 5. Close the ObjectInputStream os. close();