Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!

Campbell Ritchie

+ Follow
since Oct 13, 2005
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Campbell Ritchie

Welcome to the Ranch

Please give us full details of the book, so we know which one it is, and also details of questions if appropriate. Remember that many readers haven't got that book. The first quote does appear to be ambiguous, but have you quoted it exactly?
Not sure I understand the exact problem, but have you come across Stream.collect(Collectors.partitioningBy()?
1 hour ago

Paul Clapham wrote:. . . Yeah, we've all been there. I remember... . . .

I once spent two hours wondering why my method called throw() wouldn't compile.

on to the next tar pit!

You're such an incurable optimist, aren't you, Paul
13 hours ago
Weelcome to the Ranch

Jeremiah Waters wrote: . . .

You seem to have lots of static imports, but are you actually using them?

The following code is in the main of another class (

Please don't go thinking there is anything important about the main method. It is like the Union Flag at the Grand Prix at Silverstone. The Union Flag isn't really important: the cars are the important part. It is there for starting the application but there is nothing important about the main method. More information here.

[code=java:fistline[8]]public static String isLeapYear( int year )
//The String above was originally Boolean, but I changed it because Boolean caused a whole other sling of errors.[/code]

Don't change your code to correct the error messages. Use the error messages to find the error in your code and change the code to correct the errors. A method with a name starting is should usually return a boolean (not a Boolean). So make your method return a boolean, and run your code until you can pass years and get the results true or false. That shouldn't take long. Note what this old style guide says about boolean returns.

Attempt to fix 1: . . .

Program to the design of your application, not to get rid of the compiler errors. You have two options. You can design a class representing a year, in which case it would have a year number as a field and a method to show whether it is a leap year. That is one option. You would not have a method taking a year number to show whether it is a leap year. That means you have to create a standard Java® class and make objects from it.
The alternative, which is less object‑oriented, would be not to have any fields and make all method static as you are already trying. You don't need any objects of the LeapYear class.
13 hours ago

meenal deshpande wrote:. . . post increment, which means increment the variable after executing current statement.

No, that isn't what postincrement means. The variable is incremented as part of the current statement, following the usual rules of left‑to‑right execution and precedence. The value is however invisible until the variable is used next.

. . . pre increment, which means increment the variable in current statement itself.
Hope it helps.

Afraid that doesn't. This last bit might be correct, but if you are showing it in contrast to postincrement it simply causes confusion.

++i will increment the value of i, and then return the incremented value.

i = 1;
j = ++i;
(i is 2, j is 2)
i++ will increment the value of i, but return the original value that i held before being incremented.

i = 1;
j = i++;

That part is correct. You missed out that i is 2 and j is 1 in the last line.
14 hours ago
. . . never deleted 50% of your code and found no change in functionality . . .
1 day ago
Please provide more details of the error message. What interface does it want? Is that supposed to be a method or a constructor? In both cases you must have () after the identifier (end of 1st line) and you may need parameters, too.
1 day ago
Welcome to the Ranch

Please look at our link about the code button; it isn't obvious at first how to use it, but you put the code between the [‍code=java] part and the [‍/code] part. Since you are new I have corrected it.
If you hit problems, please ask for help early; it is much easier to help if you have written only a little code. The small parts I have read look good, but why are you matching a field description with a constructor parameter name?

Actually passing parameters to constructors is the same whether they are reference types or primitives. Let's have a Kettle which contains water when new, so its constructor might look like this:-. . . and you can call it like this, assuming the Water object already exists:-Beware: Strings are immutable and ints are primitives, so there is no need for a defensive copy of them, but Water might be mutable, so take a defensive copy OR tease the object apart into primitives and immutable objects, to maintain the integrity of your object. Your property class doesn't (I think) need any defensive copying.
Two old posts about defensive copies: 1 2.
1 day ago
People usually prefer to see the code directly rather than having to open files; some people are even suspicious about opening files. Also, please provide details about what is going wrong.
Welcome to the Ranch again.
1 day ago
Welcome to the Ranch

Please supply more details of what is going wrong, otherwise we an't help. Henry is right; this thread belongs in the JS forum.
1 day ago
Welcome to the Ranch

Please provide more details of the book, including author. Is that Boyarsky and Selikoff? I don't have a copy of that book.
I suggest you go through the code first and indent it correctly. People who write cert exam practice questions sometimes indent their code inconsistently to make the question harder. Did you notice that bitesOfCheese is a method parameter in line 2? Is the final output 5? In that case there must be some code calling eatCheese(10); Such a method call definitely assigns a value to that parameter.
Welcome to the Ranch

Please tell us what the question says, and also the author's name.
So, how does the * operator work?
1 day ago