logo

Java'da Sistem Sınıfının getproperty() ve getproperties() yöntemleri

Java'daki System sınıfının sistem özelliklerini okumak için kullanılan iki yöntemi vardır: 

    getProperty: System sınıfı getProperty'nin iki farklı sürümüne sahiptir. Her ikisi de bağımsız değişken listesinde adı geçen özelliğin değerini alır. İki getProperty yönteminden daha basit olanı tek bir argüman alır.getProperties:Java.lang.System.getProperties() yöntemi geçerli sistem özelliklerini belirler.


Yöntemlerin açıklaması:  

    getProperty(Dize anahtarı):  java.lang.System.getProperty(String key) yöntemi, özelliğin değerini içeren bir dize döndürür. Özellik mevcut değilse getProperty'nin bu sürümü null değerini döndürür. 
    Bu, aşağıdaki tabloda belirtildiği gibi anahtar - değer çiftine dayanmaktadır.  
    Sözdizimi: 
     
public static String getProperty(String key)   Parameters :   key : key whose system property we want   Returns :   System property as specified the key Null : if there is no property present with that key.
    Uygulama : 
Java
// Java Program illustrating the working of getProperty(String key) method import java.lang.*; import java.util.Properties; public class NewClass {  public static void main(String[] args)  {  // Printing Name of the system property  System.out.println('user.dir: '+System.getProperty('user.dir'));  // Fetches the property set with 'home' key  System.out.println('home: '+System.getProperty('home'));  // Resulting in Null as no property is present  // Printing 'name of Operating System'  System.out.println('os.name: '+System.getProperty('os.name'));  // Printing 'JAVA Runtime version'  System.out.println('version: '+System.getProperty('java.runtime.version' ));  // Printing 'name' property  System.out.println('name: '+System.getProperty('name' ));  // Resulting in Null as no property is present  } } 
    Çıkış : 
user.dir: /tmp/hsperfdata_bot home: null os.name: Linux version: 1.8.0_101-b13 name: null
    getProperty(Dize anahtarı Dize tanımı):java.lang.System.getProperty(String key String define) argüman tanımını ayarlamaya izin verir, yani belirli bir anahtar için varsayılan bir değer ayarlanabilir. 
    Sözdizimi: 
public static String getProperty(String key String def)   Parameters :   key : system property def : default value of the key to be specified   Returns :   System Property Null : if there is no property present with that key.
    Uygulama: 
Java
// Java Program illustrating the working of  // getProperty(String key String definition) method import java.lang.*; import java.util.Properties; public class NewClass {  public static void main(String[] args)  {  // use of getProperty(String key String definition) method  // Here key = 'Hello' and System Property = 'Geeks'  System.out.println('Hello property : '   + System.getProperty('Hello' 'Geeks'));  // Here key = 'Geek' and System Property = 'For Geeks'  System.out.println('System-property :'  + System.getProperty('System' 'For Geeks'));    // Here key = 'Property' and System Property = null  System.out.println('Property-property :'  + System.getProperty('Property'));  } } 
    Çıkış : 
Hello key property : Geeks System key property :For Geeks Property key property :null
    getProperties() : java.lang.System.getProperties()Sisteminizdeki JVM'nin İşletim Sisteminizden aldığı mevcut özellikleri getirir. Geçerli Sistem özellikleri, getProperties() yöntemi tarafından kullanılmak üzere Properties nesnesi olarak döndürülür. Böyle bir özellik kümesi mevcut değilse, önce bir sistem kümesi oluşturulur ve daha sonra başlatılır. 
    Ayrıca System.setProperties() yöntemini kullanarak mevcut sistem özellikleri kümesini de değiştirebilirsiniz. Çok sayıda var özellikler dosyasındaki anahtar/değer çifti bunlardan bazıları aşağıdaki gibidir: 
     
  Keys                          Values   --> os.version : OS Version --> os.name : OS Name --> os.arch : OS Architecture --> java.compiler : Name of the compiler you are using --> java.ext.dirs : Extension directory path --> java.library.path : Paths to search libraries whenever loading --> path.separator : Path separator --> file.separator : File separator --> user.dir : Current working directory of User --> user.name : Account name of User --> java.vm.version : JVM implementation version --> java.vm.name : JVM implementation name --> java.home : Java installation directory --> java.runtime.version : JVM version
    Sözdizimi: 
public static Properties getProperties()   Parameters :   ------   Returns :   System properties that JVM gets on your System gets from OS
    Uygulama: 
Java
// Java Program illustrating the working of getProperties() method import java.lang.*; import java.util.Properties; public class NewClass {  public static void main(String[] args)  {  /* Use of getProperties() method  System class refers to the JVM on which you are compiling your JAVA code  getProperty fetches the actual properties  that JVM on your System gets from your Operating System  */  System.out.println('Following are the JVM information of your OS :');  System.out.println('');    // Property Object  Properties jvm = System.getProperties();  jvm.list(System.out);  } } 
  • Çıktı: Tıklayın Burada çıktıyı görmek için 
     


Önemli Noktalar:   



    java.lang.System.getProperty(Dize anahtarı):yalnızca bu özellikleri - anahtarı kullanarak belirleyeceğiniz değerleri (istediğiniz belirli değerle ilişkili) getirir.java.lang.System.getProperty(Dize anahtarı Dize tanımı):istediğiniz kendi anahtar/değer kümelerinizi oluşturmanıza yardımcı olur.java.lang.System.getProperties():Sisteminizdeki JVM'nin İşletim Sisteminden aldığı tüm özellikleri - değerleri getirir.


Test Oluştur