comp.lang.java.programmer
http://groups-beta.google.com/group/comp.lang.java.programmer
[EMAIL PROTECTED]

Today's topics:

* J2ME - Newbie question - 2 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8b2ce51110520462
* Control container for AWT? - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f4f97432716d8d3d
* java.util.Random implementation - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/51185dc601b147b2
* Serialization Problems and books on serialization? - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8af88eceb230451c
* Why Liferay Enterprise Portal is better than Websphere - 2 messages, 2 authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/cbcf938287db8685
* Question on Pattern Matcher? - 2 messages, 2 authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4f43abd9dd1ae29
* JVM crashes when calling C++ DLL - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/aabe8600f06f5290
* JVM as service - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ca2d0e75df3526fa
* acceptable way to program - 4 messages, 3 authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/829184c5bd6bb8b0
* declare variable inside or outside block? - 4 messages, 4 authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/51e12987795dd5c4
* Stuff the purple heart programmers cook up - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ff788c5b12bf8d8f
* How to system("foo") in Java? - 1 messages, 1 author
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9626f7b0c131bcd0
* Question about synchronization with vectors - 4 messages, 4 authors
 
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ace40452adda263f

==============================================================================
TOPIC: J2ME - Newbie question
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8b2ce51110520462
==============================================================================

== 1 of 2 ==
Date: Sun, Jan 2 2005 9:24 am
From: "Darryl L. Pierce"  

Benjamin Schmid wrote:
> What I did already: I installed the WTK2.0, build some examples, tried
> to install the PDADemo example on my palm and execute it. I get the
> error:
> can't load javax.microedition.io.file.FileConnector
> I think that would be exactly the thing I would need, but it seems not
> to work.

Your M500 needs to have a MIDP runtime environment installed onto it. 
You can get a copy of IBM's Websphere Micro Edition that's been licensed 
to Palm, but I'm not sure how you would get it.

-- 
Darryl L. Pierce <[EMAIL PROTECTED]>
Visit my webpage: <http://mcpierce.multiply.com>
"By doubting we come to inquiry, through inquiry truth."
     - Peter Abelard



== 2 of 2 ==
Date: Sun, Jan 2 2005 9:25 am
From: "Darryl L. Pierce"  

avp wrote:
> AFAIK, there is no way in J2ME that you can create a file only RMS, for XML
> check out the following link
> http://developers.sun.com/techtopics/mobility/midp/articles/parsingxml/

If the handset implements JSR-75 then you can access files on the handset.

-- 
Darryl L. Pierce <[EMAIL PROTECTED]>
Visit my webpage: <http://mcpierce.multiply.com>
"By doubting we come to inquiry, through inquiry truth."
     - Peter Abelard




==============================================================================
TOPIC: Control container for AWT?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/f4f97432716d8d3d
==============================================================================

== 1 of 1 ==
Date: Sun, Jan 2 2005 2:33 pm
From: Andrew Thompson  

On Sun, 2 Jan 2005 19:14:59 -0800, avp wrote:

> Is there any container in AWT compatable with Java 1.1 in which I can
> dynamically place any number of controls and it automatically places scroll
> bar for selecting ?

java.awt.ScrollPane, it accepts one component, but that component
can be a Panel with a GridLayout or FlowLayout.

> any suggestions ???

Read the GUI FAQ [1].
Do the GUI/Layout tutorial at Sun (see links in GUI FAQ).
Post GUI questions to c.l.j.g.[2].

[1] <http://www.physci.org/guifaq.jsp>
[2] <http://www.physci.org/codes/javafaq.jsp#cljg>

-- 
Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane




==============================================================================
TOPIC: java.util.Random implementation
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/51185dc601b147b2
==============================================================================

== 1 of 1 ==
Date: Sun, Jan 2 2005 2:35 pm
From: Andrew Thompson  

On Sun, 2 Jan 2005 07:42:30 -0600, Ryan Stewart wrote:

> <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> Is the random number algorithm ..
..
> Check the source code.

As close as..
<http://www.physci.org/source.jsp?class=java.util.Random>

-- 
Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane




