Basic Java Syntax Flashcards
How to run a java program in a console
java <filename></filename>
How to compile a java program in a console
javac <filename></filename>
Declare a public class
public class <filename> {</filename>
}
Invoke a class constructor
<class> <object> = new <class>();
Car ferrari = new Car();
</class></object></class>
Print an output
System.out.println(“<output>") ;</output>
Declare a public main method
public static void main(String[] args) {
}
Single line comment
//
Multi line comment
/*
<Comment>
<Comment>
*/
</Comment></Comment>
Documentation comment
/**
<documentation>
<documentation>
*/
</documentation></documentation>
The name of a Java source file should exactly match what?
The public class
Which source file name is correct?
A. GFG.java
B. gfg.java
GFG.java
Which print statement is correct?
A. System.out.println(“Alice”);
B. system.out.println(“Alice”);
A. System.out.println(“Alice”);
The “S” in System is capitolized.
What is the naming convention for variables and methods?
Lower Camel Case
The first word is always lowercase. Second word is uppercase.
What is the naming convention for classses, interfaces, annotations, enums, and records?
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.
What is the naming convention for Constants?
Screaming Snake
All letters are Uppercase.