This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

Matt Wong

Ranch Hand
+ Follow
since Aug 18, 2017
Matt likes ...
MS IE Notepad Suse
Cows and Likes
Cows
Total received
5
In last 30 days
0
Total given
0
Likes
Total received
20
Received in last 30 days
0
Total given
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt Green check

Recent posts by Matt Wong

never use local paths in html
you can't just write a mail with an image tag point to a local file - sane mail clients should and will deny such access
read up RFC how to reference an atrached image as img tag in html
9 months ago
When executing from file explorer (that's what you mean by "double click on it") it's about file-(extension)-type association, or easier: What yor file explorer is configured to do when it encounters a specific file type. Most file types define a filename-extension and a magic number header, both can be used to determine what type a file contain.

As JAR files are just ZIP files following some special rules, it might happen your system opens a jar with a zip capable archive manager instead of launching it with java.
Also, at least on windows, jar files are executed with javaw executable wich doesn't open a console window (that's the famous "nothing happen" problem). By modifying this to use regular java executable wich does open a console window most beginners encounter "a black window only shortly pops up and closes itself" issue wich is caused by java display an error message and terminate itself. To read the error message beginners often told to manual open command prompt and run java by hand so the console window stays open and the error message can be read.

You wrote you can run you application from command prompt - how you do it? Do you give additional parameter without your code doesn't work? Do you have classpath dependencies?
Analyze what happen when you try to run your archive from file explorer and it differs from when you run it manual from command line. Most issues are easy to fix.
Also: do you have more than one version of java ? Could be the runtime bound to double click is different from what you start manual.
9 months ago
Well, allthough technically not quite the correct explaination nor term, you can think of "new ClassName()" as somewhat atomic in the way that the keyword new always bonds to the constructor identifier following it. Hence the paranthesis around it are not needed. It's up to personal style (can't remember if conventions mention some about it).
I prefer the style with parenthesis, someone else maybe without.
It's about the same as for any style: it should be consistent and when work as a team everyone should do the same. Otherwise it doesn't matter to bystanders other than its hard to read if the style changes within the same project.

//edit
For most of these "Why?" questions you'll see the answer is mostly "because (someone decided so - take it as given)".
9 months ago
Thanks for clearifying. As said: I wasn't sure about it as I didn't found what you posted. And, as I don't access Lists this way I didn't encountered this issue yet by myself.
9 months ago
@Mike
I'm not sure about ListIterator in specific, but for both basic Iterator and List a specific order is not guaranteed. The only order specific statement I was able to find was that if a Collection implementation guarantees a specific order between two accesses so has the Iterator to follow the same transform. As I understood this line, this very well could mean when somehow two Iterators are aquired the order could had been changed as the Collection may determine this as two destinct accesses wich can lead to de-syncronization.

I'm with you in the way that I don't know a List implementation wich does reorder - but it's possible. And the spec only define that a ListIterator has to follow the same possible reorder.
Hence the way OP tries to access two different iterators can potential lead to desync depend on the specific ListImpl. That's why I showed to only get one Iterator in the loop head and its hasNext as condition. As I don't know if it would be legal to also assign cuurent object with next as step I put it as first statement inside tbe body. I've just wrote it from the top of my head without testing.
9 months ago
The issue here is that you create two iterators wich in fact race eachother - hence causing concurrentmodex. Simple terms: You just can'T get an external iterator in combine with foreach.
Remember: the foreach loop for(Object : Iterable) gets translated to for(; Iterator.hasNext();Iterator.next())

Here's how it should be done:



