Sanding our assholes with 150 grit. Slowly. Lovingly.

Addition the java language

I would really like to see this:

Number 1:

public class com.me.yea.ClassName {
}

as oppposed to:

package com.me.yea;

import ...
import ...
import ...
import ...
public class ClassName {
}

The classname and package are pretty linked together.


Number Two:

The ability to link a jar file to a class.  For example, normally if you want to find what class a jar is in; you have to search for that class in all your jar files, for example if you have an Exception and need to track down the actual binary.

This may need to go on JoS.
Permalink Send private email Bot Berlin 
September 6th, 2006 7:27pm
Can't you do number two with Eclipse?
Permalink Funny Bünny 
September 6th, 2006 7:30pm
You sort of can.  But doesnt help if you are running your code on an actual server and you get a stacktrace and you want to track down the library that class is in.
Permalink Send private email Bot Berlin 
September 6th, 2006 7:33pm
I think you should post this to a good java forum.

For number 1, wouldn't all the imports required in both cases ?

I don't see what's different btw the two.
Permalink Rick Zeng/Tseng 
September 6th, 2006 7:38pm
One will compile, one won't.
Permalink Send private email Bot Berlin 
September 6th, 2006 7:39pm
Yeah, but you need to convince Sun that your new mechanism worths implementing.
Permalink Rick Zeng/Tseng 
September 6th, 2006 7:41pm
Like you said, they aren't very different, so it wouldnt be a hard sell.

public class com.me.yea.ClassName {
}

To have package at the top of the class in terms of the source is probably easier to interpret but having it when you define your class is more consistent with the rest of the language features. 

For example, when you run a main class:

java com.me.yea.ClassName
not:
java -package com.me.yea -class ClassName

When you get a stack trace or some other output, you see:

com.me.yea.ClassName..

etc, etc.
Permalink Send private email Bot Berlin 
September 6th, 2006 7:45pm
I don't know wheter there is technical reason to reject your proposal, but I doubt Sun and JCP companies will make change with no material gain.
Permalink Rick Zeng/Tseng 
September 6th, 2006 8:10pm
Why would they ever change it then.

The gain here is for more consistent behaviour.  Look at the new "static imports".  There isnt really much gain there either.

You already have to place the class in the proper folder i.e

file:///C:/com/on/me/all/night/baby/
  ...ClassName.class

So you are triple reinforcing the packagename:

public class com.on.me.all.night.baby.ClassName {
}
Permalink Send private email Bot Berlin 
September 6th, 2006 8:16pm
"Static imports" gives you material gain, since you don't need to mention the class name everytime you use the static methods/fields.

"You already have to place the class in the proper folder i.e

file:///C:/com/on/me/all/night/baby/
  ...ClassName.class"

That's implementation detail of which some imaginary/real  companies will do choose otherwise.

Package is a concept with real impact in the language/VM: there is the package scope. So I think it's better to make it obvious in the source file.
Permalink Rick Zeng/Tseng 
September 6th, 2006 9:02pm
Re: "want to find what class a jar is in"
I'm assuming you mean "what jar a class is in"... well, want no more:
/**
* JarFinder.java
* Safari Books Online, LLC
*/
package com.lysergicjava.util;

import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Finds the jarfile that houses java classes on the classpath.
*/
public class JarFinder
{
/**
* Returns the fully qualified location of the jar that holds the given class.
* @param c
* @return
* @throws ClassNotFoundException
*/
public static String locate(Class c) throws ClassNotFoundException
{
final URL location;
final String classLocation = c.getName().replace('.', '/') + ".class";
final ClassLoader loader = c.getClassLoader();
if (loader == null)
{
location = ClassLoader.getSystemResource(classLocation);
}
else
{
location = loader.getResource(classLocation);
}
if (location != null)
{
Pattern p = Pattern.compile("^.*:(.*)!.*$");
Matcher m = p.matcher(location.toString());
if (m.find())
{
return m.group(1);
}
else
{
throw new ClassNotFoundException("Cannot parse location of '" + location + "'.");
}
}
else
{
throw new ClassNotFoundException("Cannot find class '" + c.getName() + " using the classloader");
}
}

}
Permalink Send private email Jöhn Härën 
September 7th, 2006 9:55am

This topic is archived. No further replies will be accepted.

Other topics: September, 2006 Other topics: September, 2006 Recent topics Recent topics