Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread Display Modes
Old Apr 17, 2012, 09:07 PM   #1
macrumors member
Join Date: Apr 2012
Location: Chicago
(java) Proper way to set up a program with objects

I am wondering what the proper conventions are for setting up a java programming with objects. Keep in mind i learned about objects last lecture and i don't know everything about them yet. I know about mutator methods, accessor methods ,instantiation, and constructor. I guess I'm asking what order from top to bottom they should be in?
bigMAC28 is offline   0 Reply With Quote
Old Apr 17, 2012, 09:40 PM   #2
macrumors 68040
lee1210's Avatar
Join Date: Jan 2005
Location: Dallas, TX
Unfortunately your phrasing doesn't really tell us what you know and what you need to know. Java is object-oriented, period. The entry point to your program is a particular method (static public void main(String [])) on an object. You can try to twist it into an iterative language by never declaring another object, only using static methods, and putting all of your logic into main, etc. But this is going against the grain.

Dependent on the kind of program you're writing main should be a few lines that instantiate an object (using a constructor) and accessing its methods. The real thrust of OOP is encapsulation and reusability. Mutators and accessors break encapsulation a bit, but they are still frequently needed and used. I'm not sure what top to bottom sort of description you're wanting otherwise. Objects are a representation of a set of variables (data) and methods that act on them. There are a lot of additional complexities and abstractions like inheritance (one class inherits data and methods from another class), interfaces (a set of methods a class must adhere to in order to implement the interface), and many others.

Have you programmed in iterative languages before and this is your first OOP experience, or is this your first foray into programming of any variety?

lee1210 is offline   0 Reply With Quote
Old Apr 18, 2012, 02:48 AM   #3
macrumors 65816
macsmurf's Avatar
Join Date: Aug 2007
Not sure if this is what you're asking but this is the general layout of a simple class:

public class FooBar {

    // Fields
    private Object foo;
    private Object bar;

    // Constructors
    public FooBar() {

    public FooBar(Object foo) {
        this.foo = foo;

    // I normally put methods that are not standard getters/setters 
    // here because I think the most important part of the class in
    // terms of functionality should be near the top.
    // That implies putting private methods here as well. 
    // Most people put public methods at the top and private methods
    // at the bottom, though.

    // Standard getters/setters
    public Object getFoo() {
        return foo;

    public void setFoo(Object foo) {
        this.foo = foo;

    public Object getBar() {
        return bar;

    public void setBar(Object bar) {
        this.bar = bar;

Last edited by macsmurf; Apr 18, 2012 at 04:37 AM.
macsmurf is offline   1 Reply With Quote

MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Running a java program on OS X 10.6.8 Stud1ent Mac Programming 2 Nov 10, 2013 08:27 PM
OpenGL ES: Vertex Buffer Objects and Vertex Array Objects Blakeasd iPhone/iPad Programming 2 Jul 12, 2013 11:24 PM
Chrome on OS X -- Java plugin / Java 7 vs Java 6 Issue booyahbooyah Mac Applications and Mac App Store 4 May 31, 2013 09:13 AM
Problem running a program because of Java GrantMeThePower OS X 10.8 Mountain Lion 5 Jan 16, 2013 07:24 PM
how do I set default program for handling photo imports? MyRomeo Mac Basics and Help 0 Jul 9, 2012 06:27 AM

Forum Jump

All times are GMT -5. The time now is 12:46 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2015, MacRumors.com, LLC