Results 1 to 5 of 5

Thread: What is a Java property category?

  1. #1
    Join Date
    Jul 2006
    Posts
    289

    What is a Java property category?

    I am new to the Java. I want to know what is a Java Property Category?Can someone explain me by giving an example. Also tell me the purpose of using them.? Since I am new to the Java, very simple and right answers are warmly welcomed.!
    Signatures reduce available bandwidth

  2. #2
    Join Date
    Mar 2008
    Posts
    349

    Re: What is a Java property category?

    I think that you want to know about the Java Property class. To save and restore the properties for a program of Java, the function of the java.util.Properties class is used. Also using the java.util.Preferences will be easier. The java.util.Properties class stores and loads key/value pairs from a file, and manages them in memory. I am giving an example code for creating a new Properties table and I am assigning a string value to three different keys. Here is the code for that :
    Code:
    Properties props = new Properties(); 
    props.setProperty("recursiveSearch", "true");
    props.setProperty("maxLevel", "7");
    props.setProperty("fileName", "C:\temp\work.html");

  3. #3
    Join Date
    Nov 2008
    Posts
    1,192

    Re: What is a Java property category?

    You can use the Properties .store method for storing a Properties table in a file. This method will write the properties to the output stream, with a header line from the String parameter.
    Code:
    boolean recursiveSearch;
    String noCopyPattern;
    int maxLevel;
    . . .
    try {
      OutputStream propOut = new FileOutputStream(
                new File("props.stat"));
    }catch (. . .

  4. #4
    Join Date
    Nov 2008
    Posts
    996

    Re: What is a Java property category?

    I think that you are asking about the System Properties. I have explained how to get the System Properties. You can get only one property at a time by supplying the key in a call to System.getProperty().
    • String System.getProperty(String key, String default) - This property Returns the value of property key as a string.
    • String System.getProperty(String key) - This property returns the value of property key as a String.
    • Properties System.getProperties() - This property returns a Properties object which has the value of all the properties.

  5. #5
    Join Date
    Mar 2008
    Posts
    672

    Re: What is a Java property category?

    You can use the following program for displaying a list of System Properties.

    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    
    public class SysPropList {
        public static void main(String[] args) {
            JFrame window = new JFrame("System Properties");
            window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            window.setContentPane(new SysPropListGUI());
            window.pack();
            window.setVisible(true);
        }
    }
    
    class SysPropListGUI extends JPanel {
        JTextArea m_propertiesTA = new JTextArea(20, 40);
    
        public SysPropListGUI() {
            this.setLayout(new BorderLayout());
            this.add(new JScrollPane(m_propertiesTA), BorderLayout.CENTER);
    
            Properties pr = System.getProperties();
            TreeSet propKeys = new TreeSet(pr.keySet());  // TreeSet sorts keys
            for (Iterator it = propKeys.iterator(); it.hasNext(); ) {
                String key = (String)it.next();
                m_propertiesTA.append("" + key + "=" + pr.get(key) + "\n");
            }
        }
    }

Similar Threads

  1. Windows 7 search box is having Files Category only
    By Randomly in forum Operating Systems
    Replies: 7
    Last Post: 09-01-2012, 12:46 PM
  2. Does iPad comes in category of eReader?
    By Nauset in forum Portable Devices
    Replies: 4
    Last Post: 06-04-2010, 10:56 AM
  3. Category 6 network cabling
    By Saura in forum Networking & Security
    Replies: 5
    Last Post: 26-03-2010, 05:25 AM
  4. How to write a Property Change Listener in Java?
    By SKREECH in forum Software Development
    Replies: 4
    Last Post: 13-02-2010, 04:21 AM
  5. Cannot delete buddy category in iChat
    By MacIntel in forum Operating Systems
    Replies: 3
    Last Post: 24-10-2009, 10:08 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,362,809.37711 seconds with 16 queries