Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Possible Duplicate:
Best Java book you have read so far

I have learned to program some in Ruby, but I'm having trouble grasping OO concepts. I've been told that there are a lot of guides/books that teach object oriented programming that use Java. I've heard that Java is a good language for learning OO for a number of reasons... haha, reasons that I don't know.

Anyway, I tried to use an IDE (Eclipse) and I don't care much for it. Are there any good guides/books/videos that focus on teaching OO concepts using Java that don't use an IDE such as Eclipse to teach it?

share|improve this question
1  
If you can, check the reading list for the first year comp sci course at your nearest university, they may have something if the community here can't think of one. –  Kevin D May 3 '11 at 8:08
1  
Eclipse does seem complex but it has way too many benefits to ignore .It would be worth your while to take time in learning the actual IDE. –  Aditya P May 3 '11 at 9:57
1  
It's just I feel like I don't have enough control when using an IDE and also a lot of the "helpful" features are a crutch that may prevent a person from learning why different pieces of code go where. Yes, I suppose it's helpful in that it helps prevent bugs and whatnot, but it just I feel that when I'm forced to figure out the next thing to write out that I know my code better than when I've used some sort of autocomplete-type feature. –  Melanie May 3 '11 at 11:35
    
Maybe if you're having trouble learning OO, you should come over to the functional programming side ;) –  WuHoUnited May 3 '11 at 12:10
    
@Melanie: I have a question: What did you learn to progam Ruby in? –  FrustratedWithFormsDesigner May 3 '11 at 13:16
show 3 more comments

marked as duplicate by Mark Trapp Dec 11 '11 at 18:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

10 Answers

up vote 7 down vote accepted

Head First Java, Second Edition.
Can't recommend it enough.

share|improve this answer
1  
What do you like most about it? –  Anna Lear May 3 '11 at 13:09
1  
Because it is a great introduction to Java programming language. Easy and fun to follow and it fits the original poster's criteria. –  Chiron May 3 '11 at 15:33
1  
+1 i agree with @4bu3li this is a good insight into the finer details of OOPS basics. –  Dredd May 3 '11 at 15:39
    
Head First books are very good, but sometimes I think they're not suited for people who already know how to program. –  Mahmoud Hossam May 4 '11 at 12:36
add comment

http://www.bluej.org/ is a Java IDE designed specifically for teaching the language. It is often used at High schools and universities. I'd recommend taking it for a spin.

Alternatively if you're just out to learn OO, then you can also look at a language such as Smalltalk. Java is an OO language, but some purists argue that it's not as purely OO as it could/should be.

share|improve this answer
1  
+1 - I'm using it for my java class now. On top of that, I would recommend the book Big Java. I'm also using it for my class. –  Jetti May 3 '11 at 14:54
add comment

You don't need to use an IDE to follow a basic tutorial, specially if you're learning OOP

You can just follow any tutorial using a text editor and the JDK, as long as you know how to compile and run Java programs.

I recommend the official Java Tutorial to get started with Java, googling the term "Java OOP tutorial" might also be useful.

share|improve this answer
add comment

Well if your keen with Java how about having a peep at this book Head First Design Patterns, since you are learning Java I think you will enjoy reading this and grasp some design principles and OO concepts. However keep practicing what you read and this will help you to understand concepts more and try your own style of thinking :)

There are plenty of resources in the internet where you can easily read up, just found a few see below,

http://download.oracle.com/javase/tutorial/java/concepts/

http://java.sun.com/developer/onlineTraining/Programming/BasicJava2/oo.html

http://www.codeproject.com/KB/architecture/OOP_Concepts_and_manymore.aspx

http://blogs.sitepoint.com/oriented-concepts-java-1/

share|improve this answer
add comment

Here are some Cliffs Notes on OOP to help you get going while perusing the suggested litterature:

Some OO Basics

Encapsulation, the main point of OO, means that you put logic and data inside a logical entity known as object. They can be anything you'd like.

Relationships between objects can be achieved through composition (aka. association) or inheritance.

In Java, all objects are instantiated from a class type. Think of class as a cookie cutter and the objects as the cookie that has been cut out. Like so:

// Declaration of class
public class MyAwesomeClass {
    // Quite empty
}

// Instantiation of object from a class with "new"
MyAwesomeClass awesome = new MyAwesomeClass();
    // The object now resides as a reference in the "awesome" variable.

In contrast: some other OO-languages, such as JavaScript, does this differently with a prototype since it is prototype based instead of class based.

A class contains fields (aka. members, properties, class variables) and methods (aka. class functions). Objects will have these fields and methods for themselves. It is good practice that the fields are accessed through methods called getters (aka. accessors) or setters (aka. mutators).

public class MyAwesomeClass {
    private int myInteger; 
        // "information hiding" members related 
        // to the object are usually set to private

    // the getter
    public int getMyInteger() {
        return this.myInteger;
    }

    // the setter
    public void setMyInteger(int theInteger) {
        // theInteger is a *parameter* for the setter
        this.myInteger = theInteger;
    }
}