==============================================================================
TOPIC: Serialization Problems and books on serialization?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/8af88eceb230451c
==============================================================================

== 1 of 1 ==
Date: Sun, Jan 2 2005 6:40 am
From: "deadsea" <[EMAIL PROTECTED]> 

You might want to look at my article on converting a java ouptstream to
an inputstream:
http://ostermiller.org/convert_java_outputstream_inputstream.html

It discusses several methods for avoiding filling up the buffer of a
piped stream.

Stephen





==============================================================================
TOPIC: Why Liferay Enterprise Portal is better than Websphere
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/cbcf938287db8685
==============================================================================

== 1 of 2 ==
Date: Sun, Jan 2 2005 10:53 am
From: James McGovern  

Check out http://www.liferay.com for a 100% open source portal that 
comes with a ton of portlets and can be had for absolutely free. No per 
CPU charges and in many benchmarks it actually scales better.

http://blogs.ittoolbox.com/eai/leadership




== 2 of 2 ==
Date: Sun, Jan 2 2005 10:53 am
From: James McGovern  

Check out http://www.liferay.com for a 100% open source portal that 
comes with a ton of portlets and can be had for absolutely free. No per 
CPU charges and in many benchmarks it actually scales better.

http://blogs.ittoolbox.com/eai/leadership





==============================================================================
TOPIC: Question on Pattern Matcher?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4f43abd9dd1ae29
==============================================================================

== 1 of 2 ==
Date: Sun, Jan 2 2005 4:13 pm
From: Alan Moore  

On Sat, 1 Jan 2005 21:32:46 -0500, "hilz" <[EMAIL PROTECTED]> wrote:

>try this:
>
>Pattern.compile(".+Opens.+");

Or stay with your original regexes, but use the find() method instead
of matches().  matches() returns true only if the regex describes the
whole input, while find() looks for a subsequence of the input that
matches.



== 2 of 2 ==
Date: Sun, Jan 2 2005 2:02 pm
From: IchBin  

Alan Moore wrote:
> On Sat, 1 Jan 2005 21:32:46 -0500, "hilz" <[EMAIL PROTECTED]> wrote:
> 
> 
>>try this:
>>
>>Pattern.compile(".+Opens.+");
> 
> 
> Or stay with your original regexes, but use the find() method instead
> of matches().  matches() returns true only if the regex describes the
> whole input, while find() looks for a subsequence of the input that
> matches.

Thanks Alan...
IchBin
__________________________________________________________________________

'The meeting of two personalities is like the contact of two chemical 
substances:  if there is any reaction, both are transformed.'
-  Carl Gustav Jung,  (1875-1961),  psychiatrist and psychologist




==============================================================================
TOPIC: JVM crashes when calling C++ DLL
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/aabe8600f06f5290
==============================================================================

== 1 of 1 ==
Date: Sun, Jan 2 2005 4:22 pm
From: "Lans Redmond"  

add the -dsa option  to the catalina_opts flag

dsa diables system assertions


