Danjel Nyberg

Greenhorn
+ Follow
since Sep 12, 2012
Danjel likes ...
Eclipse IDE Java MS IE
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Danjel Nyberg

How to add your name to the wall of fame?

/Danjel
Hi

I passed the OCAJP7 1Z0-803 exam today with 90%
I have used the enthuware mock exams to study.

Thank you all for support and sharing of knowledge

Kind Regards
/Danjel
5 years ago
I would say that this line of code would not compile



however if you put it like this, then it would work



Regards
/Danjel
I was just tweaking a bit and stumbled across something strange, which i can't explain

given this simple class:


this gives different output every time i run it...

expected output is:

0
1
2
3
4
Exception in thread "main" java.lang.Exception
at SCJP.Test18.main(Test18.java:9)

but if I run it several times it could give me this output:

0
1Exception in thread "main" java.lang.Exception
at SCJP.Test18.main(Test18.java:9)

2
3
4

My only explenation to this is that the update of output to the Eclipse console is not keeping up.

Any ideas or input?


/Danjel
Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.) This method acts as bridge between array-based and collection-based APIs, in combination with Collection.toArray(). The returned list is serializable and implements RandomAccess.

/Danjel
Sorry for this, was just spinning off of the recent chars not compiling threads, plus i though i'd give you some fun for the weekend. perhaps the wrong forum.

Kind Regards
/Danjel
What is the output of this?



Have a nice weekend everyone!
/Danjel

[John] Split long lines in post
One point... The default constructor of a singleton instance should be private. You can also use Enums for singleton




/Danjel

Same goes for strings...

String a = "Test";
String b = "Test";
System.out.println(a==b); //prints true
String c = new String("Test");
System.out.println(a==c); //prints false

In this case since a and b are created via string litherals they point to the same object, but since c is created with new keyword this will be another object and therefore a is not the same as c

This is wierd in so many ways. In all normal cases you allways compare objects with equals method only...

/Danjel
Of course... absolutely correct, and so are protected (in the same package)

/Danjel
Hi

Not quite sure how that differs from what i stated above. A Default accessed attribute in a superclasss is accessible in a subclass of superclass as long as they are in the same package.

In difference here from protected:

The above method would work if i change: Account acc = new Account(); to GoldAccount acc = new GoldAccount();
as they are in different packages, but if accountNo would have been declared with default access, this should not work. (if they are in different packages)

/Danjel
Realized that only minutes after posting.. sometimes it is good to just write it down... got it now.

Thanks
/Danjel
I state the following...

public - everyone can access methods and attributes of the class
protected - class, and every subclass of class no matter of the package can access
private - only class can access
default - class, and every subclass can access if they are in the same package

accesscontrol

Question im having trouble with:


another package... another class...
[Added code tags - see UseCodeTags]

This gives a compilation error, any suggestions as to what mistake i might have made?

/Danjel
Hi

You can also convert decimals to binary with:
Integer.toBinaryString(a);

Where a is of type int

and convert binary string to decimals with:
int a = Integer.parseInt(s1, 2);
where s1 is of type string

also adding and removing specific bits from a binary is possible with follwing code:



Kind Regards
/Danjel
Can not find this book, can anyone point out a store who sells this book?

Right now im training with the EPractize labs. Is this a good way to train for the OCA 7?

/Danjel