Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Hello World!

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hello World!

    call me Rage. trust me im always like this . anyways im here to introduce my self, i am a student somewhere and they teach java there but its too spoonfeeding and the progress is so slow, i can feel it . when i jumped into this forum i just realized java is not that complicated after all. i came from C language too much procedured programming now i want to learn and deeply understand what an object oriented is.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Hello World!

    Welcome Rage. Anger is useful. Better breathing, increased blood flow, higher brain activity. It is what you do with it that counts. muahahahah

    The way I first understood oop was to forget the p. What is object oriented? Take real life examples. I want to build a house.
    What is a house? A building of many rooms?
    What rooms? Different rooms have different purposes.. but are also alike in many ways.

    Now think about what all rooms have in common. A size. A shape. A door(i hope). A window(maybe?)
    Now think about what you can do in all rooms. Open/close doors/windows.
    Things which are common to all rooms would be listed here.

    Now think about things that are specific to each room type:
    Kitchen: Stove, Fridge, Oven, Cabinets. Things to do in a kitchen: Cook, clean, eat, drink

    Bedroom: Bed, Closet. Things to do: Sit, sleep, watch tv, internet activity

    Other rooms: etc.

    Object oriented programming is the idea of organizing your data in a way that makes sense to the real world application. Given any problem to solve, if you relate it to the way people naturally interact with the problem, the hard part is over.

    Back to the P:
    public class Room {//we assume all these rooms will be simple rectangle shapes for now
        private float sizeX;
        private float sizeY;
        private String door;
        //etc
     
        //constructor(s)
        public Room(Door d, int x, int y) { //not very good names
            //set variables
        }
     
        public void openDoor() {
            //open door
        }
        public void closeDoor() {
            //close door
        }
        //other methods
        //getters n setters
    }
    public class Kitchen extends Room {
        private String stove;
        private boolean stoveIsHot;//true if hot
        private String fridge;
        private boolean fridgeIsCold;//true if cold
        private String oven;
        private boolean ovenIsHot;//true if hot
        private ArrayList<Cabinets> cabinets;//where Cabinets is another class in the house building project most likely
        //etc
     
        //constructor(s)
     
        public boolean isStoveHot() {
            return stoveIsHot;
        }
        public void turnStoveOn(int degreesCelsius) {
            //turn stove on to value degreesCelsius
        }
    public class Bedroom extends Room {
        //etc
    }
    Once you have the objects organized, and the methods to act upon those objects, you can now get on to the procedural part.
    public class HouseBuilder {
     
        public static void main(string[] args) {
     
        private Kitchen kitchen;
        private Bedroom masterBedroom;
        private Bathroom masterBathroom;
        private Den den;
     
        //call constructors for each room the house will get
        kitchen = new Kitchen(new Stove, new Fridge, new Oven);
        //organize those objects into a grid the size and shape of the building
        //sell finished house for 100 times what it cost to build it
    }
    The idea is to keep all of your related data together in a place with the methods to act on the data. Have protected(meaning secure, not the keyword protected) access to the data. Hide how you do what you do to the data from the user of the class without making it difficult or confusing to use.
    So if you get your thoughts all out on paper as you organize it, you already have your pesudo-code to work from.
    Hope that helps

Similar Threads

  1. Hello World
    By ashutosh in forum Member Introductions
    Replies: 0
    Last Post: July 6th, 2012, 03:49 AM
  2. Hello World!
    By Dracone Cordis in forum Member Introductions
    Replies: 1
    Last Post: January 7th, 2012, 09:50 PM
  3. World Map
    By LorenzoR in forum AWT / Java Swing
    Replies: 5
    Last Post: December 3rd, 2011, 12:20 AM
  4. Hello World!
    By i_masyhudi in forum Member Introductions
    Replies: 1
    Last Post: July 27th, 2011, 02:50 AM
  5. Hello World
    By av8 in forum Member Introductions
    Replies: 1
    Last Post: June 27th, 2011, 10:05 AM