Code Syntax - 1 - Flashcards
Ouput
System.out.println(“ “);
First statement to start the program
public class <class_name>{
public static void main(String[] args){</class_name>
Single-line Comment
//Comments…..
Multi-line Comment
/* Comments
Comments
Comments*/
Declare a variable
<data_type> <variable_name>;
<data_type> <variable_name> = <value>;
We should end the value with L for long , F for float, and D for double
</value></variable_name></data_type></variable_name></data_type>
Widening Casting
converting a smaller type to a larger type size byte -> short -> char -> int -> long -> float -> double
Narrowing Casting
onverting a smaller type to a larger type size
double -> float -> long -> int -> char -> short -> byte
Switch
switch (x)
{
case a:
code block
break;
case b:
code block
break;
default:
code block
break;
}
Java break/continue
“Break” is used to stop the loop when it meets thecondition
“Continue” is used to skip one iteration of the loop and then continue the loop till the end.
Array declartion
<data_type>[] <variable_name>;
<variable_name> = new <data_type>[length];
<data_type>[] <variable_name> = new <data_type> [length];
</data_type></variable_name></data_type></data_type></variable_name></variable_name></data_type>
Array initialization
<data_type>[] <variable_name> = {a[1], a[2], a[3],...};
</variable_name></data_type>
2D-array declaration
<data_type>[][] <variable_name>;<variable_name> = new <data_type>[length][length];
<data_type>[] <variable_name> = new <data_type> [length][length];
</data_type></variable_name></data_type></data_type></variable_name></variable_name></data_type>