You Gin

Ranch Hand
+ Follow
since Jul 23, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by You Gin

Hi guys, can somebody tell me why this happens, please read below.
I have my own class Data which extends Button. In my Activity's class I have a List<Data> which is appending with new Data object on each button click. I want to keep created objects of class Data on the screen after configuration changes, namely orientation change. So I've overrided onSaveInstanceState() and using it to restore my data in onCreate() method. In mentioned method I'm saving every Data object from the list of objects. In onCreate() method I'm trying to restore my data like this, the problem happens on line 18.



So in first case I'm getting IllegalStateException but it is working great for the second one. I don't understand the difference.

Just in case, here is my onSaveInstanceState() method:



And my Data class, but nothing special:

14 years ago
I got an advice recently to use:

instead of

in order to hide implementation details. I don't understand why is it so cool to hide something, why is it required?
14 years ago
Hi guys,

I'm about to finish with Head First Java book. I was advice to use it on this forum and that's why I want to ask you about next advice what book to be learned next from your standpoint.
Thank you very much.
14 years ago
Guys, what do you think, is it more perspective to learn Servlets and JSP rather than Android? I heard that servlets and JSP are losing their popularity for backend development and people more using .NET for websites and developing for Android is more in demand these days.
14 years ago
Thanks guys, that was useful - I read something I didn't know about.
14 years ago
Hi guys. I'm in doubts is it a good practice to set private methods in Constructor or not. Could you please have a look on my Class on the matter?

Thanks!

14 years ago
Ok, ok... please prove my guess. I have a feeling that on new object of String type is instantiated and because the "" is already on a string pool those two are actually the same object and thus is true? Because if I would use:


I'll get "Not Equal"
14 years ago
Thanks you for your explanation Ernest, but the question remains open. Why can' I use


if it works just fine?
14 years ago
Hello Jeanne,

Can you tell me more about Strings comparing please?

I just can't get a difference here. Why should I use equal if == works perfectly fine?


Output:
Not Equal
Not Equal
Not Equal
14 years ago
Hello Jeanne,

Thank you very much for your useful comments, taking them all into account.

Regarding exception for incorrect data in a setter, yeah, I thought about it also and added exception throwing over there, thanks a lot!
14 years ago
Hi guys.

As it was highly recommended in one of the books I'm reading I've started to write tests for each of the class I'm creating. I'm not really sure what is a good practice to cover setters and getters or not. If yes I'm not sure how because to verify the setter method you need to call the getter for this variable and vice versa. So you will never know where the actual problem is.
Where I went is just similar tests for setters and getters. I don't really like it. Could you guys refer me to a right direction?
Thank you very much!

Here is my class and a corresponding test class.


Test:


14 years ago
Thanks guys, now I understand this choice where to initialize your variables depends on you and current needs, but both cases are correct.
14 years ago
Hi guys,

I've got an impression that it is a good practice to make your instance variables initialization within class's constructor


At the same time in most examples I see instance variables are initialized like:


So, as far as I understand, by the time new is returning a reference to a newly created object the instance variable are initialized for both these cases.
Put it in a few words, am I right that there is no need to make initialization in Constructor for cases when I'm not defining initial value(s) for instance variable(s)?

Thank you very much.
14 years ago
Hi guys,

What I've noticed is that rt.jar is located in both JDK and JRE:
"c:\Program Files\Java\jdk1.6.0_21\jre\lib\rt.jar"
"c:\Program Files\Java\jre6\lib\rt.jar"

Several questions arise at the same time. Do you mind I'll list them all?

Here are they:

1. Which of them is using when I do import something in my code?
2. Why the size of these two is different?
3. Does it mean I can simply remove the jre6 folder and still be able to run java applications (as long as JRE is included in JDK)?

14 years ago