Browsing 7239 questions and answers with Jon Skeet

How to remove xmlns="" from xml request

i'm trying to remove blank xmlns from the xml request generated from stub that i've auto-generated from a wsdl using the axis wizard. Axis wizard generates the request class in...
Jon Skeet
people
quotationmark

You should specify the same namespace URI for your nested elements: elemField.setXmlName(new javax.xml.namespace.QName("http://myNamespace", "DestinationIdsInfo")) (Ditto for... more 9/25/2013 12:22:08 PM

people

Strange behaviour of Scanner.nextFloat

If I execute the following code: import java.util.Scanner; public class ScannerTest { public static void main(String[] args) { Scanner s = null; ...
Jon Skeet
people
quotationmark

Can somebody explain why this happens As you said, it's using your default locale. Print Locale.getDefault() to check what your default locale is. Note that Float.parseFloat is not locale-specific. and how can I make the Scanner... more 9/25/2013 9:47:08 AM

people

Java Simple Date Format Time Issues

SimpleDateFormat sdf1 = new SimpleDateFormat(yyyy-MM-dd kk:mm:ss); SimpleDateFormat sdf2 = new SimpleDateFormat(yyyy-MM-dd HH:mm:ss); Calendar cal = Calendar.getInstance(); Date d...
Jon Skeet
people
quotationmark

There's no reason why there should be an error. k is documentedin SimpleDateFormat as a field for: Hour in day (1-24) That explains why you get 24 for midnight instead of 00, too. If you don't want values between 01 and 24, don't use... more 9/25/2013 6:25:29 AM

people

Static final variable along with static initializer block

I made a class that contains: static final variable static initializer block with a System.out.println() statement If I call the static final variable from another class, the...
Jon Skeet
people
quotationmark

My guess is that your field is of either a primitive type or String, and is initialized with a compile-time constant expression. For static final fields initialized with a constant expression (and only such fields) - any code which refers... more 9/25/2013 6:10:49 AM

people

C#, thread priorities, and locks

In C#, if a high priority task is ready to execute and another (low priority) thread is already inside a monitor, would the low priority task be preempted in the following two...
Jon Skeet
people
quotationmark

If the higher priority thread is waiting for a lock, regardless of which thread owns the lock, it won't be scheduled. If the higher priority thread isn't waiting for anything, then it may preempt a lower priority thread. None of this is... more 9/25/2013 5:53:11 AM

people

Why is this code not threadsafe?

I have a piece of code like this: public class UserCache { private Dictionary<int, User> _users = new Dictionary<int, User>(); public User GetUser(int id) ...
Jon Skeet
people
quotationmark

No, it's not thread-safe. Imagine it's called twice at the same time with the same ID, which isn't previously present. Both threads would get as far as RetrieveUser, and they'd both call _users.Add(id, u). The second call would fail... more 9/24/2013 10:00:16 PM

people

Exit my while loop at a specific day and time

I have a while loop that will be continually processing information over the weekend. On Monday at 8:00 am I would like this process to stop. I have this running inside my while...
Jon Skeet
people
quotationmark

It sounds to me like it's as simple as: DateTime currentDate = DateTime.Now; if (currentDate.DayOfWeek == DayOfWeek.Monday && currentDate.Hour >= 8) { runLoop = false; } more 9/24/2013 9:58:34 PM

people

Using a nested for loop and getting unexpected repetitions in c#

I've the following code in c# visual basic 2010: for (int i = 7; i > 0; i--) { Char star = '*'; string numbers = "765432" ; //Console.WriteLine(star); for...
Jon Skeet
people
quotationmark

This is the problem (I suspect, anyway - it's certainly a problem): numbers.TrimEnd(numbers[numbers.Length - 1]); Strings are immutable in .NET. TrimEnd doesn't change the existing string - it returns a reference to a new one. As... more 9/24/2013 9:42:50 PM

people

Reading XML nested node values

Having an issue grabbing values in an XML file The structure is as followed <configuration> <settings> <add key="folder" value = "c:\...." /> ...
Jon Skeet
people
quotationmark

The name of the element isn't folder... that's the value of the key attribute. Also note that as you've used XElement.Load, the element is the configuration element - asking for Elements("configuration") will give you an empty collection.... more 9/24/2013 7:57:06 PM

people

For loop skips straight to the end

I started studying C# and I encountered a problem with one of my assignments. The assignment is to create a pyramid made of stars. The height is designated by user input. For...
Jon Skeet
people
quotationmark

The condition in a for loop is the condition which has to keep being true in order to go into the loop body. So this: for (int height = bar; height == 0; height--) should be: for (int height = bar; height >= 0;... more 9/24/2013 7:15:01 PM

people