This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!

Stephan van Hulst

Saloon Keeper
+ Follow
since Sep 20, 2010
Cologne, Germany
Cows and Likes
Cows
Total received
216
In last 30 days
2
Total given
193
Likes
Total received
2212
Received in last 30 days
49
Total given
280
Given in last 30 days
29
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Stephan van Hulst

What happens when you clear your browser cache?
8 hours ago
Precedence and associativity tell the compiler which operands go with which operators. You can kind of compare it to the compiler inserting explicit parentheses in the code, as the example x = (y = (z = 17)) demonstrates. This happens during compilation.

At runtime, when the expression is evaluated, Java has no idea about precedence and associativity. It just sees a tree of expressions that consist of sub-expressions. Those sub-expressions are evaluated left-to-right.

The easiest way to do this yourself is to first write down the complete expression and inserting parentheses everywhere until you can tell which operand goes with which operator without having to think about precedence rules. Then repeatedly scan the expression from left to right until you find a complete sub-expression. Evaluate it, and then rescan the resulting expression.

In the example given by the website, the first complete sub-expression is (z = 17). In the example you gave at the start, (iA[i]) is the first complete sub-expression.
14 hours ago
Because you're confusing operator associativity with order of evaluation.

The = operator is right-associative, so the expression is equivalent toPeople have the tendency to evaluate expressions by performing operations in parentheses first. That's not how Java works. Java always evaluates left-to-right, meaning the i in iA[i] is evaluated to 0 before i = 30 is evaluated, and finally 30 is assigned to iA[0].
1 day ago
Welcome to CodeRanch!

A priority queue is a queue that keeps the item with the highest priority at the head of the queue. The rest of the queue may or may not be ordered.

Usually priority queues are implemented using a "heap" data structure. Google for "binary heap" to find out how they work.
The redirect happens because Spring seems to think you're not logged in when performing an AJAX request. How did you set up Spring? Where do you store tokens from the identity provider that handles SSO?
2 days ago
The reason is because your AJAX request is redirected. During a redirect, the Origin is set to 'null', and the final destination of your request will then reject the request because you're not allowed to make cross-origin AJAX requests.

You must make sure the user is logged in before you make the AJAX request to avoid being redirected.
2 days ago
Well, where is company declared? How does the compiler know what thing 'company' refers to, and what you can do with it?
5 days ago
Simple: The code needed to protect mutable objects from corruption that is eliminated usually does this by creating copies. If every method needs to create copies of mutable objects, you're going to have much more garbage collection than if you can just pass immutable objects around without making copies of them.

Even though every operation on a String creates a new object, it's nowhere near the amount of objects that would have needed to be created if String was mutable, and every method ever written that accepts a String as a parameter would need to copy it first.
5 days ago
Also, real life projects can be HUGE. Even if you have access to all the source code, you might not be able to find all the parts where your members are accessed. I've been working on our company's main product for five years now, and I still have no idea what certain parts of it do exactly.
5 days ago
Glad you figured it out. I'd like to draw your attention to a few issues though:

Constants should be final. You're going to run into trouble if a rogue class decides that it wants to change the value of the starting cash fields.

Don't make classes that are just containers for constants. Declare constants in the class that they're closest related to. Presumably you have a Game class or something similar that keeps track of the state of the game and implements the game rules. That would be an appropriate place to declare the constants.

You should prefer BigInteger for integer amounts. In either case, prefer calling valueOf() methods over creating new instances.

Give constants clear names that indicate how they're used:
6 days ago
Welcome to CodeRanch!

First of all, you don't want to be mixing presentation and business logic. Use a template language to create the pages where you display the file names.

When you've created your template, you can render a view by passing it the data that needs to be displayed by the template. Pass it the array of file names, and let the template render them in a for-loop.

In your business logic, if you have an array of file paths, you can convert the array to a different array that contains only the file names. Use the array_map() function for this:
6 days ago
PHP
I would guess that view.findViewById(R.id.slika) returns null. Are you sure that your view contains a descendant ImageView with the given ID?
6 days ago
You are confusing a method declaration with its implementation.

The declarations Nocturnal.isBlind() and Owl.isBlind() have the SAME method signature. Nocturnal just gives a different implementation for it than Owl does.

When you call an instance method, the implementation that is used is ALWAYS the implementation given by the actual runtime type of the object, regardless of the formal type that is used for the variable that refers to the object.

What the book means by the phrase you quoted, is that you can only use method signatures declared in the formal type of the reference that you're calling the method on. Here's an example:

Line 3 demonstrates that you can call isBlind() on a reference with the formal type Nocturnal, because it's declared in Nocturnal. The compiler knows that regardless of what actual kind of nocturnal animal is assigned, it WILL have an isBlind() method. It will still use the implementation given by Owl.

Line 4 demonstrates that you can not call numberOfFeathers() on a reference with the formal type Nocturnal, because it's not declared in Nocturnal. There are nocturnal animals that don't have feathers. The compiler can't determine that the nocturnal variable will never refer to a nocturnal animal that is not an Owl.
6 days ago
Why are you still on Java 5? Support for it ended 10 years ago. I'd run away screaming if my company didn't upgrade their software in so long.

Anyway, on Java 5 you can use this method.
6 days ago