Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 136,338 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,807 people online right now. Registration is fast and FREE... Join Now!




Master Method

 
Reply to this topicStart new topic

Master Method

marcel.brown
25 Aug, 2008 - 06:02 PM
Post #1

New D.I.C Head
*

Joined: 25 Aug, 2008
Posts: 4

I am just trying to master methods. I don't want the methods with the object. I want it break down how methods work with void methods and return value method. Can you give me a good example and explain whats happening? thanks in advance


This post has been edited by pbl: 25 Aug, 2008 - 06:18 PM
User is offlineProfile CardPM
+Quote Post

pbl
RE: Master Method
25 Aug, 2008 - 06:25 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,110



Thanked: 202 times
Dream Kudos: 75
My Contributions
QUOTE(marcel.brown @ 25 Aug, 2008 - 07:02 PM) *

I am just trying to master methods. I don't want the methods with the object. I want it break down how methods work with void methods and return value method. Can you give me a good example and explain whats happening? thanks in advance

Usually methods go with objects... static methods are the exception

CODE

class Person {
     String name;
     int age;

    // method get age
   int getAge() {
      return age;
   }
   // method get name
   String getName() {
      return name;
   }
}

The 2 previous methods are used to retreive age and name from a Person object

Now a static method can be used to return "static" elements common to all Persons

CODE

class Person {
    static String[] fields = {"Name", "age"};

    static String[] getPersonFields() {
       return fields;
    }


User is offlineProfile CardPM
+Quote Post

marcel.brown
RE: Master Method
25 Aug, 2008 - 06:29 PM
Post #3

New D.I.C Head
*

Joined: 25 Aug, 2008
Posts: 4

QUOTE(pbl @ 25 Aug, 2008 - 07:25 PM) *

QUOTE(marcel.brown @ 25 Aug, 2008 - 07:02 PM) *

I am just trying to master methods. I don't want the methods with the object. I want it break down how methods work with void methods and return value method. Can you give me a good example and explain whats happening? thanks in advance

Usually methods go with objects... static methods are the exception

CODE

class Person {
     String name;
     int age;

    // method get age
   int getAge() {
      return age;
   }
   // method get name
   String getName() {
      return name;
   }
}

The 2 previous methods are used to retreive age and name from a Person object

Now a static method can be used to return "static" elements common to all Persons

CODE

class Person {
    static String[] fields = {"Name", "age"};

    static String[] getPersonFields() {
       return fields;
    }




I am talking about like write a program the regular way and write and then write it in a method and break it down. Explain whats happening in the program...

QUOTE(pbl @ 25 Aug, 2008 - 07:25 PM) *

QUOTE(marcel.brown @ 25 Aug, 2008 - 07:02 PM) *

I am just trying to master methods. I don't want the methods with the object. I want it break down how methods work with void methods and return value method. Can you give me a good example and explain whats happening? thanks in advance

Usually methods go with objects... static methods are the exception

CODE

class Person {
     String name;
     int age;

    // method get age
   int getAge() {
      return age;
   }
   // method get name
   String getName() {
      return name;
   }
}

The 2 previous methods are used to retreive age and name from a Person object

Now a static method can be used to return "static" elements common to all Persons

CODE

class Person {
    static String[] fields = {"Name", "age"};

    static String[] getPersonFields() {
       return fields;
    }




I am talking about like write a program the regular way and write and then write it in a method and break it down. Explain whats happening in the program...
User is offlineProfile CardPM
+Quote Post

pbl
RE: Master Method
25 Aug, 2008 - 07:06 PM
Post #4

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,110



Thanked: 202 times
Dream Kudos: 75
My Contributions
QUOTE(marcel.brown @ 25 Aug, 2008 - 07:29 PM) *

[I am talking about like write a program the regular way and write and then write it in a method and break it down. Explain whats happening in the program...

I don't know what you mean by "the regular way".... if you mean regular C/Pascal/Fortran/Cobol way you are far from OO and Java.

If you plan to write Java "that regular way" forget about Java and stay away from it, you will only produce shitty code

User is offlineProfile CardPM
+Quote Post

marcel.brown
RE: Master Method
25 Aug, 2008 - 08:00 PM
Post #5

New D.I.C Head
*

Joined: 25 Aug, 2008
Posts: 4

QUOTE(pbl @ 25 Aug, 2008 - 08:06 PM) *

QUOTE(marcel.brown @ 25 Aug, 2008 - 07:29 PM) *

[I am talking about like write a program the regular way and write and then write it in a method and break it down. Explain whats happening in the program...

I don't know what you mean by "the regular way".... if you mean regular C/Pascal/Fortran/Cobol way you are far from OO and Java.

If you plan to write Java "that regular way" forget about Java and stay away from it, you will only produce shitty code


Yeah I understand now what you wrote. I know but see methods are different in some java books. Some explain methods alone and others explain it with classes and object and constructors. Thats what mixing me up. No I want Java. I was basically asking like that program you wrote write it without calling a method so I can see how it work that where and the where you wrote it up there.
User is offlineProfile CardPM
+Quote Post

pbl
RE: Master Method
26 Aug, 2008 - 03:03 PM
Post #6

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,110



Thanked: 202 times
Dream Kudos: 75
My Contributions
QUOTE(marcel.brown @ 25 Aug, 2008 - 09:00 PM) *

Yeah I understand now what you wrote. I know but see methods are different in some java books. Some explain methods alone and others explain it with classes and object and constructors. Thats what mixing me up. No I want Java. I was basically asking like that program you wrote write it without calling a method so I can see how it work that where and the where you wrote it up there.


OK so here a static "regular" method that returns the age of 2 persons

CODE

static int cumulAge(Person one, Person two) {
    return one.getAge() + two.getAge();
}


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 08:07AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month