Browsing 7239 questions and answers with Jon Skeet

How to break a line?

I have this line : cmd.CommandText = "SELECT registeruser_id,registeruser_username, registeruser_email,registeruser_password FROM TestDB_RegisterUser where registeruser_email='"...
Jon Skeet
people
quotationmark

Yes, because a regular string literal can't include a line break in the source code. You can include one in a verbatim string literal however: string sql = @"SELECT FOO FROM BAR WHERE X=Y"; Or break it with... more 5/17/2014 8:00:58 AM

people

Method signature in function overriding with final qualifier in parameter

class T {} interface Interface{ void method(final T t); } class FirstClass implements Interface{ public void method(T t){ //valid } public void...
Jon Skeet
people
quotationmark

In the above code, why it is not considering the final qualifier while overriding a method? Because it's an implementation detail. It's completely irrelevant to callers. All it means is that within the method, the code can't assign a... more 5/17/2014 7:41:14 AM

people

Constant arrays in Java

I have a Move class, which is immutable (basically it's just two ints). The I have class Moves with constants: public class Moves { public static final Move NW =...
Jon Skeet
people
quotationmark

No, just avoid using arrays. Arrays are always mutable, and even if you create a new array each time, that means your callers will have to perform defensive copies if they pass the sets around. Firstly, I'd change your Move class to an... more 5/16/2014 6:17:42 PM

people

Incorrect *.bat execution from Java

I have .bat file with following content for example: mkdir testDir Now I put it to folder C:\temp Then I want to run it using java so I do...
Jon Skeet
people
quotationmark

You need to specify the working directory when you run cmd. There are overloads of Runtime.exec() which allow you to specify a working directory. For example: Runtime.getRuntime().exec("cmd /c start C:\\temp\\test.bat", null, ... more 5/16/2014 2:25:50 PM

people

serialVersionUID Exception

I'm currently writing a project where I have a serializable class ClientRepository. The class don't specifies any serialVersionUID. When I try to run my program, I got following...
Jon Skeet
people
quotationmark

Don't try to change the data - instead, if you're certain that your class is still compatible with the old version (and if only one version has data out in the wild), change your declared serialVersionUID to -477189107700903771L to match... more 5/16/2014 12:40:12 PM

people

How to nicely call property with side effects?

This is purely a language matter, because I know, that this may (and possibly even should) be solved in a different way. We have a property Prop, which in its getter has some...
Jon Skeet
people
quotationmark

If you create a variable, you'll then get code complaining that it's unused, which can be annoying. For benchmarking cases, I've sometimes added a generic Consume() extension method, which just does nothing: public static void... more 5/16/2014 12:34:44 PM

people

Send Byte array then String then Byte over socket Java

I need to send a text message to server over Java socket and then to send a byte array and then a string etc... What I've developed until now is working but the client manages to...
Jon Skeet
people
quotationmark

Something that could be useful is that i know exactly the size of each string to be read and each byte array to be read. Exactly. That's very common. Basically you length-prefix each message - and you might want to provide more header... more 5/15/2014 6:48:30 PM

people

DateFormat.parse problems

I'm trying to convert a String to Date. When I run my software I get this mistake, which is obvious I'm parsing it badly: The mistake is this: java.text.ParseException:...
Jon Skeet
people
quotationmark

This is your value: 2014-02-07 00:00:00 This is your format: yyyy-MM-dd'T'HH:mm:ss They don't match. Your format has a T in the middle - your value doesn't. If all your values have a space instead of a T, just use: yyyy-MM-dd... more 5/15/2014 2:06:30 PM

people

FileSystemEventHandler method as parameter

I have the following method that sets up a FileSystemEventHandler to monitor for changes to a config.xml file. public void WatchConfigFile(???) { this.watcher = new...
Jon Skeet
people
quotationmark

Well it sounds like you just want the handler itself as the parameter: public void WatchConfigFile(FileSystemEventHandler handler) { ... this.watcher.Changed += handler; ... } That should be fine. There'll be a method group... more 5/15/2014 1:57:16 PM

people

argument type lambda expression is not assignable to parameter type int error

I have a Major model like this: public int Id { get; set; } public string MajorName{ get; set; } public string Password { get; set; } public System.DateTime RegisterDate { get;...
Jon Skeet
people
quotationmark

I suspect you've basically got your lambda expression and your method call the wrong way round. You may want: @Html.DisplayFor(modelItem => objmajor.FindMajorById(int.Parse(modelItem.MajorId)).MajorName) In other words, you're... more 5/15/2014 1:18:44 PM

people