# A Cross-Platform Approach to Coding

**URL:** <https://discourse.processing.org/t/a-cross-platform-approach-to-coding/47614>\
**Category:** Processing\
**Created:** [December 13, 2025, 4:41pm UTC](https://discourse.processing.org/t/a-cross-platform-approach-to-coding/47614 "2025-12-13T16:41:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 13, 2025, 4:41pm UTC](https://discourse.processing.org/t/a-cross-platform-approach-to-coding/47614/1 "2025-12-13T16:41:54Z")

</div>

Hello folks!

Operating systems have some differences that can sometimes be anticipated and handled in code.

This OS-dependent example works for _Windows 10_ but not for _macOS or Linux_:

```auto
String classPaths = System.getProperty("java.class.path");

println(classPaths);
println();

String [] path = classPaths.split(";"); // OS-dependent Windows path separator
printArray(path);

```

_Note_:  
The above code assumes a Windows environment since it uses the `;` separator. On _MacOS_ or _Linux_, this will fail.

A cross-platform approach using `java.io.File`:

```auto
import java.io.File;

// String
println(File.pathSeparator); // Correct separator for current OS
println(File.separator); // Correct file separator for current OS

// char
println(File.pathSeparatorChar); // Char representation of the path separator
println(File.separatorChar); // Char representation of the file separator

```

I left integrating _File.pathSeparator_ into the split function as an exercise for the reader. `:-)`

The _Processing Wiki_ has a section on _Platforms_ that would benefit from OS-related topics for _improving clarity in cross-platform development_, such as those discussed and others:  
[https://github.com/processing/processing4/wiki/Troubleshooting#platforms](https://github.com/processing/processing4/wiki/Troubleshooting#platforms)

I will share in _GitHub Issues_ (opportunities) in the future.

Season’s Greetings! - A universally cross-platform wish for the end of the year.

This should work on Windows, macOS and Linux:

```auto
// Get the OS name
String os = System.getProperty("os.name").toLowerCase();
println("Operating System: " + os);

size(500, 200, P2D);
background(0);

textAlign(CENTER, CENTER);

fill(255, 0, 0);
textSize(48);
text("Season's Greetings!", width/2, height/3);

fill(0, 255, 0);
textSize(36);
text("OS: " + os, width/2, 2*height/3);

```

`:)`
