Java can cross the platform because Java virtual functions cross-platform.
Since the code compiled by the Java program is not code that can be run directly by the hardware system, it is an "intermediate code"-bytecode. Different Java Virtual machines (JVMS) are then installed on different hardware platforms, which are then "translated" by the virtual machine (JVM) into code that the corresponding hardware platform can execute. So for Java programmers, there is no need to consider what the hardware platform is. So Java can be cross-platform.
Because it has a virtual machine (JVM), the Java program is not running directly on the computer, it is on the virtual machine, each system platform has its own virtual machine (JVM), so the Java language can cross the platform.
The Java code does not run directly on the CPU, but on the Java Virtual Machine (the JVM).
Java is a class file that compiles Java files into binary bytecode, and the JVM interprets the execution class file.
Because Java is running on the JVM, its code can be run without modification on the JVM of the different platforms (Unix-Unix JVM, Linux-Linux JVM, Windows-based JVM)
If you are porting to UNIX with Windows, simply translate the Java file into a class file that is the UNIX JVM creates Macintosh and then run it with the JVM.
How Java works across platforms