Java Basics Flashcards
Learn some basic Java info like what year/who created Java (33 cards)
Who owns Java?
Oracle
What two programming languages are most similar to Java?
C++ and C#
What type of programming language is Java?
Ex. Logic programming, scripting programming
An object-oriented language
Is Java a proprietary, closed source, open source, or free software?
Open source
What year was Java created?
1995
Every line of code that runs in Java must be inside a ___?
class
Should a class always start with an upper case or lower case letter?
Upper case
Would Java read these as being the same? “MyClass” and “myclass”
No, Java is case sensitive
What’s a statement in Java?
A statement is a complete instruction terminated by a semicolon.
Ex.
“x = 5 + 5;” is a statement
What’s an expression in Java?
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””)
What can expressions can do?
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
What are the three types of Java statements?
Expression statements
Declaration statements
Control-flow statements
What do declaration statements do?
They declare variables ex. x = 5;
What do control-flow statements do?
They determine the order that statements are executed
Can variables created in a code block be used outside of the code block?
No, variables created in a code black can only be used in the same code block
Can you call a method above were it is defined?
Yes, unlike variables you can call methods before the method appears in your code
What’s a code block?
All code inside { }
In IntelliJ, what does a light grey method mean?
That it is not being used
What’s a parameter?
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; }
What’s an argument in Java?
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);
Can you put a method into a variable?
Yes
Should methods be created outside, or inside of the main method?
Outside. You then can call methods inside of the main method that are created outside of the main method.
In what area should you call methods?
Inside the main method
In the code, what is some unnecessary code that can be deleted?
if (score >= 1000) { return 1; } else if (score >= 500 && score < 1000) { return 2; } else { return 3; }
” && 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.