Browsing 7239 questions and answers with Jon Skeet

How to achieve pass by reference in recursive methods in Java

What are the ways in which we can achieve/mock pass by reference in Java? In order to check whether a linkedlist is a palindrome, i wrote the below code. It works/ But i would...
Jon Skeet
people
quotationmark

You only need the extra class because you've got two pieces of information to maintain - and you've only got two pieces of information to maintain because you're ignoring the return value of the recursive call. I suspect that you could... more 9/29/2014 7:22:31 AM

people

what is the class level synchronization.If the class is locked by one thread at same other thread can access the other method of that class

There is a class EmployeeInfo it has a static synchronized method non static synchronized method public class EmployeeInfo{ public static synchronized void insert(){ ...
Jon Skeet
people
quotationmark

There are two separate locks involved here - one for the instance on which you call update, and one for the class itself. So thread B would be blocked until thread A had completed, but the other two threads would execute without blocking.... more 9/29/2014 5:57:29 AM

people

Constructor of a derived class (Java)

I'm very new in Java, and about to ask a fundamental question. Hope you guys could help me. Supposed I have a base classe Super and a derived class Sub, which inheritances from...
Jon Skeet
people
quotationmark

But why is Super() printed, since Super::Super() hasn't never been called? It has, because your Sub constructor is implicitly calling it. It's as if you'd written: public Sub(int x, int y) { super(); ... more 9/28/2014 5:25:45 PM

people

Java.lang.long cannot be applied to java.lang.string?

I am trying to write a program for converting positive binary inputs into hex. Why am i getting this errors while compiling my binary to hex converter.. BinToHex.java:45:...
Jon Skeet
people
quotationmark

Well yes, look at the signature of Long.toHexString: public static String toHexString(long i) You're trying to pass in a string. Given that it's meant to convert a long into a string, it's not at all clear what you would expect this to... more 9/28/2014 5:14:22 PM

people

Java how to sort object in many ways: Arrays.sort(), Comparable<T>

Let's say that I have an array with objects, where I have some employees (objects). They all have: int age, double salary. I want to sort this array so my class implements...
Jon Skeet
people
quotationmark

To implement multiple ways of sorting a collection of Employee references, you should create separate classes implementing Comparator<Employee>. So you might have: public class EmployeeAgeComparator implements... more 9/28/2014 9:08:55 AM

people

Insert a smalldatetime into SQL Server

I am trying to insert date to a smalldatetime column in SQL Server I try something like this: DateTime transfer_date; transfer_date = DateTime.Now; SQL = "insert into MyTbl...
Jon Skeet
people
quotationmark

You're currently not doing anything with your transfer_date variable at all. Your SQL statement contains the text transfer_date, but it doesn't automatically fetch the value from the database. You want something like: // @transfer_date is... more 9/28/2014 7:59:05 AM

people

Index and length must refer to a location within the string error in substring

I have a string like this: 2899 8761 014 00:00:00 06/03/13 09:35 G918884770707. I have to take the substring G918884770707 from this given string. I know the start of the...
Jon Skeet
people
quotationmark

You've misunderstood the parameters to Substring - they aren't start and end (as they are in Java), they're start and length. So you want: No = line.Substring(Start, End - Start); From the docs: Parameters startIndex Type:... more 9/28/2014 7:52:10 AM

people

How to add more value on java string array?

I have a listview. private String[] listView2 = {"aa","aa","aa"}; int a = 0; Int values will decide to add the number of content So if a==2. listView2 = {"aa","aa"}; if...
Jon Skeet
people
quotationmark

You're clearly familiar with array initializers where you specify the content up-front... but you can also create arrays just by specifying the length, like this: String[] array = new String[length]; This will create an array where... more 9/27/2014 7:21:17 AM

people

Iinherited fields value are not changed

I'm not sure if these question is still appropriate to be asked as there could be an answer already. But i still dont understand the concept of inheritance when it comes to...
Jon Skeet
people
quotationmark

Does this means the class attributes are not polymorphic? No, fields aren't polymorphic. You've actually got two fields in your Elephant class - one declared in Animal and one declared in Elephant, which hides the one in Animal.... more 9/27/2014 7:05:00 AM

people

Method override returns null

I'm newbie in Java. So question might sound simple, but I'm stuck and can not figure out why this code returns null and 0.0 ? file: Transport.java public class Transport { ...
Jon Skeet
people
quotationmark

You've declared separate name and price variables in Car, and never assigned a value to them - they're not the same as the name and price variables declared (and initialized) in Transport. So you're seeing the default values for String... more 9/26/2014 8:32:47 PM

people