Stanislav Zorjan - Stasha - Full Stack Software Engineer and Game Development Hobbyist - Prague


1. Java - Primitives
2. Java - Strings
3. Java - Arrays
4. Java - Date
5. Java - Generics
6. Java - Collections
7. Java - Localization
8. Java - Formatting
9. Java - Regular Expressions
10. Java - System
11. Java - Serialization
12. Java - Multithreading
13. Java - IO/File
14. Java - Networking
15. Java - ORM - JPA
      a) Simple User entity class

 

 

package basics.basicsExamples;

import java.io.BufferedReader;
import java.io.Console;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.channels.Channel;
import java.util.Arrays;
import java.util.Locale;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/** ****************************************************************************
 * SYSTEM EXAMPLE CLASS
 * @author stanislav.zorjan
 */
public class SystemExample {

    
    /** ************************************************************************
     * Default constructor
     */
    public SystemExample() {
	try {
	    //errorExample();
	    //inExample();
	    systemExample();
	} catch (IOException ex) {
	    Logger.getLogger(SystemExample.class.getName()).log(Level.SEVERE, null, ex);
	}
    }
    
    
    /** ************************************************************************
     * System.err example
     */
    private void errorExample(){
	System.err.append("Error\n");
	System.err.append('c');
	System.err.append("\n");
	System.err.append("error", 0, 3);
	System.err.append("\n");
	//System.err.close();
	System.err.flush();
	System.err.format("jedan %s", "dva\n");
	System.err.format(Locale.FRENCH, "jedan %f\n", 10.00);
	System.err.print("Error message\n");
	System.err.printf("jedan %s", "dva\n");
	System.err.printf(Locale.FRENCH, "jedan %f\n", 10.00);
	System.err.println();
	System.err.println("Error String");
    }
    
    /** ************************************************************************
     * System.in example
     * @throws IOException 
     */
    private void inExample() throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	System.out.println("enter something:");
	System.out.println(br.readLine());
    }
    
    /** ************************************************************************
     * System.out example
     */
    private void outExample(){
	// The same as error
    }

    /** ************************************************************************
     * System example
     * @throws IOException 
     */
    private void systemExample() throws IOException {
	String [] str = {"1", "2", "3"};
	String [] str2 = {"4", "5", "6"};
	System.arraycopy(str, 0, str2, 1, 2);
	System.out.println(Arrays.toString(str2)); // output: [4, 1, 2];
	
	// console 
	Console console = System.console();
	if(console != null) System.console().printf("String %d", 10);
	else System.out.println("There is no access to console");
	
	
	// time in milliseconds
	System.out.println(System.currentTimeMillis());
	Properties prop = System.getProperties();
	System.out.println(Arrays.toString(prop.keySet().toArray()));
	System.out.println(System.getProperty("java.runtime.name"));
	System.out.println(System.getSecurityManager());
	System.out.println(Arrays.toString(System.getenv().keySet().toArray()));
	System.out.println(System.getenv("USERPROFILE"));
	System.out.println(System.identityHashCode(str)+"  ==  "+str.hashCode());
	Channel chan = System.inheritedChannel();
	System.out.println(chan);
	System.out.println(System.lineSeparator().codePointAt(0));
	// Maps a library name into a platform-specific string: (myLib => libMylib.so) or (myLib => myLib.dll)
	System.out.println(System.mapLibraryName("myLib"));
	System.out.println(System.nanoTime());
	
	System.setProperty("testProperty", "testPropertyValue");
	System.out.println(System.getProperty("testProperty"));
	System.clearProperty("testProperty");
	System.out.println(System.getProperty("testProperty"));
	
	
	System.out.println(System.getProperty("java.library.path"));
	System.setProperty("java.library.path", "libs");
	System.out.println(System.getProperty("java.library.path"));
	
    }
    
    
}