Browsing 7239 questions and answers with Jon Skeet

NodaTime usage for datetimepicker

To avoid label of duplicate here's a brief summary of all what i did. After spending hours of googling to calculate the difference between two dates I came across here and here...
Jon Skeet
people
quotationmark

You're performing three separate computations here. You only need one: var appointment = LocalDateTime.FromDateTime(dateTimePicker1.Value).Date; var retirement = LocalDateTime.FromDateTime(dateTimePicker2.Value).Date; var difference =... more 3/9/2015 10:27:26 AM

people

Understanding narrowing primitive conversion

I'm trying to understand the narrowing primitive conversion concept in Java. Here's what the JLS 5.1.3 says about it: 22 specific conversions on primitive types are called the...
Jon Skeet
people
quotationmark

Since there is the implicit conversion converting long to int There isn't. There's an explicit conversion. Narrowing conversions aren't generally applied implicitly, precisely because they can lose information. So you'd need: int c... more 3/9/2015 7:14:45 AM

people

Java EE VS. Java SE programming

I know the difference between Java EE and Java SE. But my question, is there difference in the Java programming language for Java SE and Java EE? Means I've learned Java and...
Jon Skeet
people
quotationmark

No, the language itself is the same - it's just a matter of the environment in which it's used, basically. It's probably more important to be aware of the differences between different versions of Java (e.g. Java 7 and Java 8) in terms of... more 3/9/2015 7:06:30 AM

people

Does the order of operands matter for an overloaded == operator in C#

I am using a 3rd party tool (Unity3d), where one of the fundamental base classes overloads the == operator (UnityEngine.Object). The overloaded operator's signature is: public...
Jon Skeet
people
quotationmark

Well, it's possible that the two calls wouldn't be the same, if the operator had been overloaded badly. Either there could be one overload, and it could be written in a way which compares the operands asymmetrically, or the two statements... more 3/9/2015 6:49:28 AM

people

Inconsistency in returning primitive arrays in Java

The following show different ways of instantiating and returning a primitive array. However, for some reason, the last one doesn't work. Is there a valid explanation for this...
Jon Skeet
people
quotationmark

Why doesn't the last block work? Because an array initializer (JLS 10.6) is only valid in either a variable declaration, as per your first and second blocks, or as part of an array creation expression (JLS 15.10.1), as per your third... more 3/8/2015 1:15:03 PM

people

Is there a way for a property to set its backing value?

I have a property, and I want it to set another property whenever it's being set. For example: private double Bpm { set { <myself> =...
Jon Skeet
people
quotationmark

A property is just a pair of methods, really - and if you use an automatically-implemented property, the compiler implements them for you and creates a field. You want one field - because you've only got one real value, and two views on it... more 3/7/2015 12:55:03 PM

people

Program that reads file with numbers

I am working on a program that read the file with car model and fuel consumption. In file I have cars like A|12.45, where A stand for model and number stands for fuel consumption...
Jon Skeet
people
quotationmark

I strongly suspect this is because the default culture on your machine is one that uses , instead of . for a decimal separator. You can use double.Parse and specify CultureInfo.InvariantCulture to parse it using the invariant culture which... more 3/7/2015 12:35:50 PM

people

NoClassDefFound means that the class cannot be found?

I don't understand NoClassDefFoundError in the context of running an OpenEJB client: thufir@doge:~$ thufir@doge:~$ java -classpath...
Jon Skeet
people
quotationmark

You include the jar file in the classpath when you execute by simply putting it in that list of jar files you've already got - you're already specifying openejb-client-4.7.1.jar etc; just add javaee-api-7.0.jar to that list (with the right... more 3/7/2015 10:29:36 AM

people

Can a public method of a public class be called in the main by just its name like "method()" in place of "classname.method()"?

I came across this code in hackerrank.com which made me ask this question: import java.io.*; import java.util.*; import java.text.*; import java.math.*; import...
Jon Skeet
people
quotationmark

Here, shouldn't it be Solution.solveMeFirst(a,b); You could call it that, but you certainly don't have to. The detailed rules for finding the meaning of a name are given in JLS 6.5, but basically the compiler will search through the... more 3/7/2015 10:17:19 AM

people

What to use instead of the 'new' statement in bukkit plugins/java

Well, I'm tring to make a bukkit plugin that checks for a YAML file called 'config.yml' but to do that I would need to do: Config = new File(this.getDataFolder(),...
Jon Skeet
people
quotationmark

I suspect you just want: if (Config.exists()) { Configs = YamlConfiguration.loadConfiguration(Config); } (Now would be a good time to learn about Java naming conventions, by the way - variables in Java conventionally start with a... more 3/7/2015 10:00:40 AM

people