btw: there's another reason why one shouldn'T try what you do: it can get de-synced. Inside for() next() is called - and then in the body you call next() on your own iterator. Beware: an Iterator isn't guaranteed to keep order. So the Iterator in the head could get other order than your external iterator. In addtion: you example only works cause you try to to remove an element no longer part of processing queue.
Try add a few more elements and try to remove neither the first nor the last object - you will get an exception as well.
9 months ago
Why do you care?
TCP is standardized - look up the RFCs or read Wikipedia. Also, as at least at some point your data go most likely through Ethernet - wich is also standardized - at some point your data will encounter the ethernet max frame size of exactly 1500 bytes (can also be read up in Wikipedia). So, change some buffere size should be avoided unless one has a very specific reason to do so - all other cases should be managed automaticly by its implementation.
@Tim Holloway
Using CMD.exe to run other programs is usual the wrong way to go. Calling CMD.exe only makes useful sens if what you try to get is an internal command or a batch script. Otherwise directly calling the desired program should be preferred.
Most user mis-use the command interpreter as they think it would be easier to just copy what one would enter into it - wich most cause even more problems.

Also, instead using Runtime.exec() rathrr ProcessBuilder should be used anyway. It provides easy methods to deal with paths and parameters. So, although your post may contain background information and OP got the issue resolved, it's not really contributing for others may stumble upon is thread later on.
10 months ago

Stephan van Hulst wrote:What do you mean? What wrong with Integer.toHexString() or String.format()?


Integer.toHexString: doesn't 0-pad - if the result is 0-15 (0-F) it only returns a String with one single character - that's the main issue in the original first post hence the question why it's needed to be done manually
as toHexString is located in Integer class it suggest to work on 32bit values (also, it's only in Long, Float and Double - the smaller datatypes Byte, Short and Character doesn't provide it - also, the toString() with additional radix parameter is only provided by Integer and Long) - and as "hex string" nowdays associated with two-leter encoding of an 8-bit byte it could be expected to at least pad to strings with length of multiple of 2 - although it could be debated if a padding to a 6 charachter string should be used when the value fits in 24 bit
String.format(): when using with some like %02x it's easy to represent a value as a 0-pad 2 character hex string - but what happens internal, parsing regex, converting, etc - is very heavy overhead for something that should be simple

in addition the parseInt method in my eyes lacks support for correctly parsing negative values correctly

correctly parse and doesn't throw any exception

instead of parse to negative integer max it throws a NumberFormatException
even more surprising:

wich doesn't make sense at all correctly parses to negative max int - although all except char is signed in java - hence "negative (negativ max int)" should throw the exception as it would result in int max +1 wich doesn't fit anymore
that's what I meant with "what SE API provide doesn't provide whats expected"
sure - as long year dev one might know these quirks - but for a new one just learn java or maybe programming at all  this doesn't seem to make sense - wich mostly causes such threads here wich mostly answered with "because someone decided so and made it spec > (link to spec here)" - wich, although maybe technically correct, isn't really a good explanation
10 months ago
well, aside from doc specify "when -d isn't set class files created where source files are" the developer is responsible for placing files correctly in the first place
most "I can't figure it out" caused by dev issues not follow what java intents or require - and sadly, as humans the one thing makes us different from animals is to make ourself more stupid than we are - we invented a machine wich is even more stupid then we are able to make ourself - so, if you write the source-line

if(statement);

how even the smartest IDE should know the obvious issue?

in addition: when you try the same example with more than one classfile depending on each other instead of the compiler somehow is smart to locate and re-locate the files to thier correct directories - the compiler simply throws a ClassNotFound - so it's not just failing to place the compiled class files in the correct output directories but also to re-locate input files - wich brings us back to: the developer is responsible to place the source files in the correct folders in the first place
10 months ago
whenever I'm encountered with such "conversions" it always bothers me that Java doesn't support such out of the box - and that the most methods the SE API provides doesn't fit what one expect
idk about the time java was once invented (back in the 80s) - but I guess output the internal binary data in a more human readable way like bitmask or hex was always some of the most basic things a maschine was needed to be able to do
remember how long it took java until the once internal-only base64 was made public?
isn't there still no "easy way" expect from regex or self-build short few-liners to correctly pad and signage - are we still slaves to apache common?
10 months ago
for teh lolz I've written a "low-level" client - I highly recommend against using it but instead use JavaMail (or by it's new name: Jakarta Mail):

this is the mail I get on google:

have fun