// Usage:
awesome.setMyInteger(4);
System.out.print(awesome.getMyInteger); // should output 4

Constructors are called when you create an instance of a method. Like so:

public class MyAwesomeClass {
    private int myInteger; 

    // The constructor has no return type, and the name is same as class
    public MyAwesomeClass(int theInteger) {
        this.myInteger = theInteger;
    }

    // getter and setter from before are here...
}

// Usage:
MyAwesomeClass awesome = new MyAwesomeClass(8);
System.out.print(awesome.getMyInteger); // should output 8   

Overloading is a cool and sometimes useful concept:

class MyAwesomeClass {

    private int myInteger; 

    // Overloading constructor example

    public MyAwesomeClass() {
        this(12); // will call the overloaded constructor with 12
    }

    // Overloads MyAwesomeClass() with another parameter
    public MyAwesomeClass(int theInteger) {
        this.myInteger = theInteger;
    }

    // Method overload example

    public addInteger() {
        this.addInteger(1); // calls the overloaded method with 1
    }

    public addInteger(int theInteger) {
        this.myInteger += theInteger;
    }

}

Composition

You can compose many objects together using references to other class types. In this case we have an MyAwesomeStrategy inside MyAwesomeClass.

In UML it is drawn like this:

+----------------+ 1   1 +-------------------+
| MyAwesomeClass |-------| MyAwesomeStrategy |
+----------------+       +-------------------+

In code it looks like this:

class MyAwesomeStrategy {
    public void doIt() {
        System.out.print("Trolololol");
    }
}

class MyAwesomeClass {

    private MyAwesomeStrategy strategy;

    public MyAwesomeClass(MyAwesomeStrategy strategy) {
        this.strategy = strategy;
    }

    public void doStrategy() {
        this.strategy.doIt();
    }
}

// in your main method:
MyAwesomeClass awesome = new MyAwesomeClass(new MyAwesomeStragety());
awesome.doStrategy(); // prints out Trolololol

Tip: Got a big class? Split it up to many using composition!

Inheritance

One object can inherit the properties and methods of another object. It can look like this in UML:

+-----------------+            +-------------------+
| MyOtherStrategy |----------|>| MyAwesomeStrategy |
+-----------------+            +-------------------+

And in code it looks like this:

class MyOtherStrategy extends MyAwesomeStrategy {
    public void doIt() {
        System.out.print("Stackoverflow Rules!");
    }
}

// in your main method:
MyAwesomeClass awesome = new MyAwesomeClass(new MyOtherStragety());
    // This works because the MyOtherStrategy object 
    // extends MyAwesomeStrategy
awesome.doStrategy(); // prints out Stackoverflow Rules!

// That's some cool POLYMORPHISM going on there!

Congrats! Now you've also learned the strategy pattern (sort of).

While inheritance is useful, it also breaks encapsulation. It does however have really good uses as long as you don't have to worry implementation about the classes. Remember the important OO mantra:

"Prefer composition over inheritance." - GOF

Phew! And that's just the start!

share|improve this answer
    
+1 for the hard work –  Ritwik G May 4 '11 at 11:04
add comment

Java Notes and it's sister Java Basics might be what you're looking for.

share|improve this answer
add comment

DrJava is a great lightweight/learning editor that gives you some of the organizational advantages of an IDE over a plain-vanilla text editor (ie, shows you your classes etc) without doing a lot of the hiding the under-the-hood stuff that a bigger IDE will. I like BlueJ, (mentioned earlier) too, but I feel like DrJava gets less in the way of the code you write.

In any case, I use Eclipse now, but I'm definitely glad I learned it separately after I had the fundamentals of OOP/Java down - and conversely, I am glad I used a simple Java-specific editor when I was learning. There's a fine line between autocorrect tools getting in the way of you figuring out what's wrong with your code yourself, and getting so frustrated figuring out simple but stubborn syntax errors that you want to give up. I find that it's often ultimately helpful to have something that points out an error, without telling you what it is.

share|improve this answer
add comment

Not directly an answer but more of a corollary on the other answers...

IDEs do have some advantages where they take away some of the drudgery handling dependencies and other peripheral tasks such as build, testing deployment etc thus allowing you to focus more on code itself. That said they are just equally a distracting source of frustration when you try to do something in appearance trivial but have not yet discovered the "natural" path through the IDE to get the job done.

So if you feel the urge of writing a whole bunch of shell scripts to automate the more boring aspects of your learnings have a look at these... they will help ... promised !!

There are other similar tools so treat this more as a starting point but they will go a long way in helping you staying productive without the use of an IDE.

share|improve this answer
add comment

I would recomend the Oracle Java Tutorial. They teach all the stuff without assuming more than you have an editor and javac.

share|improve this answer
add comment

If you want to understand the OO paradigm, maybe you should try Squeak SmallTalk.

There are excellent free resources about OO in Smalltalk, and because Smalltalk actually introduced much of the OO paradigm, the stuff is actually more geared to teaching people the OO principles.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.