Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS 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 Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Campbell Ritchie

Antonio Moretti wrote:. . . ä, ö and å.

Is that U+00E4, U+00E5 and U+00F6, as on this Unicode page? 00E4=ä 00E5=å 00F6=ö I got those characters to show correctly from JShell:

jshell> import javax.swing.JOptionPane;

jshell> JOptionPane.showMessageDialog(null, "00e4=\u00e4, 00e5=\u00e5, \u00f6=\u00f6");

What OS are you using? What happens when you put the above code into a class and compile it at the command line/terminal? You can put that one statement into the main() method.
2 hours ago

Mike London wrote:. . . when I try to Integer.parseInt(), it fails with a number format exception. . . .

You can't have tried to pass a byte[] to that method because none of its overloadings takes byte[] as a parameter, so that would fail to compile.
4 hours ago

Earlier today, I wrote:...if you change the String to a byte[] . . .

I tried it on JShell:-

jshell> "2".getBytes()
$1 ==> byte[1] { 50 }

Adding the UTF_8 charset didn't make any difference, so please check whether your text is actually in UTF8.
4 hours ago
Please start by telling us what the characters are. Some OSs have difficulty with some characters, but it shouldn't, in theory, make any difference to Swing.
4 hours ago
Welcome to the Ranch

I am afraid many people are reluctant to click on unfamiliar links, so you may get little response  
12 hours ago

Stephan van Hulst wrote:. . . not worried about somebody consuming input using your utility class . . .

How could you avoid that? If anybody writes new Scanner( anywhere, you are up the creek without a paddle anyway.
12 hours ago
...and if you change the String to a byte[], you are not simply getting 2. Please print out that text because I think you are getting more than you expected, possibly quote marks.
12 hours ago
I suppose it is possible to have multiple Scanners reading, but I agree it is a bad idea and can lead to confusion as to which input is read where. Also, remember that Scanners are not thread‑safe; the simplest answer to this problem is that when you move to a multi‑threaded program, you restrict keyboard input to one thread and one thread only.
I prefer to keep the Scanner as private static final, and use it only via static methods in my utility class. That obviates the risk of anybody accessing the Scanner and doing something like changing the delimiter while nobody else is watching I don't pass my Scanner to methods in other classes. I don't pass my Scanner full stop.
16 hours ago
Sorry; I kept finding formatting errors in my preceeding post, and there was a (double) cast which I found was unnecessary, so I removed that, too.
17 hours ago
Agree: if you have an Order class, you can make it store the information. You can make it immutable (usually a good thing) with the record data structure.You can consider setting totalPrice from the constructor, banning negative/zero quantity or price, etc.The instance initialiser in lines 3‑7 converts the declaration of the List into an anonymous class, and that is one of the ways you can create a pre‑filled (mutable) List.
17 hours ago
Welcome to the Ranch

Moving this discussion because it would sit better in the cert. exam fora.
17 hours ago
Added your discussion to our Maven forum.
17 hours ago

John O Sullivan wrote:. . . On the mock exams, I got between 39-56% . . .

What's the pass mark? If it is 66% make sure you are getting over 70% in the mocks before sitting the real thing.
1 day ago
Kindly don't edit posts like that after they have been replied to; I am refusing the changes.
1 day ago