SYSTEM (java.lang.System)
Grupeaza metode pentru interactiunea cu mediul extern masinii virtuale Java precum si metode utile pentru controlul functionarii m.v. Prin intermediul clasei System se pot accesa fisierul standard de intrare, de iesire si de eroare, prin intermediul variabilelor de tip flux in, out si err.
public static PrintStream err
public static OutputStrem out
public static InputStream in
Declaratia : public final class System extends Object
Atributul final specifica ca nu pot fi declarate sublcase ale ei
In plus, nu exista nici un constructor public, ceea ce înseamna ca nu pot fi instantiate obiecte de tipul System.
Metode
arraycopy (Object, int, Object, int, int)
Copies an array from the source array, beginning at the specified position, to the specified position of the destination array.
currentTimeMillis()
Returns the current time in milliseconds GMT since the epoch (00:00:00 UTC, January 1, 1970).
exit(int)
Exits the virtual machine with an exit code.
gc()
Runs the garbage collector.
getProperties()
Gets the System properties.
getProperty(String)
Gets the System property indicated by the specified key.
getProperty(String, String)
Gets the System property indicated by the specified key and def.
getSecurityManager()
Gets the system security interface.
getenv(String) Obsolete.
load(String)
Loads a dynamic library, given a complete path name.
loadLibrary(String)
Loads a dynamic library with the specified library name.
runFinalization()
Runs the finalization methods of any objects pending finalization.
setProperties(Properties)
Sets the System properties to the specified properties.
setSecurityManager(SecurityManager) Sets the System security.
RUNTIME (java.lang.Runtime)
Clasa Runtime este folosita de interpretorul Java în timpul executiei unei aplicatii. Ea contine clasele si metodele necesare pentru obtinerea informatiilor despre sistem în timpul executiei.
Metode
exec (String)
Executes the system command specified in the parameter.
exit(int)
Exits the virtual machine with an exit code.
freeMemory()
Returns the number of free bytes in system memory.
totalMemory()
Returns the total number of bytes in system memory.
getRuntime()
Returns the runtime.
gc()
Runs the garbage collector.
getLocalizedInputStream(InputStream)
Localize an input stream.
getLocalizedOutputStream(OutputStream)
Localize an output stream.
load(String)
Loads a dynamic library, given a complete path name.
loadLibrary(String)
Loads a dynamic library with the specified library name.
runFinalization()
Runs the finalization methods of any objects pending finalization.
traceInstructions(boolean)
Enables/Disables tracing of instructions.
traceMethodCalls(boolean)
Enables/Disables tracing of method call
Exemplu:
class MyEnv S
public void print() S
Properties p;
Runtime r;
p = System.getProperties();
r = Runtime.getRuntime();
//afiseaza toate proprietatile disponibile
p.list(System.out);
//afiseaza versiunea sistemului de operare
System.out.println(System.getProperty("os.version", "unkn"));
//afiseaza memoria totala
System.out.println("Memorie totala : " + r.totalMemory());
//afiseaza memoria libera
System.out.println("Memorie libera : " + r.freeMemory());
}
Documentul este oferit gratuit,
trebuie doar să te autentifici in contul tău.