Browsing 7239 questions and answers with Jon Skeet

use of Enums in java with different datatypes

Why it is said that use of enums is better in java. In case if you have constants for which datatypes are different I think it is better to use class with constants instead of...
Jon Skeet
people
quotationmark

One benefit of using enums is that it's strongly typed. Consider two sets of constants, both of which have integer representations. If you just use fields as you've proposed, there's nothing to stop you from passing the wrong kind of value... more 1/1/2014 10:37:17 PM

people

continue on assert

Is there any way to continue test after Assert? .. I need to see all cases which the assert causes. foreach (var ex in data) { Assert.AreEqual(ex1, ex, msg); }
Jon Skeet
people
quotationmark

No, you can't - Assert will throw an exception if it fails, and you can't just keep going after the exception. You could catch the exceptions, and then add them into a collection... but it's not terribly nice. If you're trying to... more 1/1/2014 8:12:43 PM

people

Insert command string building

I could not find the error in the following insert command string. Let me know if you notice any. What is the best way to build this type of command string.It becomes very...
Jon Skeet
people
quotationmark

What is the best way to build this type of command string. You use parameterized SQL. Do not concatenate the values you want to use into the SQL like this. It opens you up to SQL injection attacks, conversion errors, and generally... more 1/1/2014 8:10:07 PM

people

Is namespace in C# is something similar to package in Java

Exacly as stated in the subject. I do not understand idea of the namespace. Is that something which should work like package in Java?
Jon Skeet
people
quotationmark

They're similar but not the same. In particular, names are also used for access control in Java (where the default access makes a member available within the same package). That's not the case in .NET - namespaces don't come into... more 1/1/2014 7:18:08 PM

people

AsyncTask Returns Error

I have been trying to parse XML files using Asynctask, following [1] and [2] tutorials. I have implemented a class in my Activity as follows: private class GetRoutes extends...
Jon Skeet
people
quotationmark

We'll your log shows a NumberFormatException at RouteReader lines 35. That's not a NullPointerException - it's a failure to parse a string as an integer, because the string is "1S". You should work out what you want to do with invalid... more 1/1/2014 7:12:55 PM

people

ref and out arguments in async method

Does anyone know why async methods are not allowed to have ref and out arguments? I've done a bit or research on it but the only thing I could find was that it has to do with the...
Jon Skeet
people
quotationmark

Does anyone know why async methods are not allowed to have ref and out arguments? Sure. Think about it - an async method usually returns almost immediately, long before most of the actual logic is executed... that's done... more 1/1/2014 11:27:09 AM

people

Valid TimeStamp difference between JDK 6 & JDK 7

Is the below statement valid in Java 7? Timestamp.valueOf("0000-00-00 00:00:00.000000"); because building the above code with JDK 1.6 works just fine but while doing the same...
Jon Skeet
people
quotationmark

Well it's syntactically valid Java code, but I wouldn't expect it to work at execution time: 0 isn't a valid month 0 isn't a valid day-of-month 0 may or may not be a valid year, depending on how you're counting things. (It appears to... more 1/1/2014 11:14:33 AM

people

Object passed to method in java works on original copy

I have Sample class with one field and I am doing following things: Calling method with object of this class as a parameter. Make some operations on this object. Original object...
Jon Skeet
people
quotationmark

You're not doing the same thing with BigInteger - you're calling the add method which returns a reference to a new BigInteger, and you're assigning that value back to big. Your Sample.add method changes the existing object... more 1/1/2014 10:59:34 AM

people

Java : Create new ArrayLists based on some condition from existing ArrayList

I am new to java . I have 2 ArrayLists of Strings List<String> a= [2,14] List<String> b= [2,3,4,5] I want two new ArrayLists 1) List has the value which is in b...
Jon Skeet
people
quotationmark

You're really proposing set operations more than list operations - in which case you'd be better off using a HashSet than an ArrayList. Then you could use Collection<E>.removeAll: Set<String> a = ...; Set<String> b =... more 1/1/2014 10:10:27 AM

people

How to Convert ADO.NET to LINQ?

"SELECT TOP " + this.mintPageSize + " * FROM tblGroupDetail WHERE GroupDetailId NOT IN " + "(SELECT TOP " + intSkip + " GroupDetailId FROM tblGroupDetail)") How Convert this...
Jon Skeet
people
quotationmark

I suspect you just need: var query = db.GroupDetail .OrderBy(...) // You really need an ordering .Skip(intSkip) .Take(mintPageSize); You should work out what ordering you want, otherwise "the... more 1/1/2014 9:58:06 AM

people