Browsing 7239 questions and answers with Jon Skeet

Restrict the Joda timer to be not dependent with system time

I am making a Payroll and Attendance Monitoring system as a school project. Currently using Java Swing with Joda API. I'm in a part of attendance monitoring. I want a security...
Jon Skeet
people
quotationmark

If you're trusting anything from the user's computer, that's a bad start IMO. (What's to stop the user from manually modifying the data recorded?) Normally a server which you can trust would be involved. However, that's a different matter... more 3/28/2014 2:16:42 PM

people

java + converting String to Double appends trailing zero after decimal

I am not able to understand, why this code retursn 10.0, rather than 10 Double inputDouble = Double.valueOf("10"); System.out.println(inputDouble); The requirement is if I...
Jon Skeet
people
quotationmark

The requirement is if I pass 10.00, output should be 10.00 Then you're using the wrong type. double has no notion of significant digits - there's no difference between 10, 10.0 and 10.00. You should try using BigDecimal... more 3/28/2014 11:39:48 AM

people

Why would this program output "java.io.BufferedReader@Number"?

This is a quick one that stumps me. I've got a Java Program with the following code: public static void main(String[] args) throws IOException { // TODO Auto-generated...
Jon Skeet
people
quotationmark

You're printing out br1.toString() - you're calling toString() on the BufferedReader itself. BufferedReader doesn't override toString(), so you're getting the implementation from Object, as documented: The toString method for class... more 3/28/2014 6:48:09 AM

people

StringIndexOutOfBoundException in Java

How to avoid StringIndexOutOfBoundException in this code ? I want to get every two characters in the string. String path = input.nextLine(); for(int i = 0; i <...
Jon Skeet
people
quotationmark

On the last iteration, i will be equal to path.length() - 1. Therefore in this statement: String nPlus1 = path.substring(i+1, i+2); ... the first argument will be equal to path.length(), and the second argument will be equal to... more 3/27/2014 7:55:10 PM

people

GroupBy and Select extension method assistance

I am trying to GroupBy a few fields using the following code: var cars = tmp.Select(a => new { a.Make, a.Model, a.Year }); cars = cars.Distinct() .OrderBy(a =>...
Jon Skeet
people
quotationmark

Once you've grouped the cars by make and model, each element of the sequence is a group. You can get the key for the group with the Key property, so you can find the group's Make and Model, but Year makes no sense... there will be multiple... more 3/27/2014 5:49:14 PM

people

Joda Time DateTime How to set fraction of a second to value bigger than 999?

Is there any possibility to properly set the fraction of a second, not milliseconds. I tried to parse the date 2013.06.08 12:46:44.41234 using the pattern yyyy.MM.dd...
Jon Skeet
people
quotationmark

Joda-Time only stores date/time values down to the millisecond - just like java.util.Date and java.util.Calendar. So no, there's no way you can precisely represent 412340 microseconds within the second (which is what your text... more 3/27/2014 2:03:09 PM

people

When calling multiple join conditions getting Error

I am trying to join for multiple tables with multiple conditions but for 1 of the joins I am getting ERROR The type of one of the expressions in the join clause is incorrect....
Jon Skeet
people
quotationmark

The problem is that you're joining over two anonymous types, but those types aren't compatible - the property names are different. You've got to have a single key type, so both sides of the equals must be of the same type,... more 3/27/2014 1:32:41 PM

people

Class.forName(“com.mysql.jdbc.Driver”) does not work on Raspberry Pi

this code: Class.forName("com.mysql.jdbc.Driver"); leads to an ClassNotFoundException on raspberry Pi. although my Classpath is correct pi@raspberrypi ~ $ echo...
Jon Skeet
people
quotationmark

You're using -jar, which makes the -cp part irrelevant. From the documentation: When you use the -jar option, the specified JAR file is the source of all user classes, and other class path settings are ignored. Either add ClassPath... more 3/27/2014 1:25:46 PM

people

Exception Unparseable date

SimpleDateFormat readDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); String dtc = "2014-03-27T11:31:42.798Z"; Date date = null; try { ...
Jon Skeet
people
quotationmark

The Z in your format pattern is the problem. That represents an RFC 822 time zone, which can't just be Z. If your input will always be in UTC, you can use: // The Z is now quoted as a literal. SimpleDateFormat readDate = new... more 3/27/2014 1:02:34 PM

people

java constructor handling lack of arguments

i have this code here for a person details and the person should be intialized always whatever the number of possible arguments given ,like for example only height and age or...
Jon Skeet
people
quotationmark

I would suggest using the Builder pattern: public final class Person { private final int salary; private final int age; private final double height; private final String name; public Person(int salary, int age, double... more 3/27/2014 12:07:43 PM

people