Jelle Klap

Bartender
+ Follow
since Mar 10, 2008
Jelle likes ...
Eclipse IDE Java
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
7
In last 30 days
0
Total given
9
Likes
Total received
290
Received in last 30 days
0
Total given
126
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jelle Klap

Hats off to the Brits!
Couldn't be more pleased with the result

7 years ago
I quite like Querydsl myself. Yes, it is yet another way to write queries, but the typesafe fluent API is so much more convenient than writing JPQL queries or using a Criteria API. Haven't tried jOOQ yet, but it looks good to me. Sometimes ORM just doesn't seem to fit, and where I'd use Spring's JdbcTtemplate, I guess I could give jOOQ a try instead.
Have you followed the necessary steps, as outlined in this article?
It comes in handy if you want to assign an empty List , Set or Map as a default value, for instance to prevent returning a null reference.
You could just create a new instance of an appropriate implementation, but the emptyXXX() methods all return a reference to the same statically initialized immutable instance, which prevents unnecessary creation of objects.

salvin francis wrote:

Campbell Ritchie wrote:I would have used a switch statement myself.


I would have used a HashMap


The requirements specifically prohibit the use of Map implementations.
8 years ago
E-mail address validation with a regular expression looks deceptively simple. A partiall RFC-822 compliant regex, which isn't fully compliant because it can't be, can be found here: http://ex-parrot.com/~pdw/Mail-RFC822-Address.html.
I'd recommend against going down this road.
8 years ago

Emmanuel Ekweanua wrote:Ok. Just coming to understand __A_V_.length is the array length.
2) If x = 0, what does ++x evaluate to? The x++ equates to 1

3) How many times does the for loop run? Based on the condition, x++<__A_V_.length. It looped just once, because if it did the second time, it will negate the for condition of 1(no of loop)<2(length of array)



Mike has been doing a terrific job of guiding you (have a cow btw), and I don't mean to butt in, but I can't resist, so here goes.
I think a major source of confusion for you may be the pre-increment operator (++x); you don't seem to differentiate between it and the post-increment operator (x++).
The difference between them is subtle, yet important. The pre-increment operator increases the value of the operand (x in this example) by 1 and the value of the expression is that newly incremented value. With the post-increment operator on the other hand, while the operand is also incremented, the value of the expression is equal to the old value of the operand - before it was incremented. These two simple programs highlight the difference - they are both identical except for the increment operator, and they produce different outputs.
In both programs x starts out at 0. The PreIncrement program shows that when the pre-increment operator is used the new value of x - 1 - is immediately available when the expression is evaluated. The PostIncrement program shows that this is not the case when the post-increment operator is used, but the second print statement proves that x has indeed been incremented

Prints:
1
1

Prints:
0
1

The for-loop in the code you posted basically reads as: start out with x at value 0, for each iteration immidiately increment x by 1 and check if that newly incremented value is smaller than the length of array __A_V_, if it is execute the body statement, and at the end of that iteration there's nothing else to do before the next iteration - no increment expression.

If you assume you run the program with arguments "- A", then the length of array __A_V_ will be 2, with value "-" at index 0 and value "A" at index 1. The String $ starts out as an empty value. In the first iteration of the loop x is incremented to 1 during evaluation of the termination expression. As 1 is smaller than 2, the body statement is executed and String $ is appended with value "A", which is the value at index 1 of array __A_V_. The first iteration completes, there's no increment expression, the value of x remains 1. The second iteration starts and the termination expression increments x to 2, and as 2 is not smaller than 2 the loop exits immidiately without running the body statement.

What do you suppose would happend if you changed the pre-increment operator in the loop's termination expression to a post-increment operator? Try figuring it out first, then change the program and run with the same arguments as before and see what happens.
8 years ago

JLS 15.27.1 wrote:
It is a compile-time error if a lambda parameter has the name _ (that is, a single underscore character).
The use of the variable name _ in any context is discouraged. Future versions of the Java programming language may reserve this name as a keyword and/or give it special semantics.
link


You should be able to run this program from the command line, using Java 8, just fine. It is still a valid class name, although the compiler will spit out some kind of warning.

It is indeed necessary to specify two parameters - and A, because the main method arguments are used to generate the output. You can do this from the command line easily enough, but it's also quite possible when running a program from inside an IDE.
Eclipse, for instance, has a Run menu with a Run configurations... option, if you create a new Java Application run configuration there should be a tab called Arguments that lets you specify program arguments.
I recommend you steer clear of IDE's fro the time being though, as you are presumably just starting out.

As for the output, look closely at the for loop's increment statement. What value will x have in the very first iteration, and how many iteration's will there be given the value of the termination expression if you use - A as the program's arguments?

FYI, the class and variable names are all completely horrible, but as this is a K&B exercise it's likely meant to familiarize you with what is legal, and proper naming convention is taking a back seat.
8 years ago
Is the download significantly faster when using a different FTP client? It might just be a slow download due to lack of bandwidth (most FTP servers support throttling).
8 years ago
The problem, as you said, is that the newEmployee reference is declared, but never initialized, meaning that at line 5 you are trying to store a reference to a new Employee instance at index 0 of an array that doesn't exist.
Initializing the array directly after you declare the reference at line 4 will fix that. This tutorial might help you.
8 years ago
Or as an alternative to what Tim suggested, you could split using a regular expression that matches one or more whitespace characters.
How about: "The speakers should be loud enough to be clearly audible throughout the room, no louder."
8 years ago
Yes, GLaDOS.
8 years ago
If "the trick" is terminating all office employees - not in the administrative sense - then yes. Yes it will.
8 years ago
So, "no" to the nuclear bombardment?
I don't think poison and coffee are necessarily a great idea either.
Anyway, they seem to confine themselves to the powdered milk and sugar compartments, and I take neither.
Still...
8 years ago