why don't you check
www.java.sun.com
check their tutorial; it's very good for beginners
then you can check:
www.javaworld.com, they have a lot of tutorials too; then just write java tutorial in google and you will get thousand of sites:
About interfaces - it's really very easy. It's something very common to bject oriented languages and is oftern called "implementing by contract" (or someting like that).
IN java an interface is just declarations and can only contain public visible declarations. It is what is said: usual example they throw in books is to thing about for example video player: Interface is buttons and controls that you can see. You don't care so much how they are implemented inside the box; but just about what they do (for example volym will play it louder or less loud).
In java interface is much like that. You declare an interface and put some methods in it, and then when you are working with an class that implements that interface you know that this class implements methods in that interface, You don't care in principle how and what other methids are there; only those declared in interface. For example:
interface Player{
public void play();
public void stop();
}
class VideoPlayer implements interface Player{
public void play(){
( do someting here )
}
public void stop() {
(do something ihere )
}
public void anotherMethod()
{
....
}
} // end vidoe player
Now you can declare an instance of video player class. If you declare instance
as reference to your Player interface only methods visible are those declared in interface Player; if you declare an instance of VideoPlayer then you can call even anotherMethod:
class test
{
main() // just to be short ....
{
Player p = new VideoPlayer(); // only avialable methods are play & stop
VideoPlayer p2 = new VideoPlayer() // avialable play, stop & anotherMethod
}
}
There are some technical details to remember about interfaces but they are really not difficult:
First when you use interfaces, if you declare a method in interface you MUST implement that methods (or declare an abstract class). (Remember of interface as contract that obligate you).
Second you can't make an instance of an interface, since an intrface doesn't contain any implementation of methods, only declarations. It's pretty much like abstract methods. For example you can't write:
VideoPlayer p = new Player();
or
Player p = new Player();
But you can declare refernce to an interface or bettter to say reference to an object that implements certain interface; concrete:
Player p = new VideoPlayer();
Here you tell to compiler to make an VideoPlayer object, but that you are interested only in methods that are declared in Player interface.
About multiple inhertiance; such things doesn't exist in java. Some people refer to interfaces as some kind of replacment for it; but it really isn't. Maybe on conceptuall level, but not on practical, since interface can contain only declaratations of methods.
You can also use interface to cheat a bit with constants and global things. Since in java everything is local to some class, there is no global visible things; unless they are static. Putting variables in interfaces and declaring thea as public static is an easy way to get them global visible (if noeeded for some reason).
About thinking in java. I sow that book since 5 years back or something but I never liked it too much; I do like idea of public books, but really referring to all examples as class A, Class B, Class c1 class c2 and such is not really pedagogic. Somewhere classes become too many and you loose track of what was class A what was class B etc. I prefer in teaching examples to see a bit more creativ (and descriptiv) names that are easier to remember.
When I was learning java at university 3 years back, we were usings David J. Barnes: Object-Oriented Programming with Java. I liked book, coz' it really explained well object-oriented conepts, it had a litlle runnable example to every concept it was explaining and is written in nice language. I remember that even sa begginer at that time I relized that it was much better book than thinking in java and worth money.
hope it helps