Browsing 7239 questions and answers with Jon Skeet

Why My Code is working perfectly without the using of synchronization ..?

i am facing something confusion with my code behavior in my operation system .. You all now that there is a lot of ways to make a synchronization for multi-threading in order to...
Jon Skeet
people
quotationmark

I suspect your JVM happens to have generated code where count++ is JIT-compiled into an atomic operation... even though it's not guaranteed to... and your computer's memory model isn't as lax as it could be. It's still unsafe - it's just... more 10/14/2014 9:11:06 PM

people

Move rs to method causes Exception

I have some duplicated following code rs = prepStmt.executeQuery(); rs.next(); I want to move it to a method so that I can reuse the code. The method is like: public static...
Jon Skeet
people
quotationmark

You seem to be assuming that the change to the rs parameter will be propagated to the calling code. It won't. Everything in Java is passed by value - including references. Instead, you should probably do something like: public static... more 10/14/2014 3:03:50 PM

people

Youtube api V3 nuget error visual studio 2012

I'm trying to install Youtube api V3 using nuget package manager console I'm typing there Install-Package Google.Apis.YouTube.v3 but i got an error Install-Package : The...
Jon Skeet
people
quotationmark

You basically just need to update the version of NuGet installed with Visual Studio. Go to the Tools menu and select "Extensions and updates", then find "NuGet Package Manager" (at least that's what I assume it's called, based on what I... more 10/14/2014 1:58:37 PM

people

Java HttpClient getting response with illegal character in url

I'm trying to scrape data from the website Squawka.com. For example, when I'm trying to scrape data from:...
Jon Skeet
people
quotationmark

Everything beyond the # is the fragment identifier. It's not sent to the server as part of the request - in this case it would be used by the Javascript on the page to perform extra filtering. When fetching the page programmatically, you... more 10/14/2014 1:46:06 PM

people

does a List<> when changed change all other references to the LIst<>?

As we all know in Java if you change a object 'everyone' that has a reference to that object also changes like in the following example. List<String> mainList = new...
Jon Skeet
people
quotationmark

It sounds like you just want a shallow clone, e.g. List<String> referencedStrings = new ArrayList<>(referencedStrings); That will take a copy of the existing list - but as the list only contains references, any changes to... more 10/14/2014 1:27:20 PM

people

Calendar.WEEK_OF_YEAR is returning a wrong value?

I tried getting week of the year through below code but it always returns "3", I even set the timezone to GMT but still returning the same value("3"). Please help me out over...
Jon Skeet
people
quotationmark

You're setting the minutes not the month. It sounds like it's parsing this as 2014-01-14T00:10:00, and that January 14th 2014 is in the third week. You want MM for months, not mm. (I'd also encourage you to use yyyy-MM-dd if you get a... more 10/14/2014 12:06:59 PM

people

How and when the type gets resolved for generic methods in java?

I expect following Unit Test to fail with ClassCastException, but its passing. The class has a generic method whose second parameter and return value are of type V. On calling...
Jon Skeet
people
quotationmark

This is due to type erasure. Basically, the types of K and V aren't known at execution time. The cast to V is unchecked - and you should have received a warning for this at compile-time (possibly suggesting that you compile with... more 10/14/2014 11:06:44 AM

people

Take child node value via lambda expression

I want to take value from name node and fix node using a lambda expression. <Issue> <name>asdasasdasd</name> <fix>zxcczxczxczzxc...
Jon Skeet
people
quotationmark

Your question is far from clear, but I suspect you may want something like: // I would strongly discourage you from using global variables... var issues = doc.Descendants("Issue") .Select(x => new IssueModel((string)... more 10/14/2014 6:14:41 AM

people

How can I check if it is between 2pm and 1am new york time?

I need to check if the time in new york time zone is between 2pm and 1 am but i am not sure how to select the timezone or what to do next String string1 = "14:00:00"; Date...
Jon Skeet
people
quotationmark

If you're interested in whether the current time is "after or equal to 2pm, or before 1am" then don't need to use string parsing at all. You could use: TimeZone zone = TimeZone.getTimeZone("America/New_York"); Calendar calendar = new... more 10/13/2014 4:46:07 PM

people

Async using Microsoft.Bcl.Async on .net 4.0 in Visual Studion 2012

Trying to use Async using Microsoft.Bcl on .net 4.0 in Visual Studio 2012. Results does not show up. private void button3_Click(object sender, EventArgs e) { ...
Jon Skeet
people
quotationmark

This is the problem, which has nothing to do with the fact that you're using .NET 4: Task.WaitAll(tasks, -1); That will block until everything in tasks completes. At that point, your UI thread can't do any more work... but it has to do... more 10/13/2014 1:16:48 PM

people