Browsing 7239 questions and answers with Jon Skeet

Java constructor with and without "this" before attributes

Maybe this question was asked here before, but I couldn't find it here. It is basic question for Java developers, but here it goes: lets say I have class A with attribute a. What...
Jon Skeet
people
quotationmark

In the case you've given, there's no difference. Typically this is used to disambiguate between instance variables and local variables or parameters. For example: public A(String a) { this.a = a; // Assign value from parameter to... more 1/25/2014 10:44:17 AM

people

why use a dll instead of a class

i joined a new project where they use c#. I noticed that several dll's were being add in the references From my knowledge and the e-learning that i have done, after building a...
Jon Skeet
people
quotationmark

Separating your code into different projects (each of which will create a separate assembly) has various benefits: It makes the structure of your code clear. For example, it can separate your storage layer from your business logic, and... more 1/25/2014 10:09:28 AM

people

convert string to time using culture info and store in SQL

Hai friend i need to convert a string to time format using this code becauseit only support for cloud DB but its not working please dome one help me my duration value is 13:22:00...
Jon Skeet
people
quotationmark

New answer just using TimeSpan The problem is that : isn't recognized within the custom TimeSpan format specifier. You need to escape it. At that point, the culture really isn't relevant at all, so I'd specify the invariant culture,... more 1/25/2014 8:19:35 AM

people

Print Joda Time Interval

Does anybody know how to print a readable Joda-Time Interval? I tried to search for it but all I find is how to print periods. But I really need Interval. I construct it...
Jon Skeet
people
quotationmark

Just call toString() - Interval (or rather AbstractInterval) overrides toString with a readable format. For example: Instant start = new Instant(0L); Instant end = new Instant(1390596587000L); Interval interval = new Interval(start,... more 1/24/2014 8:50:10 PM

people

Predicament with arrays and expansion

So I know that the java convention is to use ArrayList< when it comes to expansions and many other applications. The typical array cannot expand. My java course is elementary...
Jon Skeet
people
quotationmark

Just count how many elements match your filter first, then create the array, then populate it. It means you'll need to go through the array twice, but there are no really nice alternatives unless you want to end up creating multiple... more 1/24/2014 8:04:37 PM

people

Unreachable return statement still throws error

I have this very simple code snippet: static String getInput() throws IOException{ if(in.ready()){ return in.readLine().trim(); } System.err.println("Please provide...
Jon Skeet
people
quotationmark

Why doesn't the JVM recognize that a System.exit(0) will not allow any other code to execute, but complains about unreachable statements if a return will not allow code to be executed? It's not the JVM - it's the compiler. And the... more 1/24/2014 3:26:35 PM

people

string.length not working properly in java

Hi I have a code that checks if a string is palindrome or not.the code is like this: package ProjeTarahi; import java.util.*; import java.io.File; ...
Jon Skeet
people
quotationmark

This is a difference between String.Substring(int) in .NET, and String.substring(int, int) in Java. In .NET, the second parameter is the length of the substring you're trying to take. In Java, the second parameter is the exclusive end... more 1/24/2014 11:08:23 AM

people

arraylist modify at specific index

I have two ArrayLists. As below example shows. ArrayList<String> listVarName = new ArrayList<String>(); ArrayList<String> listVarValue = new...
Jon Skeet
people
quotationmark

Assuming you're concerned about the list modification rather than general structure, yes - there's a better way. Rather than using remove then add, use List.set(index, element): String oldVal =... more 1/24/2014 10:40:10 AM

people

Java overloading a method with two parameters

This problem is about overloading methods and I think I understand the basic idea but I get some weird error "Overloading.java:14". Like my problem is that I don't know how to...
Jon Skeet
people
quotationmark

It's not really clear what you're trying to do, but you don't return parameters, and I don't think overloading is really the problem here. To take overloading out of the situation, you can always change the methods to have different names... more 1/24/2014 9:44:16 AM

people

Getting an specific argument from an list object in Java

Don't know if I formulated the question the right way, but here goes... I need to print the usernames of the objects from the list users. Here is the User class: public class...
Jon Skeet
people
quotationmark

I suspect you want something like: for (int i = 0; i < users.size(); i++) { // Access the user by position in the list User user = users.get(i); // Now print the username for that specific user ... more 1/24/2014 8:42:39 AM

people