Browsing 7239 questions and answers with Jon Skeet

How to send Json object through java sockets?

How do you send Json object's through sockets preferable through ObjectOutputStream class in java this is what I got so far s = new Socket("192.168.0.100", 7777); ...
Jon Skeet
people
quotationmark

Instead of using ObjectOutputStream, you should create an OutputStreamWriter, then use that to write the JSON text to the stream. You need to choose an encoding - I would suggest UTF-8. So for example: JSONObject json = new... more 2/22/2014 12:09:06 PM

people

Early Access to Async Action Results in ASP.NET MVC

When we use async action in MVC like below example, post model data is available earlier than 10 seconds in view(here in 1 second) ? I confused, How data available in 1 seccond...
Jon Skeet
people
quotationmark

You don't get to the return statement in 1 second. The method returns a Task<ActionResult> as soon as it reaches the first await expression which hasn't already completed. That task will not be completed (so you can't get its result)... more 2/22/2014 8:40:24 AM

people

async / await continuation

In the code below I need to execute the three Get... methods in parallel. When a Get... method completes I need to immediately call the Save... method. Note Save... takes thing...
Jon Skeet
people
quotationmark

Well, you could explicitly use ContinueWith - or you could break off each "get and save" into a separate async method or async lambda. For example: async Task GetAndSaveRedAsync(SomeThing thing, SomeRepository rep) { var red = await... more 2/22/2014 8:21:17 AM

people

Why the HttpServlet class is an abstract?

I am very confused. Why the HttpServlet class is an abstract? And what is the basic difference between bean and pojo?
Jon Skeet
people
quotationmark

Why would HttpServlet not be abstract? An instance of just HttpServlet would be useless - the whole point of a servlet is to be able to provide useful responses to requests, and HttpServlet can't do that. It's generally a good idea to... more 2/21/2014 5:34:03 PM

people

Why assertEquals(new int[]{1}, new int[]{1}) results in failure?

I was testing my shuffling class and came across one issue I cannot understand. Why does the following assert statement: assertEquals(new int[]{1}, new int[]{1}); results in...
Jon Skeet
people
quotationmark

but could someone explain me why Sure - arrays don't override equals, therefore they inherit the behaviour from Object, where any two distinct objects are non-equal. It's even simpler than the version you showed if you use a... more 2/21/2014 1:45:08 PM

people

Awaiting custom functions

I'm trying to get my head around the new async features in C#, and so far the strangest thing I've noticed is that every example for async features has a function that awaits...
Jon Skeet
people
quotationmark

You're not starting the task - so it will never finish. Use Task.Run instead of new Task and it will create and start the task for you. Note that you're still reading the file synchronously, which isn't ideal... and if your Subject... more 2/21/2014 12:27:04 PM

people

Exception like java.lang.IllegalArgumentException: fromIndex(XXX) > toIndex(XX)

I have a jqgrid, with pagination. User can enter data by themselves to neviaget between pages. I am getting error if user enter more than available pages on line 199 as shown in...
Jon Skeet
people
quotationmark

I would simplify it to: Work out the lower bound, which must be at least 0 and at most recipeList.size() Work out the exclusive upper bound, which must be at least 0 and at most recipeList.size() Take the sublist So: int start =... more 2/21/2014 12:20:40 PM

people

Reading from a file in by specifying start point and end point

I want to read from an input file in C#. Below is my code. public string ReadFromNewEntityFile() { string template=null; StringBuilder s = new...
Jon Skeet
people
quotationmark

Assuming your start/end "points" are actually lines, you basically need to read from the start and skip the lines until you reach the right one. Here's an easy way of doing it using File.ReadLines: var lines =... more 2/21/2014 11:46:20 AM

people

How to extract data from xml with namespace?

Data ("1.0.0") from attribute "version" fall into property. But the property "Event" in the same class remains empty. If cut namespace from XML, it will work. My...
Jon Skeet
people
quotationmark

Your event element is implicitly in the same namespace in the XML due to namespace defaulting, so you should specify that in your declaration: public class EventResponseData { [XmlElement(ElementName = "event", Namespace =... more 2/21/2014 10:29:38 AM

people

Constructor syntax for passing through arguments directly to members

Suppose I have an object: public class A { private int m_a; private int m_b; A(int a, int b) { m_a = a; m_b = b; } } This gets the job done...
Jon Skeet
people
quotationmark

This works but I have a hazy memory of being told it unnecessarily copies the integers into arguments a and b and then into m_a and m_b. Yes, the values are copied into the parameters a and b, and then into the state of the object... more 2/21/2014 10:01:37 AM

people