 |
 |
Index ‹ java-programmer
|
- Previous
- 4
- SET CLASSPATHhi, i'm using the abstract class definition, and when compiling the abstract
class it's ok, but the problem is when compiling the subclass: i get the
following message:
Rect.java:9: cannot resolve symbol
symbol : class GeoFigure
location: class figures.Rect
public class Rect extends GeoFigure
^
1 error
the abstract class is called: GeoFigure;
and the subclass is Rect
so how cn use the set classpath at command line, should it include the
directory where are located all the package files(the abstract class and
subclass .java files), or should it point at onel evel before the directory
that contains the package files?
thank's!
--
SAID BARA
- 4
- java/81177: java patch server down
>Number: 81177
>Category: java
>Synopsis: java patch server down
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: freebsd-java
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: update
>Submitter-Id: current-users
>Arrival-Date: Tue May 17 20:30:07 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator: Ron
>Release: FreeBSD 5.4-STABLE i386
>Organization:
>Environment:
System: FreeBSD justok.thuisnetwerk.nl 5.4-STABLE FreeBSD 5.4-STABLE #0: Sat May 14 16:24:15 CEST 2005 email***@***.com:/usr/obj/usr/src/sys/MYKERNEL i386
>Description:
jdk14 and jdk15 can not be installed, because http://www.eyesbeyond.com/freebsddom/java/jdk15.html is down.
<code/input/activities to reproduce the problem (multiple lines)>
Use any webbrowser to visit the URL, and see that it's down.
>How-To-Repeat:
>Fix:
Someone should bring up the webserver or let the URL point to a webserver that is up.
>Release-Note:
>Audit-Trail:
>Unformatted:
- 5
- Download a webpage that contains javascriptI am trying to download the html page at
http://www.dreamteamfc.com/dtfc04/servlet/PostPlayerList?catidx=1
Using the code
public class DownloadWebPage
{ public static void main (String[] args) throws IOException
{
URL url = new
URL("http://www.dreamteamfc.com/dtfc04/servlet/PostPlayerList?catidx=1");
BufferedReader webRead = new BufferedReader(new
InputStreamReader(url.openStream()));
String line;
while ((line = webRead.readLine()) != null)
{
System.out.println(line);
}
}
}
But all I am getting is
<HTML><HEAD><SCRIPT
LANGUAGE="JAVASCRIPT">location.replace("http://www.dreamteamfc.com");</SCRIPT></HEAD></HTML>
I'm guessing that when the web brower meets this code it executes the
javascript
location.replace("http://www.dreamteamfc.com")
And somehow loads the web page.
How do I go about downloading the actual web page that gets displayed
in a normal web browser.
Any help appeciated!
pat
- 5
- changing code while program is runningHello,
I would like to have my class code loaded into application, which is
already running. I tried something like this:
public class Main
{
...
private void reloadClass() throws Exception
{
new Pair("","").print(); //class to be reloaded
System.in.read (); //interval - here comes manual class recompilation
ClassLoader.getSystemClassLoader ().loadClass ("Pair"); //reload class
new Pair("","").print(); //check if new version loaded
}
}
It seems that ClassLoader.loadClass checks the presence of the Pair
class in memory and doesn't relod it. How to omit it?
regards
blacky
- 7
- 7
- Vetoing a change by DefaultCellEditor in JTableI'm using a DefaultCellEditor with a JTextField to capture a String
that is ultimately passed to setValueAt in my TableModel. In that
method, I have logic which could throw an exception if the String's
contents proves to be invalid (i.e. one use is where the String is a
regular expression that might be syntactically invalid).
How can I handle this? Right now, the code throws an Exception which
I'd like to catch, display a dialog, and then return the user to
editing without ever committing the value. Is this easily doable?
Regards,
Brian.
- 10
- Removing Item From JList - getSelectedIndex problemHi all,
I am currently working on a JList that populates data into a JList
from a CSV file. I have a button that is supposed to get the Selected
index and then delete that item from the JList. Below is the code that
I am using:
int index = lstComputerExceptions.getSelectedIndex();
System.out.println("index is: " + index);
model.remove(0);
int size = model.getSize();
if (size == 0) { //Nobody's left, disable firing.
btnDelete.setEnabled(false);
} else { //Select an index.
if (index == model.getSize()) {
//removed item in last position
index--;
}
lstComputerExceptions.setSelectedIndex(index);
lstComputerExceptions.ensureIndexIsVisible(index);
}
I have printed out what index is and no matter what item I have in the
Jlist I have selected it will always print out
-1. Therefore keeps on causing my program to crash and not delete the
item out of the Jlist.
Any help in this matter would be highly appreicated.
Thank you
- 10
- JNI: passing Objects containing non-primitive types back and forthHi folks,
looked through a lot a threads overhere already but did not find an
answer detailed enough:
I want to map a c-structure like this created in my native code
struct mystruct {
long pid ;
long data[] ;
long meta[][] ;
} ;
to a java-object within my Java-code which would look like this IMHO:
public class ComplexData {
final int maxdata = 100 ;
final int maxmeta = 5 ;
private long pid ;
private data[] = new long[maxdata] ;
private meta[][] = new long[maxdata][maxmeta] ;
public void ComplexData() {
// Assigning values
pid = 1234 ;
data[0] = ...
}...
As far as I understood it is now possible to pass this Java-object to
the native code using the JNI-Function NewObject and read the members
and assign their values to the c-structure's members (to make them
available from within c) and the other way round, assign the values
from the c-structure to the members within the Java-object (possibly
without the initialization in the "Java-world" (I need both
directions).
My problem now is: How do I access the object's members (especially
the array types) from within c? Functions pointed to in different
threads (e.g. (Get|Set)LongArrayRegion ) need the reference to the
array, but I have only the reference to the object up to now.
Any code snippets based on the code above would be helpful.
Cheers
Bernd
- 11
- Recognize Windows ShutdownHi,
how can i recognize that Windows is shutting down (when i'm logged off)?
Sorry for stupid questions, but i didn't found the right solution!
Greets,
Nico
-> remove the underscores in the email <-
- 11
- newbie java/OOP questionPerhaps someone here can help me with this, I tried asking someone else
about this but couldn't quite describe my question.
I understand that this syntax calls a method on behalf of an object:
b1.method();
but in some java example code I see stuff like this (from a link list app) :
answer.head = IntNode.listCopy(head);
I know that "head" is an instance variable of the class, specfically an
IntNode. I also know that "answer" is a method variable of the type
IntLinkedBag.
My question is: what the heck is going on during the "answer.head"
operation? I don't understand how answer is interacting with head.
They're just two objects. What does the period do when it connects two
objects?
Any pointers or keywords to look up would be apprecited.
--
Mike
Block Banner Ads Now
http://everythingisnt.com/hosts.html
- 12
- Help needed (GUI/passing objects)
Hi, I'm a student learning java. In my latest assignment, I am to create a
Scheduler/Diary, with a GUI.
I am getting the error
Exception in thread "main" java.lang.NoSuchMethodError: BaseFrame: method
<init>
()V not found
at Dairy.main(Dairy.java:22)
From the main method in 'project.class', I create the diary object, which
creates month and day objects etc...
I create a state object, which takes in the Diary Object and points to the
selected month, day, appointment etc
I then create a gui object, which is to change the state (through methods in
the state).
This error occurs whenever I pass in the state object to the GUI
('BaseFrame').
Exception in thread "main" java.lang.NoSuchMethodError: BaseFrame: method
<init>
()V not found
at Dairy.main(Dairy.java:22)
I'm not sure whats causing this. I'm checking like 22 in the 'diary' class,
but it's a }. Not too helpful.
GUI appears when no state object is passed, can't manipulate the data with
that though....
In main:
------------
//set up the Diary
Diary dia = new Diary();
//set up the state
State diaryState = new State(dia);
//Set up the gui
BaseFrame firstFrame = new BaseFrame(diaryState);
---------------
When setting up the GUI:
---------------
State curState;
//constructor for the basic frame, takes in a state object
public BaseFrame(State sta)
{
curState = sta;
.....................}
--------------------------
Done a search online, didn't get too far. Any ideas? What does that error
mean exactly?
- 13
- Implementing inheritance in JAVAHi,
I am a naive JAVA user. Can you please tell me, oh how to implement
the following scenario
A
^ ^
/ \
B C
^ ^
\ /
D
Classes B and C extends class A, but how to define class D, such that
members of both B and C are available to D.
Thanks
>> manjunath
- 15
- Welcome Back Roedy Green!Have you been back for awhile? (Maybe I'm just stupid!)
I was . . surprised to see a post from you
:)
- 16
- 16
- JDO nad MYSQLHello.
Im looking form examples usage JDO (opensource) to MYSQL. It's possible to
it ???
Where can I find it ???
Thanks for Your help
E.N
|
| Author |
Message |
gmalicki

|
Posted: 2006-8-22 8:59:00 |
Top |
java-programmer, Java FACT ?
"FACT: Java has no first-class functions and no macros. This results in
warped code that hacks around the problem, and as the code base grows,
it takes on a definite, ugly shape, one that's utterly unique to Java.
Lisp people can see this clear as day. So can Python folks, so can Ruby
folks. Java people flip out, and say "macros are too much power",
or "what do u mean i dont understand u" or "fuck you, you jerk,
Lisp will NEVER win". -- Steve Yegge, 2006-04-15
what would you people make of the above statement ? Has anyone here
used Lisp *and* Java on major projects ? If so would you say this
sounds off-base or correct ?
thanks,
--dcnstrct
|
| |
|
| |
 |
Otis Bricker

|
Posted: 2006-8-22 10:24:00 |
Top |
java-programmer >> Java FACT ?
email***@***.com wrote in news:1156208333.854786.117810
@p79g2000cwp.googlegroups.com:
> "FACT: Java has no first-class functions and no macros. This results in
> warped code that hacks around the problem, and as the code base grows,
> it takes on a definite, ugly shape, one that's utterly unique to Java.
> Lisp people can see this clear as day. So can Python folks, so can Ruby
> folks. Java people flip out, and say "macros are too much power",
> or "what do u mean i dont understand u" or "fuck you, you jerk,
> Lisp will NEVER win". -- Steve Yegge, 2006-04-15
>
>
> what would you people make of the above statement ?
Flame bait by a potty mouth?
He makes a grossly wide statement about java coding and then creates a
fictional Java programmer he can make look myopic.
> Has anyone here
> used Lisp *and* Java on major projects ? If so would you say this
> sounds off-base or correct ?
>
>
Lisp is a fine tool. Java is a fine tool. C++ is a fine tool. Even Python
can be a fine tool. Sense a pattern? They are tools not religions! First-
clas function(and Objects) are nice. So are Closures. But you can get by
without them. It is just easier when you don't have too.
Pick the one your can do the current one the best in. Note that I did n't
say the best one for the job. If you do not know functional programming,
learn one but that might not be the best way to tackle a project.
C and C++ have done fine up to now lacking FCF. Java does have anonymous
and inner classes that fill a small but significant part of the need.
you need to pick the right tool for a job and as the saying goes, its a
poor craftsman who blames his tools.
OB
|
| |
|
| |
 |
No Name

|
Posted: 2006-8-22 12:57:00 |
Top |
java-programmer >> Java FACT ?
email***@***.com wrote:
> what would you people make of the above statement ? Has anyone here
> used Lisp *and* Java on major projects ? If so would you say this
> sounds off-base or correct ?
Who cares? This is typical academic wanking. Wanking by eggheads who
have never written a real-world program. No first class functions?
First class my ass.
|
| |
|
| |
 |
The Ghost In The Machine

|
Posted: 2006-8-22 22:00:00 |
Top |
java-programmer >> Java FACT ?
In comp.lang.java.advocacy, email***@***.com
<email***@***.com>
wrote
on 21 Aug 2006 17:58:53 -0700
<email***@***.com>:
> "FACT: Java has no first-class functions and no macros.
I'm not sure what a first-class function is, but assuming
it's a function in the global namespace I for one would
think such unnecessary, as long as one knows the relevant
namespace. For example, Math.cos() is acceptable if
one knows where Math is -- and that's what documentation
is for.
As for macros -- one can hack around that lack, if lack
it be, in various ways; the standard one nowadays would
be m4. However, most usages of macros are better served
by functions. I'll admit that Lisp's ideas of macros is
not something I'm that familiar with beyond the fact that
they don't allow C macro abuses.
I'm mildly surprised the individual did not mention
the elephant in the room: operator overloading, along
with the issue of Java's primitive/Object dichotomy.
The former leads to constructs that get unwieldly, though
it's a tradeoff. The latter is an annoyance to purists
but most people shrug it off.
An apply() taking an arbitrary function call would be nice.
The closest I can get is something along the lines of
List apply(Collection c, Method m, Object[] extraparams)
throws Exception
{
List results = new ArrayList();
for(Iterator i = c.iterator();i.hasNext();)
{
results.append(m.invoke(i.next(), extraparams));
}
return results;
}
This looks workable but cumbersome, and is probably slow.
At that, Java is an improvement over C/C++, which has used
various methods to attempt what Lisp does almost naturally.
However, C++ has the advantage of templates, which allows
for STL's for_each() construct:
template <typename Q, /* ... */ >
class arbFunc
{
public:
void operator()(Q q) { /* ... */ }
}
arbFunc</*...*/> func(/*... */);
std::for_each(ibegin, iend, func);
Slightly cumbersome but powerful if used properly. Of
course most would probably just use the for loop instead:
for(/*...*/::iterator i = begin; i != end; i++)
func(*i, /* ... */);
so one gets a for loop "pepper" effect.
There's also the null versus "" versus "0" trichotomy. This
can lead to some weird-looking code:
void processArgs(String[] args)
{
if(args != null) for(int i = 0; i < args.length; i++)
{
if(args[i] != null && args[i].equals("-help"))
{
/* ... */
}
if(!"-help".equals(args[i]))
{
/* ... */
}
}
}
The first is straightforward but awkward. The second is slightly
unnatural, although logical enough.
As for "0": one might make a case that
void routine(String s) { int x = s; /* ... */ }
makes sense (e.g., PL/1); in Java one has to go through various
gyrations:
void routine(String s) {
int x;
if(s == null) x = 0;
else if (s.equals("")) x = 0;
else try {
x = Integer.parseInt(s);
}
catch(ParseException e)
{
x = 0;
System.out.println("Error: " + e.getClass().getName() + ": "
+ e.getMessage());
}
/* ... */
}
> This results in
> warped code that hacks around the problem,
An example of such "warped code" would be nice.
> and as the code base grows,
> it takes on a definite, ugly shape, one that's utterly unique to Java.
> Lisp people can see this clear as day. So can Python folks, so can Ruby
> folks. Java people flip out, and say "macros are too much power",
> or "what do u mean i dont understand u" or "fuck you, you jerk,
> Lisp will NEVER win". -- Steve Yegge, 2006-04-15
>
>
> what would you people make of the above statement ? Has anyone here
> used Lisp *and* Java on major projects ? If so would you say this
> sounds off-base or correct ?
It's off-base but not that off. Still, which language is winning?
It's not Smalltalk or LISP. Maybe next iteration as computers
continue to increase in power. I don't know at this point. :-)
>
>
> thanks,
> --dcnstrct
>
--
#191, email***@***.com
Windows Vista. Because it's time to refresh your hardware. Trust us.
|
| |
|
| |
 |
ram

|
Posted: 2006-8-22 23:03:00 |
Top |
java-programmer >> Java FACT ?
The Ghost In The Machine <email***@***.com> writes:
>I'm not sure what a first-class function is,
"First-class sometjing" means that "something" is a value.
I.e., you can return it from a method or assign it to a
variable.
Actually objects are not values in Java, but references are,
which often can be regarded as the object they represent.
So "first-class function" can also be fulfilled by transparent
function /references/.
For example, with function values you can write:
f = g;
y = f( x );
or
m( i )( x )
, when 籱?is a method returning a function of (at least)
one argument.
>but assuming it's a function in the global namespace I for one
>would think such unnecessary, as long as one knows the relevant
>namespace.
Values by themselves are anonymous and thus the notion
is independent of namespaces. However, there is a connection
insofar as values usually can be bound to names.
Values are run-time entities, names are source-code entities.
>As for macros -- one can hack around that lack, if lack
Here is an example, where I use macro to emulate a kind of
first-class function objects.
My Java-program following below in the style of functional
programming shows how to implement and use an 籥pply?
operation that will take a collection 籧? filter it by a
predicate, such as
PREDICATE( java.lang.String, e, e.indexOf( 'e' )> 0 )
and then send the values passed to an arbitrary operation like
ACCEPT( java.lang.String, s, java.lang.System.out.println( s ); )
It could be written without macros, they just server to
make it more readable (or "less" readable, as some might say).
Sun should have defined interfaces such as "Function" and
"Predicate" long ago to support interoperability between
different Java libraries preferring such a style.
This style, passing parametrized blocks (in other words:
"first-class functions"), by the way, is inherent to /object
oriented programming/ -- not only functional programming. That
means "object oriented programming" in the original sense (the
Smalltalk-sense), see:
http://daitanmarks.sourceforge.net/or/squeak/squeak_tutorial-2.html
------------ cut here
interface Function<Range,Domain>{ Range of( Domain value ); }
interface Predicate<Domain> extends Function<java.lang.Boolean,Domain> {}
--- PREDICATE
--- a predicate object representing a predicate of one parameter
--- @param $1 The type of the parameter of this predicate
--- @param $2 The name of the parameter of this predicate
--- @param $3 The value of this predicate for the parameter
$define PREDICATE new Predicate<$1>()
{ public java.lang.Boolean of( final $1 $2 )
{ return $3; }}
interface Accept<O>{ void accept( O object ); }
--- ACCEPT
--- an acceptor object acception an argument
--- @param $1 The type of the parameter of this acceptor
--- @param $2 The name of the parameter of this predicate
--- @param $3 The statements of this acceptor
$define ACCEPT new Accept<$1>()
{ public void accept( final $1 $2 ){ $3; }}
public class Main
{
public static <E> void apply
( final java.util.Collection<E> c, final Predicate<E> p, final Accept<E> acceptor )
{ for( final E e : c )if( p.of( e ))acceptor.accept( e ); }
public static void main( final java.lang.String[] commandLineArguments )
{ final java.util.Collection<java.lang.String> c =
java.util.Arrays.asList( "alpha", "beta", "gamma", "delta" );
apply( c, PREDICATE( java.lang.String, e, e.indexOf( 'e' )> 0 ),
ACCEPT( java.lang.String, s, java.lang.System.out.println( s ); )); }}
beta
delta
|
| |
|
| |
 |
ram

|
Posted: 2006-8-22 23:11:00 |
Top |
java-programmer >> Java FACT ?
email***@***.com (Stefan Ram) writes:
>public static <E> void apply
>( final java.util.Collection<E> c, final Predicate<E> p, final Accept<E> acceptor )
>{ for( final E e : c )if( p.of( e ))acceptor.accept( e ); }
In the context of a superclass, where the predicate and
acceptor are supplied by a subclass, this would be called
"templated method pattern".
I am not sure what it is in the way it stands there.
Possibly, the "strategy pattern"
I do not know these patterns well, but from the few things
I know, I might say that the strategy pattern is the
template method pattern without the use of inheritance.
|
| |
|
| |
 |
ram

|
Posted: 2006-8-22 23:47:00 |
Top |
java-programmer >> Java FACT ?
email***@***.com (Stefan Ram) writes:
> For example, with function values you can write:
>f = g;
>y = f( x );
> or
>m( i )( x )
While C is usually not considered to be a functional
language, this can be written in C:
#include <stdio.h>
int f0( int const x ){ return 2 * x; }
int f1( int const x ){ return 3 * x; }
int( *g( int const x ))( int const x ){ return x > 0 ? f0 : f1; }
int main( void ){ printf( "%d", g( 1 )( 2 )); }
4
C even allows the definition of a function "returning
itself":
#include <stdio.h>
void * f( int const x ){ return f; }
int main( void )
{ printf( "%d\n", f );
printf( "%d\n", f( 0 )); }
268440528
268440528
|
| |
|
| |
 |
The Ghost In The Machine

|
Posted: 2006-8-23 1:00:00 |
Top |
java-programmer >> Java FACT ?
In comp.lang.java.advocacy, Stefan Ram
<email***@***.com>
wrote
on 22 Aug 2006 15:03:02 GMT
<email***@***.com>:
> The Ghost In The Machine <email***@***.com> writes:
>>I'm not sure what a first-class function is,
>
> "First-class sometjing" means that "something" is a value.
> I.e., you can return it from a method or assign it to a
> variable.
>
> Actually objects are not values in Java, but references are,
> which often can be regarded as the object they represent.
>
> So "first-class function" can also be fulfilled by transparent
> function /references/.
>
> For example, with function values you can write:
>
> f = g;
> y = f( x );
>
> or
>
> m( i )( x )
>
> , when 籱?is a method returning a function of (at least)
> one argument.
If one is going to go that route one will also need lambda
closures. From what little I understand thereon, in Java
one would have to have a syntactic construct that might
look like
Closure f = obj.g(k,<1>,<2>);
as a local variable. f would then require two parameters
and look much like a function call. k would have the same
restrictions as passed-down members/final locals in anonymous
classes do today.
Other syntactical possibilities ensue; for example, one
might simply declare closure as a primitive keyword type,
and have it act much like a function or implicit function
pointer:
closure int(String n1, String n2) f = obj.g(k,n1,n2);
There would be two objects in the closure: 'this' and 'obj'.
obj would have to be a final local variable or a member.
In this context a lambda closure with zero passed-down
values would be your "first-class function", I think.
Closures would be reassignable and templatizable, and
of course used as values, leading to some ugly syntax
without typedefs, but one could contemplate something
along the following lines:
int(String k1, String k2)(int k1, int k2) f(String p, int q, int r)
{
}
which would be a function returning a closure taking two
int args, which itself would be a closure taking two
String args, finally returning an int.
One can also pass in closures, in a fairly obvious fashion:
int f(int(String k1, String k2) g, int) { int k = f("x","y"); /* ... */ }
One might also contemplate templatized parameters, though
I'm not sure what the exact syntax would look like, though
the following might work:
template <T> int f(int(T k1, T k2) g, int) { /* ... */ }
or
int f(template<T> int(T k1, T k2) g, int) { /* ... */ }
The main issue is proper scoping of T within the function block.
In the former, a call might look like
f<int>(g, 2);
but in the latter a call would have to be
f(g<int>, 2);
if g is a templatized closure, and
f(g, 2);
if g is not.
>
>>but assuming it's a function in the global namespace I for one
>>would think such unnecessary, as long as one knows the relevant
>>namespace.
>
> Values by themselves are anonymous and thus the notion
> is independent of namespaces. However, there is a connection
> insofar as values usually can be bound to names.
>
> Values are run-time entities, names are source-code entities.
>
>>As for macros -- one can hack around that lack, if lack
>
> Here is an example, where I use macro to emulate a kind of
> first-class function objects.
If one has true first-class functions why use macros at all?
>
> My Java-program following below in the style of functional
> programming shows how to implement and use an 籥pply?
> operation that will take a collection 籧? filter it by a
> predicate, such as
>
> PREDICATE( java.lang.String, e, e.indexOf( 'e' )> 0 )
boolean(String, int) v = /* ... */;
if(v("abc", def)) { /* ... */ }
>
> and then send the values passed to an arbitrary operation like
>
> ACCEPT( java.lang.String, s, java.lang.System.out.println( s ); )
See e.g. java.io.FileFilter for an interface that
can accomplish a similar task. The syntax is admittedly
not as clean, though.
>
> It could be written without macros, they just server to
> make it more readable (or "less" readable, as some might say).
The main problem I have with macros is that they scramble things.
Properly used, they can clarify a program greatly. Improperly,
well, you're no doubt aware of the C Obfuscation contest; some
of the entries are ... interesting. :-)
>
> Sun should have defined interfaces such as "Function" and
> "Predicate" long ago to support interoperability between
> different Java libraries preferring such a style.
>
> This style, passing parametrized blocks (in other words:
> "first-class functions"), by the way, is inherent to /object
> oriented programming/ -- not only functional programming. That
> means "object oriented programming" in the original sense (the
> Smalltalk-sense), see:
>
> http://daitanmarks.sourceforge.net/or/squeak/squeak_tutorial-2.html
>
> ------------ cut here
A codeblock could be a closure as well, and in fact a function
could be construed as a readonly closure followed by its codeblock.
void process(boolean(String p1, int p2) p, int v)
{
if(p("Test 1", v)) { /* ... */ }
}
and then one might call this with:
process( { return false; }, 2)
or, if one needs to reference the parameters for some reason,
one can use a rather ugly cast:
process( (boolean(String p1, int p2)) { return p1.equals("Duh"); }, 2)
The advantages of this particular notation over anonymous
classes implementing interface are not entirely clear;
in Java, one could simply declare:
interface Q { public boolean predicate(String p1, int p2); }
void process(Q q, int v) { if(q.predicate("Test 1", v) { /* ... */ } }
process(new Q() {
public boolean predicate(String p1, int p2) { /* ... */ }
}, 2);
>
> interface Function<Range,Domain>{ Range of( Domain value ); }
> interface Predicate<Domain> extends Function<java.lang.Boolean,Domain> {}
>
> --- PREDICATE
> --- a predicate object representing a predicate of one parameter
> --- @param $1 The type of the parameter of this predicate
> --- @param $2 The name of the parameter of this predicate
> --- @param $3 The value of this predicate for the parameter
> $define PREDICATE new Predicate<$1>()
> { public java.lang.Boolean of( final $1 $2 )
> { return $3; }}
>
> interface Accept<O>{ void accept( O object ); }
>
> --- ACCEPT
> --- an acceptor object acception an argument
> --- @param $1 The type of the parameter of this acceptor
> --- @param $2 The name of the parameter of this predicate
> --- @param $3 The statements of this acceptor
> $define ACCEPT new Accept<$1>()
> { public void accept( final $1 $2 ){ $3; }}
>
> public class Main
> {
> public static <E> void apply
> ( final java.util.Collection<E> c, final Predicate<E> p, final Accept<E> acceptor )
> { for( final E e : c )if( p.of( e ))acceptor.accept( e ); }
>
> public static void main( final java.lang.String[] commandLineArguments )
> { final java.util.Collection<java.lang.String> c =
> java.util.Arrays.asList( "alpha", "beta", "gamma", "delta" );
> apply( c, PREDICATE( java.lang.String, e, e.indexOf( 'e' )> 0 ),
> ACCEPT( java.lang.String, s, java.lang.System.out.println( s ); )); }}
>
> beta
> delta
>
--
#191, email***@***.com
Windows Vista. Because it's time to refresh your hardware. Trust us.
|
| |
|
| |
 |
The Ghost In The Machine

|
Posted: 2006-8-23 1:00:00 |
Top |
java-programmer >> Java FACT ?
In comp.lang.java.advocacy, Stefan Ram
<email***@***.com>
wrote
on 22 Aug 2006 15:47:24 GMT
<email***@***.com>:
> email***@***.com (Stefan Ram) writes:
>> For example, with function values you can write:
>>f = g;
>>y = f( x );
>> or
>>m( i )( x )
>
> While C is usually not considered to be a functional
> language, this can be written in C:
C++, perhaps, unless C now accepts the construct
int m(int, int);
int (*p)(int, int);
m = p;
p(1,2);
which last I checked it didn't but that was awhile ago;
one must use
(*p)(1,2);
(C++ has no problem with it.)
>
> #include <stdio.h>
>
> int f0( int const x ){ return 2 * x; }
> int f1( int const x ){ return 3 * x; }
>
> int( *g( int const x ))( int const x ){ return x > 0 ? f0 : f1; }
>
> int main( void ){ printf( "%d", g( 1 )( 2 )); }
>
> 4
>
> C even allows the definition of a function "returning
> itself":
>
> #include <stdio.h>
>
> void * f( int const x ){ return f; }
> int main( void )
> { printf( "%d\n", f );
> printf( "%d\n", f( 0 )); }
>
> 268440528
> 268440528
>
But C does *not* allow:
int f(int, int);
int g(int, int);
int h(int, int);
h = flag ? f : g;
h(1,2);
though one can work around it in C++ with an ugly pointer:
int (*h)(int, int);
h = flag ? f : g;
h(1,2);
This is mostly because
int f(int, int) { ... }
is vaguely similar to
int (*f const)(int, int) = { ... };
although the latter is not proper C++. In assembly, f would
be considered an immobile label.
C/C++ arrays are also labels; Pascal allows
type tarray: array[1..10] of integer;
var a: tarray; b: tarray;
begin
a := b;
end.
but trying to do similar things in C++ will not work:
typedef int ary[10];
ary a, b;
int main() { a = b; return 0; }
test.C:3: error: ISO C++ forbids assignment of arrays
--
#191, email***@***.com
Windows Vista. Because it's time to refresh your hardware. Trust us.
|
| |
|
| |
 |
ram

|
Posted: 2006-8-23 1:15:00 |
Top |
java-programmer >> Java FACT ?
The Ghost In The Machine <email***@***.com> writes:
>C++, perhaps, unless C now accepts the construct
It does since 1989:
籈xcept when it is the operand of the sizeof operator
or the unary & operator, a function designator with type
``function returning type '' is converted to an expression
that has type ``pointer to function returning type .''?
(ANSI C 1989)
So, in
printf( "\n" )
the function designator is implicitly converted to a pointer
to a function.
|
| |
|
| |
 |
Tor Iver Wilhelmsen

|
Posted: 2006-8-23 1:23:00 |
Top |
java-programmer >> Java FACT ?
email***@***.com writes:
> what would you people make of the above statement ? Has anyone here
> used Lisp *and* Java on major projects ? If so would you say this
> sounds off-base or correct ?
It's off-base because what he's really attacking is objects, and
reliability, both of which - in the context of Java -
functions-as-objects and silly macro stuff would negate: What would be
the point of class A calling a method of class B without the context
of class B?
Java "solves" the first problem via the Strategy, Command and other
patterns, like any proper OO language would. The second "problem" -
macros as Lisp understands the concept - is in effect code "compiled"
at evaluation time, which is a big no-no in Java.
I think the quoted bit is - like 99% of all articles attacking Java -
a tirade written by someone envious of how Java stole the thunder of
their pet language, whether it's Lisp, Smalltalk, Prolog, Beta, C++,
Objective-C, C+@, D, Ocaml, Haskell, C#....
For Lisp, you could also say Python and Ruby stole its thunder. There
are no more avenues left to conquer for such academic niche pets.
|
| |
|
| |
 |
ram

|
Posted: 2006-8-23 1:24:00 |
Top |
java-programmer >> Java FACT ?
The Ghost In The Machine <email***@***.com> writes:
>C++, perhaps, unless C now accepts the construct
>int m(int, int);
>int (*p)(int, int);
>m = p;
>p(1,2);
>which last I checked it didn't but that was awhile ago;
>one must use
>(*p)(1,2);
[Superseding:]
It does not support assignment to function names, but one
does not need to use the dereference operator "*" in a call,
since about 1989:
籈xcept when it is the operand of the sizeof operator
or the unary & operator, a function designator with type
``function returning type '' is converted to an expression
that has type ``pointer to function returning type .''?
(ANSI C 1989)
So, in
printf( "\n" )
the function designator is implicitly converted to a pointer
to a function.
|
| |
|
| |
 |
ram

|
Posted: 2006-8-23 3:25:00 |
Top |
java-programmer >> Java FACT ?
The Ghost In The Machine <email***@***.com> writes:
>If one is going to go that route one will also need lambda
>closures.
Here is what Sun said a few years ago with regard to
delegates:
籘he newest version of the Microsoft Visual J++
development environment supports a language construct
called delegates or bound method references. (...)
It is unlikely that the Java programming language will
ever include this construct. Sun already carefully
considered adopting it in 1996, to the extent of building
and discarding working prototypes. Our conclusion was that
bound method references are unnecessary and detrimental to
the language. (...)
We believe bound method references are unnecessary because
another design alternative, inner classes, provides equal
or superior functionality.?
http://java.sun.com/docs/white/delegates.html
And Guy Steele wrote this about closures in Java:
籄ctually, the prototype implementation *did* allow
non-final variables to be referenced from within inner
classes. There was an outcry from *users*, complaining
that they did not want this! The reason was interesting:
in order to support such variables, it was necessary to
heap-allocate them, and (at that time, at least) the
average Java programmer was still pretty skittish about
heap allocation and garbage collection and all that. They
disapproved of the language performing heap allocation
"under the table" when there was no occurrence of the
"new" keyword in sight.?
http://madbean.com/2003/mb2003-49/
And here is what they say now:
http://blogs.sun.com/roller/resources/ahe/closures.pdf
I.e., they might indeed consider them for a future release.
>[...]
>if g is a templatized closure, and
>f(g, 2);
>if g is not.
(Thanks for your interesting remarks about how closures might
be merged into Java.)
>>Here is an example, where I use macro to emulate a kind of
>>first-class function objects.
>If one has true first-class functions why use macros at all?
Right now, I do not have first-class functions yet.
|
| |
|
| |
 |
Lion-O

|
Posted: 2006-8-23 3:25:00 |
Top |
java-programmer >> Java FACT ?
> "FACT: Java has no first-class functions and no macros."
I had to do some reading up on all this because at first I didn't fully grasp
what was meant with macro's. So a google gave me a nice page
(http://www.apl.jhu.edu/~hall/Lisp-Notes/Macros.html) and from what I make out
of that page I think he's wrong.
A few quotes: "Macros in Lisp provide a very powerful and flexible method of
extending Lisp syntax.", and: "'(defmacro Square (X) \ '(* ,X ,X))' This means
that wherever the pre-processor sees (Square XXX) to replaces it with (* XXX
XXX). The resultant code is what the compiler sees." (no '' and \ means cr/lf).
Isn't this basicly what a plain method does? If I wish to extend my Java syntax
(and I do) I can easily write packages of my own which to do just that. And
Java makes writing and using your own packages (or perhaps "extensions"?)
extremely easy, this goes double when using IDE's like Netbeans. Heck, one of
the first things I did when I started out with Java was creating a project
"catslair tools" consisting of packages like org.catslair.cli and
org.catslair.gui which, as the name denotes, classes to help me with cli or gui
based issues.
Need to grab input from stdin?
import org.catslair.cli.GetInput;
...
String userinput = ReadInput();
(ps: I know; 'readInput()' would have been a better name for the method, but
when I wrote this up I hadn't read about naming conventions yet).
Second; 'first class functions'. That was a little harder for me to grok, but I
ended up on the Lisp site itself
(http://www.lisp.org/table/glossary.htm#first-class) and from what I can make
out of that I wonder if Java's annotations aren't very much alike here. This is
confusing for me, but when I look at the description: "A language supports some
data type as first-class when the objects of the type can be created and used
as data at run time." and considering how everything in Java is defined as an
object I think his point isn't valid. Granted: I have little to no experience
on the Lisp front but it would seem that there isn't really much difference.
> This results in warped code that hacks around the problem, and as the code
> base grows, it takes on a definite, ugly shape, one that's utterly unique to
> Java. Lisp people can see this clear as day. So can Python folks, so can Ruby
> folks.
I'd really like to know what the problem is then. IMO there is absolutely no
need what so ever for any "warps" to "overcome this problem" simply because as
far as I can see the problem isn't even there.
When looking at my above example to "extend the Java syntax" you'll see its
nothing out of the ordinary. This is basicly common Java programming.
> what would you people make of the above statement ?
I think he has clue when it comes to Java. If the comments he quoted are indeed
from Java programmers then I have a hunch that they too saw that he's trying to
argue and present problems which simply aren't there. And considering the tone
of his whole argument I can understand if some people get annoyed about it.
--
Groetjes, Peter
.\\ PGP/GPG key: http://www.catslair.org/pubkey.asc
|
| |
|
| |
 |
gmalicki

|
Posted: 2006-8-23 3:51:00 |
Top |
java-programmer >> Java FACT ?
Tor Iver Wilhelmsen wrote:
> email***@***.com writes:
>
> > what would you people make of the above statement ? Has anyone here
> > used Lisp *and* Java on major projects ? If so would you say this
> > sounds off-base or correct ?
>
> It's off-base because what he's really attacking is objects, and
> reliability, both of which - in the context of Java -
> functions-as-objects and silly macro stuff would negate: What would be
> the point of class A calling a method of class B without the context
> of class B?
I don't think he's attacking objects. For one he's promoting Common
Lisp which has an Object system which in my opinion is better(more
flexible) than java's. He also mentions Ruby which is a completely OO
language. Ruby has these first class functions(closures) and puts them
to good use without giving up its object orientated nature.
> Java "solves" the first problem via the Strategy, Command and other
> patterns, like any proper OO language would.
In Java, you can use the Command design pattern for example to ensure
the opening and closing of a file, database transaction, or other
resource. The problem is that this burdens the code with the useless
overhead of an anonymous inner class and callback method; in addition,
there is the distracting rule that variables passed into the anonymous
Command class must be declared final. And to ensure that logic always
executes at the end of a code block, the whole thing must be wrapped
with try{...}finally{...}.
In Ruby or other languages with first-class-functions, you can wrap any
function or code block, with no need for anonymous classes or method
definitions. In the following example the file opens, then closes
after the write() method. No code is needed beyond the "transaction"
method and the code block
File.open("out.txt", "a") {|f|
f.write("Hello")
}
This code is super sleek compared to what you would have to do in java
to achieve this same behavior. The lisp code is for this is not much
larger than the Ruby code. First class functions save the day, they
keep code smaller and easier to understand and maintain.
> The second "problem" -
> macros as Lisp understands the concept - is in effect code "compiled"
> at evaluation time, which is a big no-no in Java.
Sure its a big no-no in java, I think thats what Steve Yeggie is trying
to say. Java is less powerful because you cannot create code that
expands to other code like you can in Lisp.
> I think the quoted bit is - like 99% of all articles attacking Java -
> a tirade written by someone envious of how Java stole the thunder of
> their pet language, whether it's Lisp, Smalltalk, Prolog, Beta, C++,
> Objective-C, C+@, D, Ocaml, Haskell, C#....
Sure no doubt he's envious, but does that mean the things he says about
java are incorrect ? I don't think so.
> For Lisp, you could also say Python and Ruby stole its thunder. There
> are no more avenues left to conquer for such academic niche pets.
Pretty much all of the super cool stuff in Ruby came over from Lisp
(and some from smalltalk). This got me interested in Lisp. I've
discovered that lisp provides super useful stuff (like macros) that
even Ruby lacks, and Lisp is a hell of alot faster!
--dcnstrct
|
| |
|
| |
 |
ram

|
Posted: 2006-8-23 4:07:00 |
Top |
java-programmer >> Java FACT ?
Lion-O <email***@***.com> writes:
>Isn't this basicly what a plain method does?
Macros can build new syntax trees without evaluating their
arguments. For example, assume you find yourself often writing
something like:
try
{ javax.swing.SwingUtilities.invokeAndWait
( new java.lang.Runnable()
{ public void run(){ g0.setColor( java.awt.Color.ORANGE ); }});}
catch( final java.lang.InterruptedException interruptedException )
{ throw new java.lang.RuntimException ( interruptedException ); }
catch( final java.lang.reflect.InvocationTargetException invocationTargetException )
{ throw new java.lang.RuntimException ( invocationTargetException ); }}
Only the part now reading 籫0.setColor( java.awt.Color.ORANGE );?
differs from time to time. You could replace all these lines with a
macro:
INVOKE_AND_WAIT{ g0.setColor( java.awt.Color.ORANGE ); }
I am not sure, whether I would be able to write a method that
serves the same purposes.
Java-aware macro processors exist, like:
http://people.csail.mit.edu/jrb/Projects/java-macros.htm
|
| |
|
| |
 |
Lion-O

|
Posted: 2006-8-23 18:58:00 |
Top |
java-programmer >> Java FACT ?
> Macros can build new syntax trees without evaluating their
> arguments. For example, assume you find yourself often writing
> something like:
>
> try
> { javax.swing.SwingUtilities.invokeAndWait
> ( new java.lang.Runnable()
> { public void run(){ g0.setColor( java.awt.Color.ORANGE ); }});}
> catch( final java.lang.InterruptedException interruptedException )
> { throw new java.lang.RuntimException ( interruptedException ); }
> catch( final java.lang.reflect.InvocationTargetException invocationTargetException )
> { throw new java.lang.RuntimException ( invocationTargetException ); }}
>
> Only the part now reading 籫0.setColor( java.awt.Color.ORANGE );?
> differs from time to time. You could replace all these lines with a
> macro:
>
> INVOKE_AND_WAIT{ g0.setColor( java.awt.Color.ORANGE ); }
Now, I have read this very carefully many times and think I finally get the
whole idea. However it does raise another question with me: doesn't this
basicly allow for the "hideous spaghetti like" code the OP's quote referred to,
but simply presents a method to better masquerade it?
I've seen it happening in Java quite a few times that I used almost the same
routine. In those cases I resort to recursing and, if needed, making the
routine in question more modulair. I think thats a whole better approach than
to merely use some macro language to copy the entire routine around your entire
program wherever you need it.
/unless/ ofcourse we're not talking about actually copying the entire stuff but
treating it like a "sort of method". Still, even then I can't picture any
situation which would make this approach feasible.
--
Groetjes, Peter
.\\ PGP/GPG key: http://www.catslair.org/pubkey.asc
|
| |
|
| |
 |
Tim Smith

|
Posted: 2006-8-24 8:18:00 |
Top |
java-programmer >> Java FACT ?
In article <email***@***.com>, The Ghost In The Machine wrote:
>> "FACT: Java has no first-class functions and no macros.
>
> I'm not sure what a first-class function is, but assuming
<http://en.wikipedia.org/wiki/First-class_function>:
In computer science, a programming language is said to support first-class
functions if it treats functions as first-class objects. Specifically, this
means that functions can be created during the execution of a program,
stored in data structures, passed as arguments to other functions, and
returned as the values of other functions.
These features are a necessity for the functional programming style, in
which (for instance) the use of higher-order functions is a standard
practice. A simple example of a higher-ordered function is the map or
mapcar function, which takes as its arguments a function and a list, and
returns the list formed by applying the function to each member of the
list. For a language to support map, it must support passing a function as
an argument.
<http://en.wikipedia.org/wiki/First-class_object>:
In computing, a first-class object (also -value, -entity, -citizen), in the
context of a particular programming language, is an entity which can be
used in programs without restriction (when compared to other kinds of
objects in the same language). Depending on the language, this can imply:
* being expressible as an anonymous literal value
* being storable in variables
* being storable in data structures
* having an intrinsic identity (independent of any given name)
* being comparable for equality with other entities
* being passable as a parameter to a procedure/function
* being returnable as the result of a procedure/function
* being constructable at runtime
For example, in C, it is not possible to create new functions at runtime,
whereas other kinds of object can be created at runtime. So functions in C
are not first-class objects; sometimes they are called second-class objects
because they can still be manipulated in most of the above fashions (via
function pointers). Similarly, strings are not first class objects in
FORTRAN 66 as it is not possible to assign them to variables, whereas
numbers can be so assigned.
--
--Tim Smith
|
| |
|
| |
 |
Tim Smith

|
Posted: 2006-8-24 8:21:00 |
Top |
java-programmer >> Java FACT ?
In article <email***@***.com>, The Ghost In The Machine wrote:
> In comp.lang.java.advocacy, email***@***.com
><email***@***.com>
> wrote
> on 21 Aug 2006 17:58:53 -0700
><email***@***.com>:
>
> An apply() taking an arbitrary function call would be nice.
> The closest I can get is something along the lines of
...
> This looks workable but cumbersome, and is probably slow.
> At that, Java is an improvement over C/C++, which has used
> various methods to attempt what Lisp does almost naturally.
Before going down that path, one should first consider Greenspun's Tenth Rule:
Greenspun's Tenth Rule of Programming: any sufficiently complicated C or
Fortran program contains an ad hoc informally-specified bug-ridden slow
implementation of half of Common Lisp.
--
--Tim Smith
|
| |
|
| |
 |
Oliver Wong

|
Posted: 2006-8-28 23:45:00 |
Top |
java-programmer >> Java FACT ?
<email***@***.com> wrote in message
news:email***@***.com...
>
> there is the distracting rule that variables passed into the anonymous
> Command class must be declared final.
I believe on reason the variables must be declared final is to reduce
bugs resulting from the misconception above. You don't actually pass
variables around. You pass the objects that the variables point to. But
people might incorrectly think that the variable itself is being passed
around, and thus expect any changes made to the variable to be visible to
the anonymous class. If the variable is made final, there's no chance for
this error to occur.
- Oliver
|
| |
|
| |
 |
ram

|
Posted: 2006-8-29 0:11:00 |
Top |
java-programmer >> Java FACT ?
"Oliver Wong" <email***@***.com> writes:
>You don't actually pass variables around.
With closures you would do so, when the final-restriction would
not be there. (In Java, "variable" means "storage location")
>You pass the objects that the variables point to.
With the current Java specification one does pass either
primitive or reference values.
>But people might incorrectly think that the variable itself is
>being passed around, and thus expect any changes made to the
>variable to be visible to the anonymous class. If the variable
>is made final, there's no chance for this error to occur.
If there would be no need to declare it final, one would
actually pass the variable itself (as it happens with
"closures" in other languages), so believing in this would
not be an error in this case.
|
| |
|
| |
 |
Oliver Wong

|
Posted: 2006-8-29 3:20:00 |
Top |
java-programmer >> Java FACT ?
"Stefan Ram" <email***@***.com> wrote in message
news:email***@***.com...
> "Oliver Wong" <email***@***.com> writes:
>>You don't actually pass variables around.
>
> With closures you would do so, when the final-restriction would
> not be there. (In Java, "variable" means "storage location")
>
>>You pass the objects that the variables point to.
>
> With the current Java specification one does pass either
> primitive or reference values.
>
>>But people might incorrectly think that the variable itself is
>>being passed around, and thus expect any changes made to the
>>variable to be visible to the anonymous class. If the variable
>>is made final, there's no chance for this error to occur.
>
> If there would be no need to declare it final, one would
> actually pass the variable itself (as it happens with
> "closures" in other languages), so believing in this would
> not be an error in this case.
Perhaps so, but I was speaking of how Java works currently, as opposed
to how Java might work if it had closures.
- Oliver
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Reference and Garbage CollectionI'm not quite sure about what kind of references to an object determine
its "alive" quality and its readiness for garbage collection. For the
moment I understand that *any* living reference, including non-explict
of member classes, keep the object alive.
Would you agree that the follwoing class "NeverRelease" entails
instances which will never get prone to garbage collection?
class NeverRelease
{
Child1 child;
public NeverRelease ()
{
child = new Child1();
}
private class Child1
{
}
}
While would you also agree that instances of the following class
"AlwaysRelease" always become garbage because the member class is static
and hence does not take reference to the enclosing class?
class AlwaysRelease
{
Child2 child;
public AlwaysRelease ()
{
child = new Child2();
}
private static class Child2
{
}
}
- 2
- Is Eclipse the Commercial IDE Killer?Thomas G. Marshall wrote:
> Super Spinner coughed up:
>> Tim Tyler wrote:
>>> In comp.lang.java.advocacy Super Spinner <email***@***.com>
>>> wrote or quoted:
>>>
>>> [Eclipse plugins]
>>>
>>>> I'd say that anyone that came up with an extension wouldn't be able
>>>> to make money because an OSS group would make a knock-off and give
>>>> it away for free.
>>>
>>> Your argument apparently suggests that nobody can make money selling
>>> software. I think history has proven that that is not the case.
>>
>> I think that one can make money by selling software only if the
>> software is "complex", where "complex" means "too complex to be
>> satisfactorily knocked off by OSS". And the set of "complex" sofware
>> becomes smaller and smaller, as OSS commodotizes more and more
>> markets. I used to think that something like Excel was sufficiently
>> complex to be safe from OSS, but I now know that within the next 5
>> years the spreadsheet market will be fully commodotized and therefore
>> not profitable. The same goes for all "office"-type apps. The same
>> goes for Photoshop and the like.
>>
>> The only software that I can see being safe from commodotization is
>> software that requires special domain knowledge, knowledge that devs
>> themselves do not possess and aren't likely to obtain in a competent
>> manner. Something like tax preparation software; this requires expert
>> knowledge of the tax laws and accountants that have such knowledge
>> aren't foolish enough to work for free like software devs appear to be
>> eager to do. So I can't see OSS "winning" in that space (yes, there
>> are OSS tax preparation packages, but the vast majority won't trust
>> that the devs understand the tax laws enough to trust those packages).
>>
>> Now, as for IDE extensions, sorry, there's no way that those are out
>> of the reach of OSS commodotization. Any extension would be knocked
>> off within a year, so the developers of the original would only have
>> one year to recoup the initial investment of resources and I don't see
>> anyone bothering to try. So nearly all future IDE extensions will
>> have to come from OSS from the get-go.
>>
>> A lot of OSS starts life as poor man's versions of commercial software
>> and gradually improves, but as commercial software is killed off, new
>> software inventions will have to come from OSS itself.
>>
>> As for individual programmers, they'll have to make money by working
>> on in-house stuff or custom solutions for a contractor, because it'll
>> be quite difficult to make money selling software to the general
>> public since OSS competition will make such an effort prohibitive.
>
> I have said for a lonnng time that if you write free software, you are
> only
> making it more difficult for other software engineers to earn a living. I
> don't mean small little utilities, like OE_QuoteFix and the like. But
> creating entirely free large scale applications doesn't make you a hero,
> it makes you a villain.
>
There's an easy solution to this. All the "for money" people have to do is
WRITE BETTER software...
I can't believe that projects like Eclipse are doing so well, simply because
they are OSS. It's because they are better...
--
******************************************************************************
Registered Linux User Number 185956
FSF Associate Member number 2340 since 05/20/2004
Join me in chat at #linux-users on irc.freenode.net
Buy an Xbox for $149.00, run linux on it and Microsoft loses $150.00!
7:42pm up 10 days, 4:15, 1 user, load average: 0.05, 0.07, 0.03
- 3
- Image Processing Problem. Need HelpHello, I am writing a web application with Java. There is a function that
user can upload a picture to server, and the server will resize it. I am
using the Java API to do this function. However, the result is not very
satisfactory. The resized image quanlity is very bad.
Can anyone reccommend that any way or tool can resize image with good
quality?
Please help. My boss needs me to complete this project this week.
Regards,
Chris
- 4
- performance and memory usage.
Hi
I created a test program to try the speed and size management of the JDK
HashMap. With regards to this I was wondering if anybody has any
comments on whether this is an appropriate way of testing this
performance, i.e. how realistic is the results with respect to caching
influence of data, heap management etc. The code is simple, but would it
produce a correct result. (the program finishes in 11 seconds on my
machine). the code is attached.
Secondly, I was wondering about the memory (heap) usage in java for this
program. It needs at least 256 MB of heap to run to finish. cmd:
java -Xms32m -Xmx256m -cp target/classes/ App
Using -Xmx128m causes OutOfMemoryError.
When calculating on the size of the datastructure i find approx that
2M Dto's = 16MB
2M Integer's for map key = 8MB
2M Integer's for ArrayList = 8MB
Thats a total of 32MB plus some megabytes for the objects,
datastructures, JVM and so on. So probably about 48-64MB in total.
Thats a completely different number from 128 MB or 256 MB.
Does anybody have any comments on why the program requires that much memory?
arnie
*****************
/* Create 2 million Dto objects with random data and insert into HashMap
also add key to an iterable list */
public void test1() {
int size = 2000000;
Map<Integer, Dto> hmap = new HashMap<Integer, Dto> (size);
Collection<Integer> alist = new ArrayList<Integer> (size);
Random r = new Random();
Dto data;
for (int c=size; c>0; c--) {
data = new Dto();
data.ip= r.nextInt(2000000000);
hmap.put(data.ip, data);
alist.add(data.ip);
}
int c = 1;
for (Integer d : alist) {
hmap.get(d);
}
}
/* Simple data placeholder */
public class Dto
{
public int ip;
public int serialnum;
}
- 5
- JComboBox strange behaviorHello!
I have interesting problem with javax.swing.JComboBox (java 1.4.2)
When I click at combo to open list - there is no reaction to mouse
moves except these on combo header or outside my combo. So I cannot
choose any item from the list.
But I can use keyboard...
This is default combo, I've just create it and populate some Strings
into it.
any idea what's wrong?
B.
- 6
- Error :could not initialize interface awt - Exception:java.lang.ExceptionInInitializerErrorHello
i had problems by the install of the german language pack 6.0.2.CF1
for a Lotus domino Server 6.0.2 CF1.
the System:
Acer altos 19000 Server
2X Pentium Pro 200 Mhz
512 MB Ram
OS windows 2000 Server SP4
the Update of the Notes Server was no Problem but when I tried to
install the Language Pack German (its an Java install Wizard ) there
coms the following Error Message :
Error :could not initialize interface awt - Exception:
java.lang.ExceptionInInitializerError
and if i installd the java software jre 1.3.1 standart the Aplet in
Systemcontrol could not be opend without anny Error Message.
what can I do?
Please help.
Thanks for Help
Stefan Germany
- 7
- Location of Temp Directory?I'm having an app developed for me and they are storing the files in a
newly created folder on the C: drive but I don't want to make directory
there. Is there not a way to get the temp variable for machine, like
%temp or %tmp? Thanks
- 8
- show a form from anotherPlease bear with me as I am pretty new to Java.
I am developing a Java Client application.
I have a frame with a button. When I click on the button, it hides the
current frame and opens another frame which is in another class.
When I click on a button on this second frame, I want to close it
(this.dispose) and show the first frame.
The question I have is:
From the second class frame, how do I reference the first frame?
I don't want to close the first frame as I want to keep any data entered.
TS
- 9
- what i do wrong???Hello All!
I think I have a mistake in my logical sequence of thoughts...
When I want to take influence on my JComponents (JTextField,
JCheckBox, etc.),
do I have to place a listener within the constructor???
My problem was the following. I wanted to get the values from my
different JTextFields an write them to any *.txt file. That did only
work, when I inserted a KeyListener who registered any changes in the
text fields. But my real problem is now, to get the values back from
the *.txt file an set them with setText(String) in the text fields.
This don't work.
I have seen in the NG, that there will be oft spoken about
revalidate() or repaint(), but that don't work anyway.
It does not matter, what I want to do - set a component enabled, or
disabled or what ever, I have to have an adequate listener within the
constructor so that the changes will be visible, isn't it that way???
For example:
public void any_method()
{
myTextfield.setEnabled(false);
}
// IT DON'T WORK
// ...but I don't know why. When I put it within the constructor, it
works...
I don't know what to to. I know it from MFC, there I could get
influence on my components in any method.
I don't know what I do wrong in Java.
(My program is an application with JFrame and SWING componets. I use
JTabbedPane and for each tab a Jpanel)
There must be a simple solution for my problem (I hope so).
Please led me out from this dead-end street.
Thanks in advance
Dariusz
- 10
- How to receive events from a jcombobox in an internal Jpanel ??Good evening,
I've a Frame with two Jpanel, in Jpanel1 I've a Jcombobox and it's
listener while in Jpanel2 I've a JLabel where I want to write the
selected value of the Jcombobox,
Jpanel1 , Jpanel2 and the main frame are in 3 separate class and files,
this because I want to arrange a modular design.
My question is how I can receive in the main Frame the event coming
from Jcombox value changed in Jpanel1 ???
Thanks for your help
Antonio
www.etantonio.it/en
- 11
- Any HID support for Java?Human Interface Device (mouse, etc)
Does anyone know whether java support the HID devices? (under MS
Windows)
I checked the document but did not see any. A google on this group
also returns little information.
Thanks a lot.
- 12
- Precision problem with doubleHi everyone,
I am a Java beginner, and I am trying to create a very simple binary
tree.
Each node has a value, the left child has the same value + an
increment, the right child has the same value - the same increment.
I try to recursively create the tree, but I have precision problems.
My "main" node has a value of 10, the increment is 0.1, tree depth is
4
So i want a tree that goes like this :
depth 1 : 10
depth 2 : 0.9 / 10.1
depth 3 : 0.8 / 10 / 10 / 10.2
depth 4 : 0.7 / 0.9 / 0.9 / 10.1 / 0.9 / 10.1 / 10.1 / 10.3
But at depth 4 when I try to print the value I get 9.700000000000001
instead of 9.7, and 10.299999999999999 instead of 10.3
And things get worse when the depth increase.
All the values and increment are stored in double (native type).
Is it normal? How can I avoid this problem?
Thanks a lot,
Tom.
[main class]
double increment = 0.1;
double startValue = 10;
int maxDepth = 4;
Tree myTree = new Tree(startValue, 1);
myTree.recursivelyCreateChildren(increment, maxDepth);
[Tree.java]
public int depth;
public double value;
public Tree leftChild;
public Tree rightChild;
Tree(double value, int depth){
this.value=value;
this.depth=depth;
System.out.println("node of depth " + depth + " created, value = " +
value);
}
public void createChildren(double increment){
rightChild = new Tree(value - increment, depth+1);
leftChild = new Tree(value + increment, depth+1);
}
public void recursivelyCreateChildren(double increment, int maxDepth)
{
if (depth < maxDepth){
createChildren(increment);
leftChild.recursivelyCreateChildren(increment, maxDepth);
rightChild.recursivelyCreateChildren(increment, maxDepth);
}
}
- 13
- Java encryption <--> .NET encryptionHajo,
I need to exchange encypted data between
.NET and Java environments. The first
problem I encountered is that symmetric
ciphers in .NET needs initialization
vector and Java counterparts don't.
Can some one point me out the place
where I can find any practise and
patterns for encrypted communication
between Java and .NET ?
thanks for any info
Gawel
- 14
- PrintServiceLookup.lookupPrintServices fails to list new printers until re-start (JDK1.4.2_03, Linux RedHat, Tomcat 4.x)Hi Forum,
How could I get
javax.print.PrintServiceLookup.lookupPrintServices(null,null) to return the
current available services while the program that uses lookupPrintServices
is running? In a tomcat servlet I use the lookupPrintServices(..) to get a
list of the printer services available. The class works well and returns the
list but if I install a new printer, the servlet does not list the newly
installed service until I restart Tomcat. Is there a way to unload and
reload the PrintServiceLookup class and then call
PrintServiceLookup.lookupPrintServices?
It appears that the lookupPrintServices(..) returns the list of services
that was available when the instance of the virtual machine was started.
Hence, while the instance is running, it allways returns the same list of
services. If I run a program that lists the services and then exits, the
program lists the newly added printer on re-run. But if the program never
exits (it runs in a loop, re-listing the services every so often), and I add
a new printer while the program is running, the newly added printer is not
listed until I terminate teh rpogram and re-start it.
Thanks in advance for your responser
- 15
- src.zip of j2ee1.4 sdkHi,
I downloaded the j2ee1.4 sdk, but I can't seem to find the source files
in that package. They used to be in a src.zip file, or not? Anyway I
already looked at the Sun website, but I didn't find a URL to download
the source files from.
Kind regards,
Dirk
|
|
|