Tutorial Addendum On Java - Beheading Ambiance

wargamesios kidsgamesios wordgamesios
 31 December 18:00   

    



    



    

Non-system Properties

    



    

The arrangement backdrop are infact stored in a map structure. It can aswell be acclimated

    

by the Java appliance program to abundance its own properties. For example, the afterward program

    

stores two non-system backdrop at the beginning, and uses them after in the program:

    

 

    

/**

    

* PropertyTest.java

    

* Absorb (c) 2002 by Dr. Yang

    

*/

    

public chic PropertyTest {

    

accessible changeless abandoned main(String a) {

    

setProgramInfo();

    

printMessage();

    

}

    

accessible changeless abandoned setProgramInfo() {

    

// Modifying a arrangement property

    

System.setProperty("java.io.tmpdir","c:\var\tmp");

    

// Abacus my own properties

    

System.setProperty("program.name","Property Test");

    

System.setProperty("program.version","3.01");

    

}

    

accessible changeless abandoned printMessage() {

    

Cord userName = System.getProperty("user.name");

    

Cord programName = System.getProperty("program.name");

    

Cord programVersion = System.getProperty("program.version");

    

Cord ioTempDir = System.getProperty("java.io.tmpdir");

    

System.out.println("Hello "+userName+",");

    

System.out.println("");

    

System.out.println("Welcome to ""+programName+", "

    

+programVersion+"".");

    

System.out.println("Note that the Java I/O "

    

+" acting agenda is amid at "+ioTempDir+".");

    

}

    

}

    



    



    

Output:

    

 

    

Hello ,

    

Welcome to "Property Test, 3.01".

    

Note that the Java I/O acting agenda is amid at c:var mp.

    



    



    

The Runtime Instance

    



    

When a Java appliance program is active central a JVM, the JVM offers an instance of the

    

Runtime chic to the program. The Java program can use this Runtime instance

    

to collaborate with the JVM and the acknowledging operating system.

    



    

There are several absorbing types of methods accessible on the Runtime instance:

    



        

  • Getting activating advice about the JVM, like freeMemory().

        



  •     

  • Launching a separate action at the operating arrangement level, like exec().

        



  •     

  • Interacting with the abeyance arrangement of the JVM, like addShutdownHook().

        



  •     

  • Forcing an actual debris accumulating job on the JVM, like gc().

        



  •     



    



    

The Runtime chic is a appropriate class. It represents the run time ambiance of

    

the Java appliance program active central the JVM.

    

You can not make a new instance of Runtim chic in your appliance program.

    

You can alone get the instance created by the JVM for your appliance program by

    

calling the Runtime.getRuntime() method.

    



    

So, the afterward cipher is wrong:

    

 

    

Runtime rt = new Runtime();

    

rt.gc();

    



    



    

The afterward cipher is correct:

    

 

    

Runtime rt = Runtime.getRuntime();

    

rt.gc();

    



    



    



    

Free Anamnesis

    



    

There a brace of ethics acclimated in Java accompanying to anamnesis management:

    



        

  • Free Memory: Amount of bytes accessible for the appliance program.

        



  •     

  • Total Memory: Amount of absolute bytes allocated to the appliance program.

        



  •     

  • Maximum Memory: Best amount of bytes that can be allocated to the application

        

    program.

        



  •     



    



    

There is one adjustment in the Runtime chic to get the anniversary of those values.

    

Here is a program assuming how to use those methods properly:

    

 

    

/**

    

* FreeMemory.java

    

* Absorb (c) 2002 by Dr. Yang

    

*/

    

public chic FreeMemory {

    

clandestine changeless long fm = new long;

    

clandestine changeless long tm = new long;

    

clandestine changeless long mm = new long;

    

clandestine changeless long um = new long;

    

accessible changeless abandoned main(String a) {

    

Runtime rt = Runtime.getRuntime();

    

getMemoryInfo(rt,0);

    

getMemoryInfo(rt,1);

    

getMemoryInfo(rt,2);

    

getMemoryInfo(rt,3);

    

getMemoryInfo(rt,4);

    

printMemoryInfo(rt,0);

    

printMemoryInfo(rt,1);

    

printMemoryInfo(rt,2);

    

printMemoryInfo(rt,3);

    

printMemoryInfo(rt,4);

    

for (int i=0; i<5; i++) {

    

System.out.println("Get anamnesis advice - move = "+i);

    

System.out.println(" Chargeless anamnesis = "+fm);

    

System.out.println(" Absolute anamnesis = "+tm);

    

System.out.println(" Best anamnesis = "+mm);

    

System.out.println(" Anamnesis acclimated = "+um);

    

}

    

}

    

accessible changeless abandoned getMemoryInfo(Runtime rt, int i) {

    

fm = rt.freeMemory();

    

tm = rt.totalMemory();

    

mm = rt.maxMemory();

    

um = tm-fm;

    

}

    

accessible changeless abandoned printMemoryInfo(Runtime rt, int i) {

    

continued fm = rt.freeMemory();

    

continued tm = rt.totalMemory();

    

continued mm = rt.maxMemory();

    

System.out.println("Print anamnesis advice - move = "+i);

    

System.out.println(" Chargeless anamnesis = "+fm);

    

System.out.println(" Absolute anamnesis = "+tm);

    

System.out.println(" Best anamnesis = "+mm);

    

System.out.println(" Anamnesis acclimated = "+(tm-fm));

    

}

    

}

    



    

 


Tags: program, system, application, class, property, memory, instance, environment, public, string, properties

 system, program, runtime, memory, println, static, public, class, application, getmemoryinfo, printmemoryinfo, string, freememory, maximum, private, total, getproperty, properties, instance, following, property, environment, bytes, getruntime, setproperty, , system out, application program, static void, public static, private static, free memory, static long, system getproperty, new long, maximum memory, total memory, runtime class, system setproperty, java application, jvm like, runtime getruntime, public static void, private static long, java application program, println free memory, println total memory, println memory used, memory info step, println maximum memory, system getproperty program, static void main, void main string, system setproperty program, java execution environment,

Share Tutorial Addendum On Java - Beheading Ambiance:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  java