"chella mani" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> hi all,
> I am calling functions in existing C\C++ program (DLL) through a
> wrapper C++ program (another DLL)  from java.
>
>  ie    java <---->Wrapper C++ <-----> Ordinary C++ function
>
> My problem is JVM crashes(some times) and gives the following error,
>
> An unexpected exception has been detected in native code outside the
> VM.
> Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred
> at PC=0x80C2F75
> Function=[Unknown.]
> Library=(N/A)
>
> NOTE: We are unable to locate the function name symbol for the error
>      just occurred. Please refer to release documentation for
> possible
>      reason and solutions.
>
>
> Current Java thread:
> at java.lang.Class.getDeclaredMethods0(Native Method)
> at java.lang.Class.privateGetDeclaredMethods(Class.java:1647)
> at java.lang.Class.getMethod0(Class.java:1893)
> at java.lang.Class.getMethod(Class.java:976)
> at javax.swing.UIDefaults.getUI(UIDefaults.java:726)
> at javax.swing.UIManager.getUI(UIManager.java:784)
> at javax.swing.JToolTip.updateUI(JToolTip.java:82)
> at javax.swing.JToolTip.<init>(JToolTip.java:64)
> at javax.swing.JComponent.createToolTip(JComponent.java:2603)
> at javax.swing.ToolTipManager.showTipWindow(ToolTipManager.java:257)
> at 
> javax.swing.ToolTipManager$insideTimerAction.actionPerformed(ToolTipManager.java:689)
> at javax.swing.Timer.fireActionPerformed(Timer.java:271)
> at javax.swing.Timer$DoPostEvent.run(Timer.java:201)
> at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
> at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
> at 
> java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
> at 
> java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
> at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
> at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
>
> Dynamic libraries:
> 0x7CC00000 - 0x7CC1D000 C:\WINDOWS\SYSTEM\IMAGEHLP.DLL
>
> Heap at VM Abort:
> Heap
> def new generation   total 4608K, used 234K [0x10010000, 0x10510000,
> 0x10ed0000)
>  eden space 4096K,   1% used [0x10010000, 0x10021eb0, 0x10410000)
>  from space 512K,  31% used [0x10490000, 0x104b8a80, 0x10510000)
>  to   space 512K,   0% used [0x10410000, 0x10410000, 0x10490000)
> tenured generation   total 60544K, used 11740K [0x10ed0000,
> 0x149f0000, 0x1c010000)
>   the space 60544K,  19% used [0x10ed0000, 0x11a47348, 0x11a47400,
> 0x149f0000)
> compacting perm gen  total 12032K, used 11914K [0x1c010000,
> 0x1cbd0000, 0x20010000)
>   the space 12032K,  99% used [0x1c010000, 0x1cbb2ad0, 0x1cbb2c00,
> 0x1cbd0000)
>
> Local Time = Thu Aug 26 18:58:43 2004
> Elapsed Time = 41
> #
> # The exception above was detected in native code outside the VM
> #
> # Java VM: Java HotSpot(TM) Client VM (1.4.2_02-b03 mixed mode)
> #
>
>
>
> Can Any one give me a solution to this problem or way to find out the
> cause of the problem,
>
> Thanks and Regards,
> Chella.mani 






==============================================================================
TOPIC: JVM as service
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ca2d0e75df3526fa
==============================================================================

== 1 of 1 ==
Date: Sun, Jan 2 2005 4:27 pm
From: "Lans Redmond"  

yes, what you need to do is write two classes,
one is a java launcher(server) and the other is a client which passes 
objects to the launcher.  The launcher will load the object and look for the 
main method to run.  If it finds one then it will run it within its own jvm.

There is a book out by Oriely, Java Performance tuning that explains how to 
do it in more details, I think you can find it on the java.sun.com website.

I use this so that all our applications uses one jvm for better performance. 
ou will only need to worry about your heap size


"Jonathan Neve" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Hi all!
>
> Has anyone ever tried to make the JVM into a OS service, so that
> instead of having to load it for each and every Java application, it
> could be loaded once by the OS at startup. Then, if you want to launch
> a Java application, all you would have to do would be to call the JVM
> service, and tell it which class to load, in exactly the same way as
> it is now. The only difference would be that the JVM wouldn't have to
> be loaded every time, which would considerably reduce both startup
> time and memory consumption.
>
> Has anyone done this? Any ideas?
>
> Thanks!
> Jonathan Neve. 






==============================================================================
TOPIC: acceptable way to program
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/829184c5bd6bb8b0
==============================================================================

== 1 of 4 ==
Date: Sun, Jan 2 2005 8:35 am
From: DA Morgan  

fishfry wrote:
> In article <[EMAIL PROTECTED]>,
>  "Tom Dyess" <[EMAIL PROTECTED]> wrote:
> 
> 
>>Yes, I would agree with the relational database. ORDB are mainly hype and 
>>usually promoted by coders that have never had to write a report or mine 
>>data effectively.
>>
> 
> 
> Is this really true? I'm an experienced database programmer learning the 
> Java/OO way of doing things and I'm puzzled that people use Hibernate 
> and similar tools to define objects, with the database serving as just a 
> passive serialization mechanism with no thought to database theory. How 
> can this possibly work in real life? Also I've been told that stored 
> procedures are not supported by Hibernate, is that true? How can it be 
> that 20 years of relational theory seems to be getting thrown out 
> overnight? Or am I just misinformed?

