Browsing 7239 questions and answers with Jon Skeet

Character Array Java

This question is hard to be asked on Google even though is so simple. Basically I wrote this : public static void main(String[] args) { char cipher[] =...
Jon Skeet
people
quotationmark

So my question is just what is this 196 ? It's the UTF-16 code unit for 'a' (which is 97) followed by the UTF-16 code unit for 'c' (which is 99). Other than for string concatenation, operands of the addition operator undergo binary... more 10/27/2013 9:01:37 PM

people

ObjectInputStream being initialised causes an EOFException of the type IOException

I have been writing a to-do list app in java and each todo item is stored as an object of the class ToDo (which I created). The ToDo class is serializable and I am using an...
Jon Skeet
people
quotationmark

Yes, this is behaving as documented: Creates an ObjectInputStream that reads from the specified InputStream. A serialization stream header is read from the stream and verified. ... Throws: IOException - if an I/O error... more 10/27/2013 8:49:22 PM

people

Error in output while reading a file from mac

I am trying to read file from mac OS. The code and everything is correct. There is no error while running the program. Whereas, the result is coming with extra data along with...
Jon Skeet
people
quotationmark

You're reading an RTF (Rich Text Format) document. It does contain all that data - it's just that if you open it in an editor which understands RTF as a format, it will format the text for you using the information rather than displaying... more 10/27/2013 8:43:14 PM

people

Java (Joda): Seconds from midnight of LocalDateTime

I tried to use this: secondsFromMidnight = Seconds.secondsBetween(localDateTime.toLocalDate(), localDateTime).getSeconds(); but it throws an exception (cf. below). I...
Jon Skeet
people
quotationmark

If you want to know the time of day, in seconds since midnight, it would be easiest to just use getMillisOfDay(): int secondsOfDay = localDateTime.getMillisOfDay() / 1000; (Use DateTimeConstants.MILLIS_PER_SECOND if you really want to -... more 10/27/2013 7:26:23 PM

people

Why lock Prevents Timer Overlap

I was wondering how using lock prevents the System.Threading.Timer from overlapping the portion of code inside the lock statement but not the code outside it! ?, how is it...
Jon Skeet
people
quotationmark

Presumably because you've got multiple threads locking on the same object. The whole point of a lock statement is that only one thread can acquire any particular monitor at a time. If they didn't do that, they'd be pretty pointless! If... more 10/27/2013 6:12:30 PM

people

List of Dictionary to List of another Dictionary

I have a huge list of Dictionary like List<Dictionary<String,SomeType>> Dict = new List<Dictionary<string,SomeType>>(); I need to convert to the list...
Jon Skeet
people
quotationmark

Yes, you can use LINQ: AnotherDict = Dict.Select(d => d.ToDictionary(pair => pair.Key, pair => Convert(pair.Value))) .ToList(); Where Convert is whatever... more 10/27/2013 9:26:27 AM

people

Unknown StackOverFlow Error which may be Related to Class Object ArrayList & Data Storing

Here's the error code I got: Exception in thread "main" java.lang.StackOverflowError at JavaKeywords.<init>(JavaKeywords.java:5) at...
Jon Skeet
people
quotationmark

The problem is that in order to create an LStore instance, you create an LAddClass - and in order to create an LAddClass instance, you create an LStore instance. So one constructor is effectively calling the other, which is calling the... more 10/27/2013 9:21:58 AM

people

How to call a subclass method from superclass?

Java newbie here. Banana and Apple extend Fruit (Fruit might as well be an abstract class since no Fruit will ever be instanciated). Banana and Apple both have a (wildly...
Jon Skeet
people
quotationmark

I would like to do fruit.toString() and have it run the Apple.toString() or Banana.toString() method based on what the fruit actually is. That's exactly what will happen automatically, so long as you're really overriding the existing... more 10/27/2013 9:12:08 AM

people

What's wrong with my method? Addition isn't working, always printing 0

public static void main(String args[]) { LinkedHashMap<String,Integer> map = new LinkedHashMap<String,Integer>(); Scanner scan = new Scanner(System.in); ...
Jon Skeet
people
quotationmark

This is the problem: addition(tokens, value); You're calling the method, but ignoring the return value. You should always be wary when you're calling a non-void method, but ignoring the return value. I suspect you want: value =... more 10/26/2013 6:34:48 PM

people

Is it possible to implement the hashCode() method in this case?

I have got a class which has two strings fields. Either of them (but not both) can be null. public class SimpleBluetoothDevice { final String macAddress; final String...
Jon Skeet
people
quotationmark

Currently you can't implement even equals in a way which obeys the contract of Object.equals which statesstates: The equals method implements an equivalence relation on non-null object references: ... It is transitive: for... more 10/26/2013 5:57:36 PM

people