Browsing 7239 questions and answers with Jon Skeet

Convert time based on timezone using java.time

How to change the time based on timezone in LocalDateTime, here i have built a date with Time zone as EST, now i need to find the UTC of the corresponding time. please help me how...
Jon Skeet
people
quotationmark

You shouldn't think about "changing the time zone" of a LocalDateTime - a LocalDateTime doesn't have a time zone. Instead, you should build a ZonedDateTime from a LocalDateTime and a time zone (ZoneId). First remove the formatter.withZone... more 6/16/2015 3:58:21 PM

people

Why ConcurrentModificationException occurred only at iterate loop

I wrote two example code as following: private static class Person { String name; public Person(String name) { this.name = name; } } public static void...
Jon Skeet
people
quotationmark

Yes, in your original for loop you're accessing the value by index - although you should note that you're skipping the check for element c (because by then the value that was at index 2 is now at index 1). There's no way this would create... more 6/16/2015 2:10:25 PM

people

Java: BufferedReader Keeps Writing Values 128 159 as 63 When Converting to Char

I am trying to write a hex editor. I'm trying to store values by writing a char to a text file. For some reason every decimal number 128-159 is being written or read (not sure...
Jon Skeet
people
quotationmark

When you use FileReader and FileWriter, they will use the default encoding for your platform. That's almost always a bad idea. In your case, it seems that that encoding doesn't support U+0092, which is fairly reasonable given that it's a... more 6/16/2015 6:13:43 AM

people

Handle StringIndexOutOfBoundsException for string

try { string = scan.nextLine().charAt(0); } catch(StringIndexOutOfBoundsException siobe){ System.out.println("invalid input"); } I am trying to use this code for...
Jon Skeet
people
quotationmark

Your compilation error is because String.charAt() returns a char, not a String. They're different types - and you need to be very clear about the difference between them. You could just change the variable to a char variable, renaming it... more 6/16/2015 5:59:45 AM

people

Giving preference to one jar over another

I have to refer generic JSONObject. import statement: import org.json.JSONObject; is in my project. But it is loading org.json.JSONObject from cdh hive jar instead our...
Jon Skeet
people
quotationmark

You just need to put the jar file you want earlier in the build path in Eclipse, or earlier in the classpath in general. You might want to have a look for a version of CDH / Hive (I haven't used them) which doesn't come bundled with a copy... more 6/16/2015 5:53:06 AM

people

Low number of requests/second on process that writes files on disk

I have a process that receives a lot of requests and i'm running some load tests using Apache Bench to find out why it's so slow (240 requests/second). I've isolated all points...
Jon Skeet
people
quotationmark

It's not clear to me what mailMessage.writeTo(baos, Array[String]("X-Sender")) actually does, but it feels like your initial code is being very wasteful in converting everything to a string and back, and even your second code is doing a... more 6/15/2015 9:11:33 PM

people

Why does Java prefer to call double constructor?

public class test { test(double[] a) { System.out.println("in double"); } test(Object a) { System.out.println("in object"); } public...
Jon Skeet
people
quotationmark

Both constructors are applicable, because null is convertible to both Object and double[] - so the compiler needs to use overload resolution to determine which constructor to call. JLS 15.9.3 uses JLS 15.12.2 to determine the "most... more 6/15/2015 4:54:28 PM

people

.NET use IIF to assign value to different variables

Could I (and if so how) do the following in .NET language (more specifically VB.NET): Dim a,b as Integer if(somecondition=1,a,b) = 12345 Or any variant with IIF would be fine...
Jon Skeet
people
quotationmark

No, I don't believe there's any way of doing that in VB. Conditional operators (such as If(x, y, z)) are designed to evaluate one expression or the other based on a condition. In other words, it's the result that's conditional, not the use... more 6/15/2015 4:43:19 PM

people

No value given for one or more required parameters. in asp.NET

am trying to get the column values from a grid view when a row is checked and insert those values into some other table , here is my c # code when a check box in grid...
Jon Skeet
people
quotationmark

You should be specifying parameters for your values: commd.CommandText = "insert into funds_hidden values(?, ?)"; commd.Parameters.Add("code", OleDbType.VarChar).Value = fund_code; commd.Parameters.Add("name", OleDbType.VarChar).Value =... more 6/15/2015 4:09:54 PM

people

linq to XML: unique attribute value count per group

I have got XML nodes as below. ... <ParentNode> <Node id="2343" name="some name" mode="Some Mode"> //Some child nodes here </Node> <Node...
Jon Skeet
people
quotationmark

Assuming you want the count of the distinct "mode" attribute values within the nodes with the same ID/name, you just need to project from each element in the group to the mode, then take the distinct sequence of those modes, then count... more 6/15/2015 9:39:06 AM

people