BASE-4502: Compile time examples
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.compiletimeconstants;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ClassConstants {
|
||||
|
||||
public static final int MAXIMUM_NUMBER_OF_USERS = 10;
|
||||
public static final String DEFAULT_USERNAME = "unknown";
|
||||
public static final List<String> DEFAULT_GROUPS = List.of("all", "reader");
|
||||
|
||||
public static final Logger log = LoggerFactory.getLogger(ClassConstants.class);
|
||||
public static final List<String> contributorGroups = Arrays.asList("contributor", "author");
|
||||
|
||||
public static final int MAXIMUM_NUMBER_OF_GUESTS = MAXIMUM_NUMBER_OF_USERS * 10;
|
||||
public static boolean DEFAULT_GROUPS_DEFINED = DEFAULT_GROUPS != null;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.compiletimeconstants;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class CompileTimeVariables {
|
||||
|
||||
public final int MAXIMUM_LOGIN_ATTEMPTS = 5;
|
||||
|
||||
public static void main(String[] args) {
|
||||
PrintWriter printWriter = System.console().writer();
|
||||
CompileTimeVariables instance = new CompileTimeVariables();
|
||||
final String username = "baeldung";
|
||||
printWriter.println(username);
|
||||
printWriter.println(instance.MAXIMUM_LOGIN_ATTEMPTS);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.compiletimeconstants;
|
||||
|
||||
import java.io.Console;
|
||||
public class RunTimeVariables {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Console console = System.console();
|
||||
final String input = console.readLine();
|
||||
console.writer().write(input);
|
||||
final double random = Math.random();
|
||||
console.writer().write("Number: " + random);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user