Special objects in Java and their applications

Source: Internet
Author: User

/*
* System: The methods and properties in the class are urban static.
* out: Standard output, default is console.
* In: standard input, default is keyboard.
* Propperties getProperties (): Gets the system property information.
*/


Import java.util.Properties;
public class Systemdemo {
public static void Main (string[] args) {

Properties also hashtable subclasses, so you can get the elements of the collection by using the Map method.
Properties prop=system.getproperties ();
Outputs the prop collection with an advanced for loop.
/*for (Object obj:prop.keySet ())
{
String value= (String) prop.get (obj);
SOP (obj+ "---" +value);
}
*/
Gets the system property information.
SOP (Prop.stringpropertynames ());
Define some custom information in the system.
System.setproperty ("MyKey", "myvalue");
Gets the specified information for the system
String value =system.getproperty ("Os.name");
System.out.println ("value=" +value);
Some property information is loaded dynamically when the virtual machine starts.

}
Public static<t> void sop (T t)
{

System.o

Ut.println (t);

}

}


/*
* Runtime object: Each Java application has a runtime class instance that enables the application to connect to the environment in which it is running. The current runtime can be obtained through the GetRuntime method.
The application cannot create its own instance of the Runtime class.
* This class has no constructors and cannot be a new object, so his methods are static.
* This class also has non-static methods. Indicates that the class can obtain a unique object through a method that is static and returns a value of this class type.
* This class uses a singleton design pattern: static Runtime getruntime ();
*
*/
Import java.io.IOException;
public class Runtimedemo {
public static void Main (string[] args) throws Exception {
Runtime R=runtime.getruntime ();
EXEC (String command): Executes the specified string commands in a separate process
Process p=r.exec ("C:\\qq7.4.exe");
Let the thread
Thread.Sleep (4000);
Kill the process.
P.destroy ();
Process p=r.exec ("notepad.exe Systemdemo.java");
}
Public static<t> void sop (T t)
{
System.out.println (t);
}
}



/*
* Basic mathematical methods of operation in Java.
*/
Import java.math.*;
Import Java.util.Random;
public class Mathdemo {
public static void Main (string[] args) {
Random r=new random ();
for (int x=0;x<10;x++)
{
Double d= (int) (Math.random () *10+1);
int D=r.nextint (10) +1;
SOP (d);
}
}
public static void Show () {
Returns the smallest integer greater than the number
Double D=math.ceil (12.36);
SOP (d);
Returns the largest integer less than the number
Double D1=math.floor (12.36);
SOP (D1);
Returns the rounding number of the number
Double D2=math.round (12.36);
Double D3=math.round (12.86);
SOP (D2);
SOP (D3);
}
Public static<t> void sop (T t)
{
System.out.println (t);
}
}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Special objects in Java and their applications

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.