Skip to content

Instantly share code, notes, and snippets.

@leraux
Created January 21, 2021 18:19
Show Gist options
  • Save leraux/0d7ce10f4dcd334c870315bc2eefc022 to your computer and use it in GitHub Desktop.
Save leraux/0d7ce10f4dcd334c870315bc2eefc022 to your computer and use it in GitHub Desktop.
Covering maximum Java Keywords
package in.flyspark.keywords; // ##package
import java.io.File; // ##import
public strictfp class Keywords { // ##public ##strictfp ##class
public static void main(String[] args) { // ##static ##void
Keywords keywords = new Keywords(); // ##new
try { // ##try
keywords.test();
} catch (Exception e) { // ##catch
e.printStackTrace();
} finally { // ##finally
System.out.println("finally");
}
}
public Keywords() {
System.out.println("Constructor");
}
private static final double PI = 3.142159; // ##private ##final ##double
byte b = 127; // ##byte
short s = 125; // ##short
int i = 10; // ##int
long l = 100; // ##long
float f = 125.25f; // ##float
double d = 125.333; // ##double
boolean boolTrue = true | false; // ##boolean ##true ## false
char c = 'a'; // ##char
protected int T = 123; // ##protected
transient int F = 45; // ##transient
String nullVal = null; // ##null
public void test() throws Exception { // ##throws
for (int i = 1; i < 5; i++) { // ##for
if (i == 3) { // ##if
break; // ##break
}
if (i == 2) {
continue; // ##continue
}
System.out.println(i);
}
int a = 1;
while (a < 5) { // ##while
System.out.println(a);
a++;
}
do { // ##do
System.out.println(a);
a++;
} while (a < 7);
if (a > 7) {
System.out.println("a==7");
a++;
} else if (a == 7) { // ##else
System.out.println("a>7");
}
switch (a) { // ##switch
case 7: // ##case
System.out.println(a);
break;
case 8:
System.out.println(b);
default: // ##default
System.out.println("default");
}
}
public enum OPERATIONS { // ##enum
ADD, SUB, MUL, DIV
}
public interface Calculator { // ##interface
public int add(int a, int b);
}
abstract class CalculatorImpl extends Thread implements Calculator { // ##abstract ##extends ##implements
public synchronized int add(int a, int b) { // ##synchronized
try {
File f = new File("");
System.out.println(f.getAbsolutePath());
System.out.println(f instanceof File); // ##instanceof
throw new Exception();
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("finally will execute");
}
return a + b; // ##return
}
public native void testNative(); // ##native
int T = 10;
public CalculatorImpl() {
super(); // ##super
System.out.println(this.T); // ##this
}
}
{
System.out.println("Init");
}
private static volatile int ABC = 10; // ##volatile
/**
* Not Used - ##const ##goto
* Special - ##var ##_
* JUnit - ##assert
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment