Browsing 7239 questions and answers with Jon Skeet

Why first enumeration of encrypting data takes so long

I want to create performance test where I am encrypting data using AES with PKCPadding5/7 depends on provider(IBM or BouncyCastle) on aix system. My question is why first...
Jon Skeet
people
quotationmark

Revised answer There's time taken to load and JIT-compile the code on the first call - that's why typically benchmarks don't include the first run. (In fact, many JVMs re-JIT more and more aggressively, so the performance improves over... more 4/1/2014 1:59:01 PM

people

Overcoming generics put get rule

I have read about the generics get and put rule that should prevent you from adding a Banana to a List<? extends Fruit>: public abstract class Fruit { } public class Banana...
Jon Skeet
people
quotationmark

No, it's absolutely fine to have two different kinds of Fruit in a List<Fruit>. The issue comes when you've actually created a List<Banana>. For example: List<Banana> bananas = new ArrayList<>(); bananas.add(new... more 4/1/2014 1:15:39 PM

people

Improper output of the following String programs

public class NoOfConsAlphabet { public static void main(String[] args) { String str="aaabbddaabbcc"; int count=1; String finalString=""; for(int...
Jon Skeet
people
quotationmark

This is the problem: str.charAt(i)+count+"," That's performing a char + int conversion, which is just integer arithmetic, because + is left-associative. The resulting integer is then converted to a string when "," is concatenated with... more 4/1/2014 12:30:33 PM

people

Java enum custom names

I want to have a Java enum whose values are integers. For example: public enum TaskStatus { TaskCreated(1), TaskDeleted(2) } But I also want custom names for...
Jon Skeet
people
quotationmark

Just add a field for that: public enum TaskStatus { TaskCreated(1, "Task Created"), TaskDeleted(2, "Task Deleted"); private final int value; private final String description; private TaskStatus(int value, String... more 4/1/2014 11:37:13 AM

people

why variable defined in a class is not a local variable but instance variable in java?

According to the doc Local variables in java are declared in methods, constructors, or blocks. In the below Class A isn't x a local variable too since it is in blocks({}) i know...
Jon Skeet
people
quotationmark

In the below Class A isn't x a local variable too since it is in blocks({}) No. It's not in a block. It's in a class declaration, but that's not a block as such. "Block" isn't synonymous with "text in braces". To be a bit clearer,... more 4/1/2014 8:19:19 AM

people

XmlDocument file name with space

I have XML file that contains services names in windows7, one of the services has white space i.e "service name" I get exception when I load the file: fileName = file; pathToFile...
Jon Skeet
people
quotationmark

The problem has nothing to do with the name of the XML file, or the code you posted. It has everything to do with the XML being invalid. XML element names can't contain spaces, so this isn't valid: <Service-1 Agent/> Instead, you... more 4/1/2014 7:47:52 AM

people

How to add xmlns attribute to the root element?

I have to write xml file like the fallowing <VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> ...
Jon Skeet
people
quotationmark

LINQ to XML makes this trivial - you just specify the namespace for the element, and it will include the xmlns="..." automatically. You can give it an alias, but that's slightly harder. To produce the exact document you've shown, you just... more 4/1/2014 6:14:51 AM

people

Why does adding float give different result depending on how its performed

I have run in to an issue when adding floats in C#. The following is taken from the immediate window in Visual Studio. I have declared f as float, and now do a simple calculation...
Jon Skeet
people
quotationmark

As i see it, the numbers are nowhere near the precision limit of the float They really are - or rather, the difference is. The exact values involved are 8.52500057220458984375 (rounded up to 8.525001 for display) and... more 4/1/2014 5:55:29 AM

people

Why I get "Comparison method violates its general contract"

if I call this line of code Arrays.sort(allNew, 0, sizeNew, mCatBPosComparator); with that comparator private class BPosComparator implements Comparator<CatBPos> { ...
Jon Skeet
people
quotationmark

I suspect this is at least one immediate problem: if (p1.getBPos().isDeparture() && p2.getBPos().isVacation()) { return SWAP_BPOS; } else if (p1.getBPos().isVacation() && p2.getBPos().isDeparture()) { return... more 3/31/2014 5:38:12 PM

people

ids cannot be resolved or is not a field

I'm new to android development and I'm currently working on building a pretty basic application. I want 'button1' to open a new activity. Looked around online and I can't work out...
Jon Skeet
people
quotationmark

Your super call is outside the method. This: public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); { ... } should be: public void onCreate(Bundle savedInstanceState) { ... more 3/31/2014 4:52:37 PM

people