It is true. Most of the Java being written against relational databases
doesn't perform and doesn't scale well. The saving grace for all of
those Java geniuses is that they can blame it on the web and 99% of IT
management is too clueless to know better.
-- 
Daniel A. Morgan
University of Washington
[EMAIL PROTECTED]
(replace 'x' with 'u' to respond)



== 2 of 4 ==
Date: Sun, Jan 2 2005 10:28 am
From: Chris Smith  

Chris Uppal <[EMAIL PROTECTED]> wrote:
> It may help to consider the difference between:
> 
> a)    a program (or group of closely related programs) that
>       happens to require (ACID) persistence.
> 
> b)    a program that is required to manipulate independently-existing
>       data in a more-or-less public repository (database).

Indeed, I do find that to be a useful distinction.  But,

> In my opinion, O-R technologies are mostly about (a) -- that is to say they
> provide a poor man's object database.

This isn't exactly true.  There are a number of factors to consider when 
making use of O/R mapping technologies, and this is one of them.  Some 
such technologies are extremely limited in terms of how their data is 
stored, and are only suitable for application-private data that uses a 
relational database by coincidence.  Others are considerably more 
flexible, and can deal with data that's represented in a number of ways, 
and map from there to a number of different OO models.

Hibernate is a good example of the latter.  I enjoy using Hibernate 
because I can do (or get someone else to do) intelligent database design 
without thinking of my application, and then I can pretty easily create 
an OO model of that data using Hibernate that's fairly easy to use from 
Java.  Same goes for a pre-existing database.  Indeed, I can create 
different OO models for different applications (which ought to be the 
way O/R mappers are used; good O/R mapping is a functional concern, and 
is not inherent in the data itself) and they will work together 
flawlessly, making connections to the same database.

That said, I know of no O/R mapper that's really universally outstanding 
in being able to map an existing database schema in an ideal way.  
Generally, you'll end up with some quite quirks in the OO model of the 
data.  I imagine more flexibility could be provided by products in the 
future.  Nevertheless, I don't think it's fair to characterize use of an 
O/R mapper for this as a hack, or to claim that it's different from the 
intended usage of the tool.

-- 
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



== 3 of 4 ==
Date: Sun, Jan 2 2005 10:56 am
From: Chris Smith  

fishfry <[EMAIL PROTECTED]> wrote:
> Is this really true? I'm an experienced database programmer learning the 
> Java/OO way of doing things and I'm puzzled that people use Hibernate 
> and similar tools to define objects, with the database serving as just a 
> passive serialization mechanism with no thought to database theory. How 
> can this possibly work in real life? Also I've been told that stored 
> procedures are not supported by Hibernate, is that true? How can it be 
> that 20 years of relational theory seems to be getting thrown out 
> overnight? Or am I just misinformed?

There is undoubtedly some bad database programming being done by Java 
programmers (and by C programmers, and especially by VB programmers, 
etc.).  Nevertheless, the use of Hibernate doesn't represent poor 
database programming practice.  What you should look for instead is ay 
of the following indicators of poor use of Hibernate:

- Use of Hibernate when it's a poor idea.  If a task is inherently 
suited to a tabular view of data, then Hibernate isn't necessarily the 
best tool.  Also, if an application looks at data in a lot of different 
combinations and does a lot of selecting of specific columns and joining 
of tables (particularly in ways that aren't easily predicted at 
development time), then Hibernate is obviously not the best way to do 
this.  These are tasks which are best accomplished in a relational 
model.  Use of Hibernate to write an application that naturally fits 
into the relational model is a bad idea.

- Use of Hibernate's tool to convert existing objects to an auto-
generated database schema, if that schema might be used by a separate 
application.  That derives the data model from the functional model of 
that data in a specific application, and that is a bad idea for data 
that will be shared between multiple applications.

