Move articles out of core-java-lang part 2
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
package com.baeldung.system;
|
||||
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
/**
|
||||
* Note: This class is not meant for unit-testing since it uses system
|
||||
* features at low level and that it uses 'System' gc() which suggests
|
||||
* JVM for garbage collection. But the usage below demonstrates how the
|
||||
* method can be used.
|
||||
*/
|
||||
public class ChatWindow {
|
||||
public void windowStateChanged(WindowEvent event) {
|
||||
if (event.getNewState() == WindowEvent.WINDOW_DEACTIVATED ) {
|
||||
System.gc(); // if it ends up running, great!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.baeldung.system;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class DateTimeService {
|
||||
|
||||
// One hour from now
|
||||
public long nowPlusOneHour() {
|
||||
return System.currentTimeMillis() + 3600 * 1000L;
|
||||
}
|
||||
|
||||
// Human-readable format
|
||||
public String nowPrettyPrinted() {
|
||||
return new Date(System.currentTimeMillis()).toString();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.baeldung.system;
|
||||
|
||||
public class EnvironmentVariables {
|
||||
public String getPath() {
|
||||
return System.getenv("PATH");
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.baeldung.system;
|
||||
|
||||
/**
|
||||
* Note: This class is not meant for unit-testing since it uses system
|
||||
* features at low level and that it uses 'System' standard error stream
|
||||
* methods to show output on screen. Also unit-tests in CI environments
|
||||
* don't have console output for user to see messages. But the usage below
|
||||
* demonstrates how the methods can be used.
|
||||
*/
|
||||
public class SystemErrDemo {
|
||||
public static void main(String[] args) {
|
||||
// Print without 'hitting' return
|
||||
System.err.print("some inline error message");
|
||||
|
||||
// Print and then 'hit' return
|
||||
System.err.println("an error message having new line at the end");
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.baeldung.system;
|
||||
|
||||
/**
|
||||
* Note: This class is not meant for unit-testing since it uses system
|
||||
* features at low level and that it uses 'System' exit() which will
|
||||
* exit the JVM. Also unit-tests in CI environments are not meant to
|
||||
* exit unit tests like that. But the usage below demonstrates how the
|
||||
* method can be used.
|
||||
*/
|
||||
public class SystemExitDemo {
|
||||
public static void main(String[] args) {
|
||||
boolean error = false;
|
||||
|
||||
// do something and set error value
|
||||
|
||||
if (error) {
|
||||
System.exit(1); // error case exit
|
||||
} else {
|
||||
System.exit(0); // normal case exit
|
||||
}
|
||||
|
||||
// Will not do anything after exit()
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.baeldung.system;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
/**
|
||||
* Note: This class is not meant for unit-testing since it uses system
|
||||
* features at low level and that it uses 'System' standard output stream
|
||||
* methods to show output on screen. Also unit-tests in CI environments
|
||||
* don't have console output for user to see messages. But the usage below
|
||||
* demonstrates how the methods can be used.
|
||||
*/
|
||||
public class SystemOutDemo {
|
||||
|
||||
public static void main(String[] args) throws FileNotFoundException {
|
||||
// Print without 'hitting' return
|
||||
System.out.print("some inline message");
|
||||
|
||||
// Print and then 'hit' return
|
||||
System.out.println("a message having new line at the end");
|
||||
|
||||
// Changes output stream to send messages to file.
|
||||
System.setOut(new PrintStream("file.txt"));
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.baeldung.system;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Console;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* Note: This class is not meant for unit-testing since it uses system
|
||||
* features at low level and that it uses 'System' standard input stream
|
||||
* methods to read text from user. Also unit-tests in CI environments
|
||||
* don't have console input for user to type in text. But the usage below
|
||||
* demonstrates how the methods can be used.
|
||||
*/
|
||||
public class UserCredentials {
|
||||
|
||||
public String readUsername(int length) throws IOException {
|
||||
byte[] name = new byte[length];
|
||||
System.in.read(name, 0, length); // by default, from the console
|
||||
return new String(name);
|
||||
}
|
||||
|
||||
public String readUsername() throws IOException {
|
||||
BufferedReader reader =
|
||||
new BufferedReader(new InputStreamReader(System.in));
|
||||
return reader.readLine();
|
||||
}
|
||||
|
||||
public String readUsernameWithPrompt() {
|
||||
Console console = System.console();
|
||||
|
||||
return console == null ? null : // Console not available
|
||||
console.readLine("%s", "Enter your name: ");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user