StudyLover
  • Home
  • Study Zone
  • Features
    • Workout Interval Timer
    • Typing Tutor
  • Profiles
  • Contact us
  • Sign in
StudyLover The System Architect
Download
  1. Java
  2. Programs
The Decision Hub
Programs
Initiative: To understand the JVM environment and master the rules of manual type conversion (Casting).
public class SystemArchitect { // Define the public class named SystemArchitect
    public static void main(String[] args) { // Main entry point of the Java application
        System.out.println("=== JVM Environment Audit ==="); // Print header for the environment section
        
        var props = new String[]{"java.version", "os.name", "user.home"}; // Create a string array using var type inference
        for (String p : props) { // Iterate through each property key in the array
            String val = System.getProperty(p); // Retrieve the system property value for the given key
            System.out.println(p + " -> " + val); // Display the key and its corresponding system value
        } // End of the for-each loop
        
        System.out.println("\n=== Numeric Casting Lab ==="); // Print header for the casting section
        double d = 99.9987; // Declare a high-precision 64-bit floating-point number
        System.out.println("Double Value: " + d); // Show the original double value in the console
        
        float f = (float) d; // Manually cast double to a 32-bit float (Narrowing)
        System.out.println("Casted to Float: " + f); // Show the float value (notice minor precision loss)
        
        long l = (long) f; // Manually cast float to a 64-bit integer long (Truncation)
        System.out.println("Casted to Long: " + l); // Show the long value (decimal part is now gone)
        
        int i = (int) l; // Manually cast long to a 32-bit integer (Narrowing)
        System.out.println("Casted to Int: " + i); // Show the final integer value
        
        char c = 'J'; // Declare a single character literal 'J'
        int ascii = (int) c; // Cast character to its corresponding ASCII integer value
        System.out.println("Char 'J' to ASCII: " + ascii); // Print the numeric representation of the char
        
        byte b = (byte) 130; // Cast an out-of-range integer to a byte (-128 to 127)
        System.out.println("Overflow Byte (130): " + b); // Show how the value wraps around to -126
        
        boolean isJavaFun = true; // Declare a boolean flag for logic demonstration
        System.out.println("Boolean State: " + isJavaFun); // Print the state of the boolean variable
        
        System.out.println("Audit Complete."); // Final termination message for the program
    } // End of the main method
} // End of the SystemArchitect class
The Decision Hub
Our Products & Services
  • Home
Connect with us
  • Contact us
  • info.studylover@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website