What is the difference between setting system property from command line and code? What is the difference between setting system property from command line and code? sqlite sqlite

What is the difference between setting system property from command line and code?


Somewhere in your code, you are probably relying on the default character set being UTF-8. For example, when you call String.getBytes() without specifying a character set, Java will use the default character set. If you always want UTF-8, then specify this when calling String.getBytes():

byte[] utf8bytes = text.getBytes("UTF-8");

Also, if you want to read a file with a specific character encoding, then specify the character encoding rather than relying on the default setting. For example:

InputStream is = new FileInputStream("utf8file.txt");BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));// Read text, file will be read as UTF-8String line = in.readLine();in.close();


If you specify your system properties on the command line they are available as soon as the program loads.

If you specify them inside your program then they will only become available after you set them, by loading the class with your main method you might also already load other classes using system properties before you are even able to set them !


Not all properties could be changed at runtime. This mean if do not specify value as argument and decide to set it from System.setProperty, that would not have effect. "file.encoding" is one of those. Possible duplicate.