Create a package named QHApplicationEntrance under QHEntrance, then create a class called QHBaseEntrance to serve as the application entry point. Let's start with a simple hello world to verify the setup works correctly.
Once you see the console output "Helo world!Now we get to start!", you can proceed with the implementation.
The goal is to configure the application to run on an X64 platform and operate in development mode. We'll define constants that can be passed as arguments to the main function. Using developer mode allows us to exclude code that is only needed during testing but should not be included in the release version. We'll also add a constant to determine whether the loaded content is a demonstration case from this project.
To accomplish this, create a package named QHBasic under QHBaseBasic, then create a globally accessible constants class called SConst. This class should be final to prevent extension, and any future constants can be added here as needed.
package QHBasic;
/**
* Global constants for application configuration
*/
public final class SConst {
/**
* Command line arguments
*/
public static String[] StartupParameters = null;
/**
* Development mode flag
*/
public static boolean DeveloperMode = false;
/**
* X64 platform flag
*/
public static boolean IsX64 = true;
/**
* Whether this is a project demo
*/
public static final boolean MZDemo = true;
}
Now let's implement the main functon to handle startup paramter initialization.
The main function now looks like this:
package QHApplicationEntrance;
import QHBasic.SConst;
public class QHBaseEntrance {
public static String[] StartupParameters = null;
public static void main(String... args) {
System.out.println("Hello world!Now we get to start!");
SConst.StartupParameters = args;
StartupParameters = args;
if (args != null && args.length != 0) {
for (int i = 0; i < args.length; i++) {
if (args[i].compareToIgnoreCase("--DeveloperMode") == 0) {
SConst.DeveloperMode = true;
}
if (args[i].compareToIgnoreCase("--X64") == 0) {
SConst.IsX64 = true;
}
}
}
if (SConst.DeveloperMode) {
System.out.println("In Developer Mode");
} else {
System.out.println("In Publication Mode");
}
if (SConst.IsX64) {
System.out.println("In X64 platform");
} else {
return;
}
}
}
Note: The X64 platform detection here is manually controlled rather than automatically validated. The developer mode setting is primarily used to initialize the constant for later use. The return statement in the else branch is not truly correct from a design perspective, but it doesn't prevent continuing with subsequent development.