Browsing 7239 questions and answers with Jon Skeet

How can I sort a list using a method that uses the list's item as a parameter?

Let's say that I have the following list and method: List<myObject> myList = (some function that prepopulates myList); I would like to sort myList in descending order...
Jon Skeet
people
quotationmark

LINQ makes this easy: // Method group conversion List<myObject> sorted = myList.OrderByDescending(SortByThisValue).ToList(); // Lambda expression List<myObject> sorted = myList.OrderByDescending(x => SortByThisValue(x)) ... more 9/16/2013 4:40:25 PM

people

The output value is expeceted to be from 0 to 1 but sometimes it produces more than 1

I have the following neural network which uses RPOP - Resilent back propagation NetCore = new BasicNetwork(); NetCore.AddLayer(new BasicLayer(null, false,...
Jon Skeet
people
quotationmark

After training the network, the error rate is minimized to around 1%, i pass the test data and most of the time the output is produced something like this "5,07080020755566E-10" where i expect numbers from 0 to 1 and also it should be... more 9/16/2013 2:08:56 PM

people

Superclass method cannot find overridden method in subclass

public class test { public static void main(String[] args) { new Person().printPerson(); new Student().printPerson(); } } class Student extends...
Jon Skeet
people
quotationmark

The parent getInfo() is private but does that mean that the second call of printPerson() is prevented from finding the child getInfo() (which is public)? Yes. The subclass's getInfo() method is not overriding the superclass's one, as... more 9/16/2013 6:12:52 AM

people

Convert yyyy mm ddThh:mm:ssz to date time hour comes back incorrect

I have a string in the following format: yyyy-mm-ddThh:mm:ssZ Example string: 2013-09-15T00:24:26.4215967Z I need to convert this in to a date time, so I use the following...
Jon Skeet
people
quotationmark

Why is the 00 in the time being converted to 10 am? XmlConvert.ToDateTime(string) returns a DateTime with a Kind of Local - in other words, it's converting the UTC value to the equivalent system local time. Presumably you're in a time... more 9/16/2013 6:07:17 AM

people

Does increase in the number of comments increases the execution time?

Consider the following cases: Case 1: (Less comments in for loop) import java.io.IOException; public class Stopwatch { private static long start; public static void...
Jon Skeet
people
quotationmark

Question: If we add more comments, does the program takes more time to execute? Why? No. Comments have no effect on execution. They will slow the compiler down a tiny bit - but even that should be imperceptible unless you have a... more 9/16/2013 5:54:21 AM

people

Why is the order in which notify() is called in the following blocking queue example important?

I wrote a simple Blocking Queue example for a Prod-Cons problem. The example below won't work; unless I swap the add/remove part of the enqueue/dequeue logic with notify on the...
Jon Skeet
people
quotationmark

In the enqueue part, shouldn't it be correct to add the element and then notify? That part doesn't really matter, as you're in a synchronized method - the other threads won't get to run until you've left the enqueue method anyway.... more 9/16/2013 5:51:44 AM

people

Serving Multiple Clients

I wonder if it is really possible for a simple server program using server socket can handle multiple clients at the same time simultaneously? I am creating a server program that...
Jon Skeet
people
quotationmark

The code you've posted doesn't actually do anything with the client connection, which makes it hard to help you. But yes, it's entirely possible for a server to handle multiple concurrent connections. My guess is that the problem is that... more 9/16/2013 5:46:23 AM

people

What happens when you change a reference inside a method? (7)

What happens when you change a reference inside a method? public void reverseX(int[] nums) { int[] nums2 = new int[nums.length] ; for( int i=0 ; i < nums.length ; i++...
Jon Skeet
people
quotationmark

Objects, reference types are suppose to be immutable. Not all of them. Some, but not all. For example, String is immutable, but StringBuilder isn't. All arrays are mutable. What happens here when nums is set to nums2. The nums... more 9/15/2013 4:37:51 PM

people

How is 0x80000000 equated to 2147483648 in java?

Taking the binary of 0x80000000 we get 1000 0000 0000 0000 0000 0000 0000 0000 How does this equate to -2147483648. I got this question with this program. class a { ...
Jon Skeet
people
quotationmark

This is what happens with signed integer overflow, basically. It's simpler to take byte as an example. A byte value is always in the range -128 to 127 (inclusive). So if you have a value of 127 (which is 0x7f) if you add 1, you get -128.... more 9/15/2013 3:25:07 PM

people