Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Code from Core Java2 fails

Reply
Thread Tools

Code from Core Java2 fails

 
 
printdude1968@gmail.com
Guest
Posts: n/a
 
      05-10-2006
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?

 
Reply With Quote
 
 
 
 
James McGill
Guest
Posts: n/a
 
      05-10-2006
On Tue, 2006-05-09 at 17:20 -0700, wrote:

> Enumeration enum = systemProperties.propertyNames();
> while (enum.hasMoreElements())


enum is a reserved word now. Tell your javac "-source 1.3" and it
should build ok.

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      05-10-2006
On 9 May 2006 17:20:23 -0700, ""
<> 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

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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code from Core Java2 fails printdude1968@gmail.com Java 0 05-10-2006 12:53 AM
Core Solo & Core Duo are not Core microarchitecture; 65nm Pentium M chips bigal Hardware 0 03-22-2006 11:24 AM
Java2 javax Print Service help needed Lionel Chin Java 0 08-26-2004 08:17 AM
Print LANDSCAPE JAVA2 AWT ONLY pcouas@infodev.fr Java 0 01-07-2004 10:08 AM
Java2 install in Mozilla..?? Frank Kuypers Firefox 1 12-13-2003 10:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57