Browsing 7239 questions and answers with Jon Skeet

+ operator on String and char values in println() method in Java

I have following code snippet and their output below: String System.out.println("A"); // output A System.out.println("B"); // output...
Jon Skeet
people
quotationmark

What is the reason that char's out is getting printed as string for single char value where as integer if + operator is used? There's no + operator for char, so both operands are being promoted to int (values 65 and 66 respectively,... more 5/22/2015 12:11:15 PM

people

Lightweigth default StreamReader reading nothing

I am in the need of a default StreamReader reading nothing without throwing any exceptions. How can I efficiently construct such an object? Edit Specifically, if I read from the...
Jon Skeet
people
quotationmark

Ideally, I would suggest using TextReader as your abstraction level - it's rarely necessary to depend on StreamReader directly, as messing around with the underlying stream is generally a bad idea anyway. If you have code that takes a... more 5/22/2015 8:32:57 AM

people

Timestamp and UTC kind

In my application i receive Time stamp and in c# code I convert into date and pass this date to execute the stored procedure .My application is placed in server machine. But when...
Jon Skeet
people
quotationmark

Well currently you're converting the UTC timestamp to the system-local time - and presumably your server is in a different time zone to you. I would strongly advise you to log the UTC timestamp directly, in UTC. Whatever reads your logs... more 5/22/2015 6:14:06 AM

people

Why registering a generic type with one type parameter to Unity Container fails here?

I am trying to register a generic type to unitycontainer via configuration file, as shown below in a simplified way. However on the LoadConfiguration method call I get an...
Jon Skeet
people
quotationmark

Looking at the documentation again, I think you want to use backticks or square brackets for the open type in the alias target, but not for the closed type or the alias itself: <unity... more 5/22/2015 6:02:23 AM

people

DateTime.TryParseExact returning false for localized date

I am trying to parse a Dutch date from some logfiles but C# DateTime.TryParseExact is always returning false: DateTime.TryParseExact("mei 21, 2015 12:25:35:719 AM", "MMM dd, yyyy...
Jon Skeet
people
quotationmark

It looks like that culture doesn't use an AM designator: var culture = new CultureInfo("nl-BE"); Console.WriteLine("x{0}x", culture.DateTimeFormat.AMDesignator); That prints xx, suggesting that the AM designator is empty. You can... more 5/21/2015 6:20:25 PM

people

Why can't I add extra argument validation in the subclass constructor?

I have two classes. The superclass: public abstract class Question(){ public Question(String question, String answer, String... alts){... } And the subclass: public class...
Jon Skeet
people
quotationmark

As kocko notes, the super statement must be the first statement in your constructor. However, if you really, really don't want to get as far as the superconstructor before validating (e.g. because it will blow up with a less-helpful... more 5/21/2015 1:08:46 PM

people

Java memory reference issue

Why does the below mentioned code prints 4,3,2,1,0 and why not 4,4,4,4,4. Since the reference sb is same so why not it pointing towards the last updated value and why not it...
Jon Skeet
people
quotationmark

Since the reference sb is same It's not. You're using the sb variable each time, but each time you call stack.add(sb) it's adding "the current value of sb" which is different on each iteration due to this line: sb = new... more 5/21/2015 10:35:27 AM

people

Why am I getting a weird results from my scaleImage method?

I'm trying to scale an image in relation to the width/height. Here is my method: private byte[] scaleImage(Bitmap image) { byte[] image = new byte[]{}; int width=...
Jon Skeet
people
quotationmark

You're running into a problem of integer arithmetic, basically - you're performing a division to get a scaling factor, but as an integer - so for something like 640x480, the scaling factors would be 1 and 0, because 640/480 is 1, and... more 5/21/2015 10:21:40 AM

people

JIT stands for Just In Time compiler. what is the meaning of compiler here

Can we compare JIT with inline function? how It works and why we call it compiler, when JVM is combination of Java Interpreter and OS.
Jon Skeet
people
quotationmark

The JIT "compiles" bytecode to native machine code which can then be run directly on further calls. In practice, many JVMs (e.g. Hotspot) will JIT-compile the same bytecode multiple times, adapting the optimization settings based on... more 5/21/2015 6:04:35 AM

people

shorthand for ctor delegate

I have the following lambda expression: Something((o, i) => new TheNewSwiss(o, i)); Is there a shorthand syntax? Something simliar to this but for ctors? Something((o, i)...
Jon Skeet
people
quotationmark

No, there's no equivalent of method group conversions for constructors. (I can see it being handy, but it doesn't exist.) You just need to use the lambda expression syntax you've got in your first snippet. more 5/20/2015 6:25:16 PM

people