Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Code from Core Java2 fails

Thread view: 
printdude1968@gmail.com - 10 May 2006 01:20 GMT
I'm running Java 5.0 using Eclipse.
This piece of code is failing within the IDE.

import java.util.*;

/**
  This program prints out all system properties.
*/
public class SystemInfo
{
  public static void main(String args[])
  {
     Properties systemProperties = System.getProperties();
     Enumeration enum = systemProperties.propertyNames();
     while (enum.hasMoreElements())
     {
        String key = (String)enum.nextElement();
        System.out.println(key + "=" +
           systemProperties.getProperty(key));
     }
  }
}

The API says (I think) that it's right but nothing I do can make it
work.
Any ideas?
James McGill - 10 May 2006 01:36 GMT
>       Enumeration enum = systemProperties.propertyNames();
>       while (enum.hasMoreElements())

enum is a reserved word now.  Tell your javac "-source 1.3" and it
should build ok.
Roedy Green - 10 May 2006 05:03 GMT
On 9 May 2006 17:20:23 -0700, "printdude1968@gmail.com"
<printdude1968@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>Any ideas?

here is my code from Wassup that does the same thing:

   /**
    * Get a sorted list of all the system properties. Only works in
    * applications and signed Applets.
    *
    * @param separator usually "\n\n"
    *
    * @return String contaning pairs of property-value
    */
   public static String displayAllProperties( String separator )
       {
       try
           {
           Properties sysprops = System.getProperties();

           // Count properties
           int count = sysprops.size();

           // prepare Matrix to hold the properties
           String[][] matrix = new String[ count ][ 2 ];

           // read System properties into the matrix
           int j = 0; // Java won't let me put this in the for loop,
Ouch!
           for ( Enumeration e = sysprops.propertyNames(); j < count;
j++ )
               {
               String key = (String) e.nextElement();
               String value = sysprops.getProperty( key );
               matrix[ j ][ 0 ] = key;
               matrix[ j ][ 1 ] = value;
               } // end for

           // sort by key
           Arrays.sort( matrix, new StringComparator() );

           // concatenate all key value pairs.
           StringBuffer result = new StringBuffer( 4096 );
           for ( int i = 0; i < count; i++ )
               {
               String key = matrix[ i ][ 0 ];
               if ( key != null )
                   {
                   String value = matrix[ i ][ 1 ];
                   if ( value != null )
                       {
                       if ( value.equals( "\r\n" ) )
                           {
                           value = "[hex chars: 0x0d 0x0a i.e. CrLf,
\\r\\n]";
                           }
                       else if ( value.equals( "\n" ) )
                           {
                           value = "[hex char: 0x0a i.e. Lf, \\n]";
                           }
                       else if ( value.equals( "\r" ) )
                           {
                           value = "[hex char: 0x0d i.e. Cr, \\r]";
                           }
                       result.append( key );
                       result.append( " = " );
                       result.append( value );
                       result.append( separator );
                       }
                   }
               } // end for
           return result.toString();
           }
       catch ( Exception e )
           {
           return "No security clearance to see the restricted System
properties.";
           }
       } // end displayAllProperties

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.