Browsing 7239 questions and answers with Jon Skeet

My java code does not synchronize

class MultiplyTable1 { synchronized void printTable(int n) { for (int i = 1; i <= 5; i++) { System.out.println(n * i); try { ...
Jon Skeet
people
quotationmark

You're creating two separate MultiplyTable1 objects. A synchronized instance method is effectively using: synchronized (this) { ... } so if you call that method on two different objects, they can still run in parallel. To see the... more 3/16/2014 7:41:53 AM

people

Parsing wrong element....I don't know how to parse day

try { InputStream in = getResources().openRawResource(R.raw.database); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document...
Jon Skeet
people
quotationmark

You're parsing the elements fine (at least as far as we can see) - it's just what you're doing with the result which is wrong. You've got a NodeList. Calling toString() on that isn't what you want - you're trying to get the name attribute... more 3/15/2014 12:30:28 PM

people

Returning an array of double values from string

String numbers = ("5,25,77,44,64,8,55,28,86,35"); I would like to return an array of double values from the string. I am unable to do that successfully with the following code...
Jon Skeet
people
quotationmark

You're calling toString() on an array - and arrays don't override Object.toString(). So you get the behaviour from Object.toString(): The toString method for class Object returns a string consisting of the name of the class of which... more 3/14/2014 8:44:10 PM

people

differentiate among multiple webclient results

There is a List. I want to download each url via webclient.DownloadStringAsync the problem I encounter is: how do I know which e.Result corresponds to what url ? public class...
Jon Skeet
people
quotationmark

the problem I encounter is: how do I know which e.Result corresponds to what url ? There are various different options for this: UserState You can pass in a second argument to DownloadStringAsync, which is then available via... more 3/14/2014 8:29:31 PM

people

Why can't create instance of local class in Java?

If I have this code. public class Test{ { class People { } } public static void main(String[] args) { People person...
Jon Skeet
people
quotationmark

(Adding a second answer as my wrong one had three upvotes already.) You can declare a class within an initializer block - but its scope is that initializer block, just like if you declared it in a method. So this works: public class Test... more 3/14/2014 7:16:11 PM

people

Closures behavior

This function returns two different values depending on the way its called. I understand that Closures close over variables, not over values and I expected the values returned...
Jon Skeet
people
quotationmark

Each time you call Sum, you're creating a separate test delegate closing over a new test variable. The difference isn't "whether or not you use Invoke" but "whether you're using the result of a new call to Sum(). To demonstrate this, you... more 3/14/2014 6:16:01 PM

people

Property losing value even though declared Public

I've a file SiteMinder.CS in App_code where I set the UserID who has accessed the webpage public class SiteMinder : IHttpModule { public string UserID { get; set; } ...
Jon Skeet
people
quotationmark

You're creating a new SiteMinder object. That's not the same object that had the property set on it, so the property will have the default value (null). You need to obtain a reference to the original SiteMinder object which set the... more 3/14/2014 4:32:46 PM

people

Dynamically constructing an Expression<Func<T,bool>> doesn't work for GreaterThen

Hi I have a simple query in Entity Framework: using (var db = new BookstoreContext()) { return db.Book .Where(w => w.PublishedYear > 2005) ...
Jon Skeet
people
quotationmark

The problem is the nullability. You could probably get away with just adding a conversion expression from the value to the type of the property: public Expression<Func<Book, bool>> GreaterThan(string columnName, object... more 3/14/2014 4:01:54 PM

people

PreparedStatement Update showing error ORA 00927 missing equal sign

I am trying to update the records in database according to data read from an Excel sheet. I have more than 50 columns in db whose column names are stored in an array...
Jon Skeet
people
quotationmark

I suspect this is due to the LEAD TIME BUCKET column name, which should either have underscores (like the other column names) or be escaped somehow - the spaces within the column name are causing the error. It would be better to have... more 3/14/2014 10:29:12 AM

people

Fastest way to check if value is in array many times

I have an array of some values between -15 and 31 and I have to check, if some x is in this array for ~300 000 000 times. Because there is negative values, I can't create boolean...
Jon Skeet
people
quotationmark

You could easily create a boolean array and just offset the index: // Do this once... int minValueInclusive = -15; int maxValueExclusive = 31; boolean[] presence = new boolean[maxValueExclusive - minValueInclusive + 1]; for (int value :... more 3/14/2014 10:02:51 AM

people