Browsing 7239 questions and answers with Jon Skeet

MD5 hash in android or java

I required to convert string in MD5 hash. I am using MessageDigest md = MessageDigest.getInstance("MD5"); byte[] thedigest = md.digest(bytesOfMessage); final protected static...
Jon Skeet
people
quotationmark

The second web site is simply using base64 instead of hex to represent the binary data as text. So you can get rid of your bytesToHex method entirely, and just use Base64: String base64Digest = Base64.encodeToString(thedigest,... more 7/24/2014 9:19:08 AM

people

Java: How does the Array provide instant lookup

More specifically, how does the Array object in Java allow users to access each bucket in constant time? I understand that Java allocates memory equivalent to the specified size...
Jon Skeet
people
quotationmark

An array is just stored as a big contiguous block of memory. Accessing an element is a matter of: Finding where the data starts Validating the index Multipying the index by the element size, and adding the result to the start... more 7/24/2014 9:07:23 AM

people

how to create\start a thread with parameters

How do I use ThreadStart to create\start a thread with method parameters. private void GenerateData(Type Method){ ThreadStart tStart = null; tStart = new...
Jon Skeet
people
quotationmark

It sounds like you might just want: private void GenerateData(ThreadStart method) { Thread thread = new ThreadStart(method); thread.Start(); } You could then certainly have: private void DoWork() { ... } private void... more 7/24/2014 8:37:07 AM

people

NodaTime get Country Time based on CountryCode

I've a requirement where Admin will select some countries List and Time for Alert for users for that Countries List. Lets Say the Admin selects 24/07/2014 09:00 AM in the...
Jon Skeet
people
quotationmark

Your code is nearly correct - although it can be simplified somewhat, and made more testable, and it should handle the case where there's no such zone... // You should use dependency injection really - that makes the code much more //... more 7/23/2014 6:57:32 PM

people

How to update NodaTime.xml for NodaTime .NET?

I am new to NodaTime and doing samples with it. NodaTime is great and while reading the documentation for NodaTime implementation, I noticed that there was a file(contains...
Jon Skeet
people
quotationmark

You're getting confused between XML documentation files and the time zone (nzd) files. You don't need to update XML files at all. To get the most recent version of the TZDB data, you should: Fetch (and store) the contents of... more 7/23/2014 6:52:51 PM

people

A recursive must resolve to type but I don't know how to structure it?

public static Directory makePath(Directory parent, String[] path) { // While path has more than one item in it, recurse if (path.length > 1) { ...
Jon Skeet
people
quotationmark

I suspect you just want to return the results of the recursive calls. So turn these calls: FileSystem.makePath(newParent, newPath); into return FileSystem.makePath(newParent, newPath); Although I think it's worth noting that you have... more 7/23/2014 6:17:30 PM

people

Getting error: A field initializer cannot reference the non static field, method, or property

The error message was: Error 1 A field initializer cannot reference the non-static field, method, or property 'AmazingPaintball.Form1.thePoint' This is the...
Jon Skeet
people
quotationmark

You haven't shown enough context, but I suspect you've got something like: class Game { Point thePoint = new Point(50, 50); Paintball gun = new Paintball(thePoint); } As the compiler says, a field initializer can't refer to... more 7/23/2014 4:03:15 PM

people

c# How to iterate through a dictionary and compare values?

I'm teaching myself c# and working on my own mini project. The program populates an array with random numbers, the program returns the number (0-15) and the number of occurrences...
Jon Skeet
people
quotationmark

I wouldn't use the current approach at all, to be honest - you're doing much more work than you need to. LINQ gives you much better tools than this. You can use GroupBy to make it all cleaner: var pairs = array.GroupBy(x => x) ... more 7/23/2014 3:22:22 PM

people

Groovy catch statement weird behavior

I have the following 2 groovy snippets that should do the same but they don't. try { throw new RuntimeException() } catch (IllegalStateException) { println("hello!") } The...
Jon Skeet
people
quotationmark

In the first case, you're introducing a variable called IllegalStateException. It's equivalent to: try { throw new RuntimeException() } catch (Exception IllegalStateException) { println("hello!") } In the second case, you're only... more 7/23/2014 3:01:14 PM

people

Linq Group By multiple value on custom dynamic object

I made a simple dynamic object: class Row { Dictionary<string, object> properties = new Dictionary<string, object>(); private int rIndex; public Row(int...
Jon Skeet
people
quotationmark

Okay, I think it probably makes sense to have something like a RowView class, which contains a reference to a Row, and the properties you're interested in (a subset of the row's properties). You can then make it implement... more 7/23/2014 2:53:56 PM

people