Java Basics Flashcards

Learn some basic Java info like what year/who created Java (33 cards)

1
Q

Who owns Java?

A

Oracle

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

What two programming languages are most similar to Java?

A

C++ and C#

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

What type of programming language is Java?

Ex. Logic programming, scripting programming

A

An object-oriented language

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

Is Java a proprietary, closed source, open source, or free software?

A

Open source

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

What year was Java created?

A

1995

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

Every line of code that runs in Java must be inside a ___?

A

class

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

Should a class always start with an upper case or lower case letter?

A

Upper case

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

Would Java read these as being the same? “MyClass” and “myclass”

A

No, Java is case sensitive

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

What’s a statement in Java?

A

A statement is a complete instruction terminated by a semicolon.
Ex.
“x = 5 + 5;” is a statement

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

What’s an expression in Java?

A

An expression is a combination of operators, literals, method calls, constants, and variables. It does not include data types or semicolons. Expressions are part of statements.
Ex.
Double “x = 5 +5”;
System.out.println(““this is an expression””)

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

What can expressions can do?

A

Produce a value: int “x = 1+1”;

Assign a variable: int “v = 10” ;

Produce no result but might have a side effect. Side effects occur when an expression changes the value of any of its operands. Ex.
int “product = a * b” ;

The only variable changed in this expression is product, a and b are not changed. This is called a side effect

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

What are the three types of Java statements?

A

Expression statements
Declaration statements
Control-flow statements

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

What do declaration statements do?

A

They declare variables ex. x = 5;

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

What do control-flow statements do?

A

They determine the order that statements are executed

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

Can variables created in a code block be used outside of the code block?

A

No, variables created in a code black can only be used in the same code block

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

Can you call a method above were it is defined?

A

Yes, unlike variables you can call methods before the method appears in your code

17
Q

What’s a code block?

A

All code inside { }

18
Q

In IntelliJ, what does a light grey method mean?

A

That it is not being used

19
Q

What’s a parameter?

A
The values that are apart of a functions header
Ex.                                              
                                                 //A &   B   are parameters
public static int Example (int a, int b) {
    return a + b;
}
20
Q

What’s an argument in Java?

A

When a function is called, the values that are passed in the call are arguments. Also called actual parameters.
Ex.
public static void main (String[ ] args) {

    int x = 2;
    int y = 5;
                                   //X & Y are the arguments
    int sum = multiply (x, y);
21
Q

Can you put a method into a variable?

22
Q

Should methods be created outside, or inside of the main method?

A

Outside. You then can call methods inside of the main method that are created outside of the main method.

23
Q

In what area should you call methods?

A

Inside the main method

24
Q

In the code, what is some unnecessary code that can be deleted?

if (score >= 1000) {
    return 1;
} else if (score >= 500 &amp;&amp; score < 1000) {
    return 2;
} else {
    return 3;
}
A

” && score < 1000”
“ else {“
return 3;
Resin being is the second if condition of “score < 1000” will always be true.
And
Reason for removing “else {“ is that in if statements, the last line of code will run if all statements above are false.

25
What's method overloading?
When you create two methods with the same name (with different parameters)
26
What is concatenation?
When you use the + symbol to add strings together
27
What's a char?
A single character ex. "F"
28
Can you declare (create) a constant / static variable inside a method?
No it must be declared outside of a method
29
``` Which of these formats should a constant be declared? A. CONSTANT_VARIABLE B. Constant_Variable C. constant_variable D. constantVariable ```
A. CONSTANT_VARIABLE This is pretty much the universal way of writing a constant. You can technically write it however you want though, but it'd be a bit like wRItInG lIKe tHiS.
30
What 4 primitive types can be used with switch statements?
byte, short, char, and int
31
Do you define a char with ' ' or " "?
' ' why? I don't know but characters are defined with " "
32
What can you do to make a value of "24.0048630" print a double with only two decimal numbers?
String.format("%.2f", double value)
33
What is this new line of code doing? What are three things it can be called? House blueHouse = new House ("blue");
It's creating a new variable called 'blueHouse' , which is also a new instance of the 'House' class. The code is also called a reference meaning it's referencing to the House class. So that code can be called a new variable, instance, or reference. Also it assigns blue to blueHousre