Browsing 7239 questions and answers with Jon Skeet

Declaring variables before call to super() but super must be the first statement

I have a constructor in an abstract class that takes many parameters in it's constructor I am trying to extend this class and I want to set some default values in the call to...
Jon Skeet
people
quotationmark

No, you can't do that - but if the important part is to give the arguments meaningful names, you could consider something like: class Foo extends Bar { private static final int DEFAULT_WIDTH = 10; private static final int... more 2/3/2015 1:24:26 PM

people

C# StreamReader.ReadToEnd() is extremely slow

I'm making a Web Crawler and I just found out that one of my methods, GetHTML, is very slow because it uses a StreamReader to get a string of the HTML out of the HttpWebResponse...
Jon Skeet
people
quotationmark

When I call this method but return String.Empty instead of the ReadToEnd, the method takes about 500 MS. All that says is that starting to get the response takes 500ms. Calling GetResponseStream doesn't consume all the... more 2/3/2015 10:18:15 AM

people

Difference between .NETs using Statement and Javas try with ressources

I learned C# in school and now I started to learn Java. In Java there is "try with ressources" which will close/dispose stuff (like a Scanner) when it's not used anymore. The...
Jon Skeet
people
quotationmark

No, they're not exactly the same. try-with-resources statements can declare multiple variables of different types; using statements can declare multiple variables, but they all have to be of the same type A using statement doesn't have... more 2/3/2015 8:11:09 AM

people

how do I use C# to dump a web page's HTML to a text file?

I am working on a project where I need to be able to take a website url www.google.com for example and get the html for it in a text file to be parsed separately, but I don't know...
Jon Skeet
people
quotationmark

Downloading just a single URL to a file is dead easy using WebClient: using (var client = new WebClient()) { client.DownloadFile(url, filename); } The trickier bit is that very few web pages really consist of a single piece of HTML... more 2/3/2015 7:22:13 AM

people

using TreeSet to sort without providing a Comparator to it

I know that TreeSet in java automatically sort its elements in ascending order an it guarantees the order. for example, If i have an array of Date object in random and I copy it...
Jon Skeet
people
quotationmark

What is the point of using TreeSet in this situation for sorting data if i am also providing a custom Comparator to it ? Because it's the TreeSet code that keeps it sorted. You haven't had to provide any of the code for that - all... more 2/2/2015 7:16:15 PM

people

Java 8 Streams: IntStream to String

In Java 8 streams API, calling chars() on any String object returns an IntStream object containing all the characters. What would be the correct way to convert the returned...
Jon Skeet
people
quotationmark

You can use toArray(), then the String(int[], int, int) constructor. This isn't entirely satisfactory as chars() is specified to return UTF-16 code units, basically: Returns a stream of int zero-extending the char values from this... more 2/2/2015 3:16:11 PM

people

What is the neatest way to find the last possible instant of a LocalDate, in a particular time zone?

Apologies if this seems a simple question, but I mostly just want to check that the solution I have is the most sensible/holds for all cases. The pre-existing SQL Server database...
Jon Skeet
people
quotationmark

Firstly, as noted in comments, any time you can work with an exclusive upper bound, that would be a good idea :) Your AtEndOfDay method looks reasonable to me, except that I'd use Duration.Epsilon instead of Duration.FromTicks. In... more 2/2/2015 11:36:07 AM

people

Check if a string contains only date

I have a string which can contain a date(yyyy-MM-dd) or date and time (yyyy-MM-dd HH:mm:ss) in respective formats. I want to know which strings contains only date. DateFormat...
Jon Skeet
people
quotationmark

I would use the overload of parse which takes a ParsePosition - you can then check the position afterwards: import java.util.*; import java.text.*; public class Test { public static void main(String[] args) throws Exception { ... more 2/2/2015 8:49:33 AM

people

How to make a maxium number of the position of the decimal point, in java

For example: int getMax(int a) { return max; } a : 1 -- max : 9, a : 2 -- max : 99, a : 3 -- max : 999 and so on. Thanks.
Jon Skeet
people
quotationmark

There are various options for this. Given that your method can only return int, there aren't very many options available, so you could just write: private static final int[] results = { 9, 99, 999, 9999, ... }; public static int... more 2/2/2015 7:19:19 AM

people

The type or namespace name 'DataSetExtensions' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)

I know this is a common error but I have the correct reference to the System.Data.DataSetExtensions.dll added to the project and my project is a SQL CLR project built for .net 4.5...
Jon Skeet
people
quotationmark

System.Data.DataSetExtensions is an assembly, not a namespace. You just need to add a reference to System.Data.DataSetExtensions.dll (as you say you already have) and then a using directive for the System.Data namespace: using... more 2/1/2015 9:02:58 PM

people