It should be mentioned here that I am referring to data that might be 
used by multiple applications *right now* under current requirements.  
If the data might be used three years from now by a separate application 
and the current application isn't that awfully proliferant, I wouldn't 
worry about it.  It only takes a weekend or so to write a tool that 
moves data from the old database to a new database schema if there's no 
live application.

As for stored procedures, it is true that current production releases of 
Hibernate cannot use stored procedures for the simple CRUD tasks that 
are implemented by Hibernate.  You can, however, call stored procedures 
in the database just fine.  Version 3 can even use stored procedures for 
CRUD operations, and there's a beta available for version 3.  
Nevertheless, it would be a royal pain to write stored procedures for 
every little thing like that.  Data validity can be better checked in 
the database with constraints and triggers without interfering with the 
application interface.  Stored procedures (at least, though exposed to 
applications) are best reserved for domain-specific logic, and don't 
need Hibernate to be called anyway.

Stored procedures are, of course, not any part of relational theory at 
all, so it's silly to complain that relational theory is being thrown 
out.  Use of Hibernate in no way contradicts relational theory.

-- 
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



== 4 of 4 ==
Date: Sun, Jan 2 2005 1:32 pm
From: Sudsy  

fishfry wrote:
<snip>
> Is this really true? I'm an experienced database programmer learning the 
> Java/OO way of doing things and I'm puzzled that people use Hibernate 
> and similar tools to define objects, with the database serving as just a 
> passive serialization mechanism with no thought to database theory. How 
> can this possibly work in real life? Also I've been told that stored 
> procedures are not supported by Hibernate, is that true? How can it be 
> that 20 years of relational theory seems to be getting thrown out 
> overnight? Or am I just misinformed?

The goal is to implement the business logic in the middle layers,
removing it from the database tier. You end up using the database
as the incredibly fast and powerful resource it started out to be.
It's important from a portability prespective; would you really
want to rewrite all your stored procedures if/when you have to
migrate to another RDBMS?




==============================================================================
TOPIC: declare variable inside or outside block?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/51e12987795dd5c4
==============================================================================

== 1 of 4 ==
Date: Sun, Jan 2 2005 9:59 am
From: Chris Smith  

hilz <[EMAIL PROTECTED]> wrote:
> I like to agree with others that declaring variables as close to their scope
> as possible is a better idea.
> I just like to ask why would you do:
> String foo= new String();
> This does not seem to be the correct thing to do.
> what you probably need is:
> String foo = someOtherString;
> or
> String foo = "some hardcoded string";

I'd go a step further.  Since this is a local variable, you should do 
something like this by default:

    String foo;

What this does is declare a variable, but give it no defined value.  If 
you try to use the variable before assigning a value to it, the 
*compiler* will let you know.  Any time you need to declare a variable 
but there's no initial value needed for it to make the code correct, 
this is what you should do.

If foo needs an initial value for the code to be correct, of course, 
then you give it one; but in that case, it's silly to be guessing at 
what it should be when we don't know how you're using it.  Maybe it 
should be null, or maybe it should be "abracadabra".  We simply don't 
know.

> String foo = new String() does not seem to serve any purpose to me. Does
> anybody care to comment on this?

Joona's answer is the whole story.  Since it's really bad form to depend 
on instance identity for String objects, using "" should be functionally 
identical to new String()... but it is nevertheless possible to observe 
a difference between the two.

-- 
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



== 2 of 4 ==
Date: Sun, Jan 2 2005 12:27 pm
From: "Harish"  

A variable declaration inside means that the variable has to be created for 
each iteration.
For eg:
while (true) {
    String foo = new String();
}
if the loop executes say 100 times, the variable foo will be created 100 
times. (I am not talking about the "new String()" part, but the creation of 
the foo: creation of a reference to store the
string)
now if the varaible was declared outside the loop, this won't happen, and 
you get yourself a better code.

They(?) also say, a good optmizing compiler will be smart enough to detect 
these and handle'em appropriately.
Also, in java, a reference is only a couple of bytes. So there is nuthing 
much one can save by moving the decl outside.


