Browsing 7239 questions and answers with Jon Skeet

Inconsistent string length definition between Java String.substring() and Oracle 11g column VARCHAR2 size

I set up my database with a table like this: CREATE TABLE t_audit_log ( description VARCHAR2 (2500) ); In the Java app which uses it, I employ Hibernate to map a data class...
Jon Skeet
people
quotationmark

I suspect your database settings are set to use "byte semantics" for the length operations (which is the default for NLS_LENGTH_SEMANTICS), in which case you're saying you want the field to be up to 2500 bytes in length when encoded, not... more 11/9/2015 4:19:27 PM

people

c# DataTable.cselect(string regExpression) strange exception throwing

I am developing a c# database program but now I have trouble using the DataTable's Select(string regExpression) method. I am calling the method like that: DataRow[] tmpDr =...
Jon Skeet
people
quotationmark

You should read the DataTable.Expression documentation. In particular: User-defined values may be used within expressions to be compared with column values. String values should be enclosed within single quotation marks (and each... more 11/9/2015 3:46:50 PM

people

Java: try catch error, must be caught to be thrown

I have tried to create a method to load files but it is not working the way it should. Why do I get this error? Is there a problem with my try-catch block? NamnMetod.java:157:...
Jon Skeet
people
quotationmark

It's got nothing to do with the try/catch block in the run() method. The problem is with the method that calls invokeAndWait... EventQueue.invokeAndWait() is declared to throw InterruptedException, which is a checked exception... so either... more 11/9/2015 10:05:34 AM

people

Java8 LocalDateTime parsing error

I am trying to parse the following timestamp string 03-feb-2014 13:16:31 using java.time but it is throwing an error. Here is my code. String timestamp = "03-feb-2014...
Jon Skeet
people
quotationmark

If you use yyyy instead of YYYY in your pattern, the code you've given works. YYYY is "week-based year" which would normally only be used if you're also specifying week number and day-of-week (e.g. a pattern of YYYY-ww-EEE). This is pretty... more 11/9/2015 7:15:36 AM

people

Will instances inside an instance get null'ed when the main instance is null'ed

Let's say we have this code: public class c1 { c2 secondclass = new c2(); } public class c2 { public c2() { System.out.println("c2 instance created"); ...
Jon Skeet
people
quotationmark

No, it won't. It's important to understand that you never set an instance to null - you just set the value of a variable to null. There can be multiple variables with references to the same instance. It's hard to comment on your exact... more 11/8/2015 5:14:26 PM

people

C# Linq: Return a multidimensional array from a list of Object

Say you have a list of Object person: private List<Person> lstPersons = new List<Person>(); In which person is defined as: public class Person { public...
Jon Skeet
people
quotationmark

Well you can create an object[][], yes: object[][] array = people.Select((p, index) => new object[] { index, p.Name, p.Mail }) .ToArray(); If you wanted an object[,], that's not doable with regular LINQ as... more 11/7/2015 9:38:20 PM

people

Instance method Synchronization in JAVA

Suppose there are TWO Threads A and B . There is one object which has 2 synchronized methods dothisOne and dothisTwo which should get executed in the order (dothisOne---dothisTwo)...
Jon Skeet
people
quotationmark

Are there chances of ThreadB starting dothisOne (or) is it 100% guarenteed that thread A will go for dothisTwo ? No guarantees at all. I suspect it's more likely that thread A will get to go into doThisTwo instead, because basically... more 11/7/2015 9:22:16 PM

people

Why do I need to cast a dynamic object when calling IEnumerable.Contains()?

I am trying to call IEnumerable.Contains() with a dynamic argument, but I am getting the error 'IEnumerable' does not contain a definition for 'Contains' and the best...
Jon Skeet
people
quotationmark

Enumerable.Contains is an extension method - and extension methods aren't resolved by the mini-compiler which is used at execution time. (Execution methods depend on using directives, which aren't preserved. They could be, but I guess that... more 11/6/2015 5:43:21 PM

people

Static variables in java

I have scenario like this public class Test{ static int a; int b; public static void main(String[] args){ Test t1 = new Test(); Test t2 = new Test(); ...
Jon Skeet
people
quotationmark

As per my understanding since variable a is static variable it will be both in object 1 and object 2. No. It's not in either object. It exists without reference to any particular instance at all. Although Java allows you to refer to... more 11/6/2015 2:02:16 PM

people

Assert.assertEquals on two lists

I have a class MySchool: public class MySchool{ private long timestamp; private SchoolEvent event; private Object value; //getter & setters ... ...
Jon Skeet
people
quotationmark

I don't understand why the error doesn't sound like an error, I mean just check the error message, every field of every element object in two lists are euqal. Yes, but that doesn't mean that the objects are considered to be... more 11/6/2015 9:49:05 AM

people