Basic Java Syntax Flashcards

1
Q

How to run a java program in a console

A

java <filename></filename>

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

How to compile a java program in a console

A

javac <filename></filename>

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

Declare a public class

A

public class <filename> {</filename>

}

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

Invoke a class constructor

A

<class> <object> = new <class>();
Car ferrari = new Car();
</class></object></class>

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

Print an output

A

System.out.println(“<output>") ;</output>

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

Declare a public main method

A

public static void main(String[] args) {

}

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

Single line comment

A

//

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

Multi line comment

A

/*

<Comment>
<Comment>
*/
</Comment></Comment>

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

Documentation comment

A

/**

<documentation>
<documentation>
*/
</documentation></documentation>

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

The name of a Java source file should exactly match what?

A

The public class

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

Which source file name is correct?

A. GFG.java
B. gfg.java

A

GFG.java

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

Which print statement is correct?

A. System.out.println(“Alice”);
B. system.out.println(“Alice”);

A

A. System.out.println(“Alice”);

The “S” in System is capitolized.

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

What is the naming convention for variables and methods?

A

Lower Camel Case
The first word is always lowercase. Second word is uppercase.

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

What is the naming convention for classses, interfaces, annotations, enums, and records?

A

Upper Camel Case
The first word is always uppercase. If several words are used to form the name of the class, each inner word’s first letter should be in Uppercase.

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

What is the naming convention for Constants?

A

Screaming Snake
All letters are Uppercase.

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

How to initialize an array

A

<Datatype>[] <variable_name> = {value1,value2....

};

ex:
int[] rating = {1,2,3,4,5,6,7,8,9};
</variable_name></Datatype>

17
Q

how to return a value from a method

A

return <variable_name>;</variable_name>

18
Q

How to create a for loop

A

for (int i = 0; i < 10; i++) {
code;
}

19
Q

How to declare a two-dimensional loop

A

int[][] myMatrix;
myMatrix = new int[10][3];

This has 10 rows and 3 columns

20
Q

How do you import the Arraylist?

A

import java.util.ArrayList;

21
Q

How to declare an array list?

A

ArrayList <datatype> array_list name = new Arraylist <data_type>(array_size)</data_type></datatype>

ArrayList <String> employees = new ArrayList <String>(5)</String></String>

22
Q

How to add items to an Array List?

A

Array_name.add(value);

ex:
employees.add(“Jane Eyre”);

23
Q

How to create a for loop for an Array list?

A

for(data_type counter : Array_name) {

}

ex:
for (String counter : employees) {

}

24
Q

How do you import only the scanner from the java utility class?

A

import java.util.Scanner;

25
Q

How do you input a value from the scanner function?

A

Scanner <scanner_name> = new Scanner(System.in);</scanner_name>

Scanner atm_keypad = new Scanner(System.in);