"The Abrasive Sponge" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Angus Parvis wrote:
>
>> Hi,
>>
>> I just asked myself, whether it is better to declare a variable inside or 
>> outside a block, if you only want to use it inside the block;
>>
>> I always do it like this:
>>
>> String foo;
>> while (true) {
>>     foo = new String();
>> }
>>
>> Guess that's better than:
>>
>> while (true) {
>>     String foo = new String();
>> }
>>
>> In the second example i declare the variable String foo every time the 
>> loop is repeated - guess that's the worse solution, isn't it?
>>
>> Well, I'd be interested in your comments on this,
>>
>> thanks in advance,
>>
>> Angus
>
>
> If I need reference to foo after the while loop I use the first if I don't 
> I use the second.
> 





== 3 of 4 ==
Date: Sun, Jan 2 2005 6:19 pm
From: Joona I Palaste  

Harish <[EMAIL PROTECTED]> scribbled the following:
> A variable declaration inside means that the variable has to be created for 
> each iteration.
> For eg:
> while (true) {
>     String foo = new String();
> }
> if the loop executes say 100 times, the variable foo will be created 100 
> times. (I am not talking about the "new String()" part, but the creation of 
> the foo: creation of a reference to store the
> string)
> now if the varaible was declared outside the loop, this won't happen, and 
> you get yourself a better code.

This, of course, is nonsense. The variable foo is only created at
compile time, and at compile time it doesn't matter at which scope the
variables are in, they are handled the same way anyway. The compiler
reserves a few bytes of space in the variable table for each variable
and translates all uses of the variable into use of its space in the
table.
Now, when the while loop actually runs, foo isn't created at all any
more. The only thing that is created is new String(). The way the
run-time environment sees it, it's creating a new String and assigning
a reference to it into some space in the variable table. Where that
space came from, the environment doesn't know or care.

> They(?) also say, a good optmizing compiler will be smart enough to detect 
> these and handle'em appropriately.

Make that "any compiler anywhere, optimising or not". Compilers that
actually ran while loops while translating variable names into spaces in
the variable table would be downright idiotic.
It has nothing to do with optimising. It's a matter of basic compiler
operation.

> Also, in java, a reference is only a couple of bytes. So there is nuthing 
> much one can save by moving the decl outside.

This is the only part that is absolutely true.

-- 
/-- Joona Palaste ([EMAIL PROTECTED]) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"Holy Banana of this, Sacred Coconut of that, Magic Axolotl of the other."
   - Guardian in "Jinxter"



== 4 of 4 ==
Date: Sun, Jan 2 2005 10:32 am
From: "newB"  

in Java, i guess that doesnt really matter.





==============================================================================
TOPIC: Stuff the purple heart programmers cook up
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ff788c5b12bf8d8f
==============================================================================

== 1 of 1 ==
Date: Sun, Jan 2 2005 9:07 am
From: "Last Timer"  


Ryan Stewart wrote:
> "Andrew Thompson" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Others can waste further attention on you if they see fit.
> > I'm outta' this one.
> >
> I'll jump in. Wouldn't the Starbucks/Pointerbucks be more suited to C

> programmers? I really don't see how that applies to Java.
>
> And really, why are you posting all this junk? If you're just a
troll,
> you'll make a name for yourself quickly.

You're asking for more:

Why Java uses semi-colon?

A full colon will be organ donation

What is java importing all the time?
It's the american way

What is an inner class?
It's a co-ed class

Why is the signature public static void main required?
Anything else would be a forgery

How many java programmers does it take to replace a light bulb?
None; the bulb is javacuum.





==============================================================================
TOPIC: How to system("foo") in Java?
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/9626f7b0c131bcd0
==============================================================================

== 1 of 1 ==
Date: Sun, Jan 2 2005 10:12 am
From: Chris Smith  

fishfry <[EMAIL PROTECTED]> wrote:
> > Look at the java.lang.Runtime.exec family. Especially
> > the 
> > 
> > exec(String[] cmdarray) 
> > 
> > one.
> 
> Thanks, that's exactly what I'm looking for.

Note that it is subtly different from the C system() function.  C's 
system() takes a single string and passes it to a platform-dependent 
shell interpreter.  Java's Runtime.exec immediately creates a process 
from the arguments given, and does not pass anything through a shell 
interpreter.  This has a number of important consequences, including:

1. Shell built-in commands will ne be available.  This includes, for 
example, the UNIX (or MacOS X) bash shell's 'jobs', 'alias', 'ulimit', 
'pwd', and quite a few more.  On Windows, it includes 'dir' and 'copy', 
among others.

2. Shell interpretation of some parameters will not occur.  On UNIX, 
this even applies to wildcards, which are typically expanded by the 
shell.  On both UNIX and Windows, it applies to quoting and pipes.

If you need any of the above, then you need to run a shell explicitly, 
as in:

    Runtime.getRuntime().exec(new String[] {
        "/bin/sh", "-c", myCommand
    });

(or equivalent in other operating systems).

-- 
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation




==============================================================================
TOPIC: Question about synchronization with vectors
http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ace40452adda263f
==============================================================================

== 1 of 4 ==
Date: Sun, Jan 2 2005 11:07 am
From: "Jorge"  

Hi

I am a bit confused about the synchronization with vectors:
In my application I have a vector in which a few threads add and remove
objects and another thread reads it every once in a while.
By now it is working, but I want to avoid possible random errors when
the threads start to make more insertions and deletions in the vector.
I have read how to synchronize using the sychronize keyword around the
statements that use the vector, but I have also read that the vector is
thread-safe. So should I synchronize by hand the access to the vector
or the vector class handle it for me??

(I know it is a pretty newbie question, but I hope that this is the
place to understand this)

Thanks in advance!

Jorge




== 2 of 4 ==
Date: Sun, Jan 2 2005 11:11 am
From: [EMAIL PROTECTED] 

If you look at the documentation for the Vector class, it will show you
which methods are synchronized.




== 3 of 4 ==
Date: Sun, Jan 2 2005 7:10 pm
From: Alex Kizub  

> I have read how to synchronize using the sychronize keyword around the
> statements that use the vector, but

> I have also read that the vector is
> thread-safe.

You are right.
>Unlike the new collection implementations, Vector is synchronized.
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html

> So should I synchronize by hand the access to the vector
> or the vector class handle it for me??

no, yes.
Alex Kizub.




== 4 of 4 ==
Date: Sun, Jan 2 2005 11:31 am
From: "VisionSet"  



"Jorge" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi
>
> I am a bit confused about the synchronization with vectors:
> In my application I have a vector in which a few threads add and remove
> objects and another thread reads it every once in a while.
> By now it is working, but I want to avoid possible random errors when
> the threads start to make more insertions and deletions in the vector.
> I have read how to synchronize using the sychronize keyword around the
> statements that use the vector, but I have also read that the vector is
> thread-safe. So should I synchronize by hand the access to the vector
> or the vector class handle it for me??
>
> (I know it is a pretty newbie question, but I hope that this is the
> place to understand this)
>

The Vector class is synchronised, but all this means is that a **single**
method call (eg add(yourObject) is guaranteed atomic (that is thread-safe).
Only you can decide if you need further synced access.
If you do two operations on the collection that require nothing to have
changed inbetween then you will have to sync the calls:

synchronized(myVector) {
    if(! myVector.contains(...)) myVector.add(...)
}

If you always guarantee thread safety externally like this, there is no need
to use a synced collection such as a Vector - which can basically be
considered deprecated anyhow.  So use an ArrayList instead.
If you want a synced list, get one like this:

List myList = Collections.synchronizedList(new ArrayList());

--
Mike W





==============================================================================

You received this message because you are subscribed to the Google
Groups "comp.lang.java.programmer" group.

To post to this group, send email to [EMAIL PROTECTED] or
visit http://groups-beta.google.com/group/comp.lang.java.programmer

To unsubscribe from this group, send email to
[EMAIL PROTECTED]

To change the way you get mail from this group, visit:
http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe

To report abuse, send email explaining the problem to [EMAIL PROTECTED]

==============================================================================
Google Groups: http://groups-beta.google.com 

Reply via email to