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 5 of 5

Thread: Method declaration in Java

  1. #1
    Junior Member
    Join Date
    Jun 2009
    Posts
    15
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Method declaration in Java

    Hi;
    How can me declare a Method in Java?

    Thanks,mohsen


  2. #2
    Member Truffy's Avatar
    Join Date
    May 2009
    Location
    Philippines
    Posts
    93
    Thanks
    2
    Thanked 9 Times in 7 Posts

    Default Re: Declare a method

    Hi Mohsen,

    Welcome to java prog forums.

    Heres a sample site for you:

    Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)


    Cheers,
    Truffy.

  3. #3
    Member Truffy's Avatar
    Join Date
    May 2009
    Location
    Philippines
    Posts
    93
    Thanks
    2
    Thanked 9 Times in 7 Posts

    Default Re: Declare a method

    Hi,

    you can use this as reference:

    http://www.javaprogrammingforums.com...e-program.html

  4. The Following User Says Thank You to Truffy For This Useful Post:

    mohsendeveloper (June 11th, 2009)

  5. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Declare a method

    Hello mohsendeveloper, welcome to the Java Programming Forums.

    Do you know about the main method? Declaring another method is basically the same. Here is an example for you.

    public class Mohsendeveloper {
     
        /**
         * JavaProgrammingForums.com
         */
     
        public static void anotherMethod(){
            // Here is another method we have declared
            // called anotherMethod.
     
            // This is printed when the method is called
            System.out.println("Thats how you declare a method");
     
        }
     
     
        public static void main(String[] args) {
     
            // This is the main method and is the
            // starting point of an application.
     
            // You can call the anotherMethod method
            // like this:
            Mohsendeveloper m = new Mohsendeveloper();
            m.anotherMethod();
     
        }
     
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  6. #5
    Member Truffy's Avatar
    Join Date
    May 2009
    Location
    Philippines
    Posts
    93
    Thanks
    2
    Thanked 9 Times in 7 Posts

    Thumbs up Re: Declare a method

    Quote Originally Posted by JavaPF View Post
    Hello mohsendeveloper, welcome to the Java Programming Forums.

    Do you know about the main method? Declaring another method is basically the same. Here is an example for you.

    public class Mohsendeveloper {
     
        /**
         * JavaProgrammingForums.com
         */
     
        public static void anotherMethod(){
            // Here is another method we have declared
            // called anotherMethod.
     
            // This is printed when the method is called
            System.out.println("Thats how you declare a method");
     
        }
     
     
        public static void main(String[] args) {
     
            // This is the main method and is the
            // starting point of an application.
     
            // You can call the anotherMethod method
            // like this:
            Mohsendeveloper m = new Mohsendeveloper();
            m.anotherMethod();
     
        }
     
    }

    Great example. I got lazy typing one. LOL.


    Cheers,
    Truffy

Similar Threads

  1. [SOLVED] Java exception "result already defined"
    By rptech in forum Object Oriented Programming
    Replies: 3
    Last Post: May 20th, 2009, 06:48 AM
  2. How to display the contents of my queue?
    By rocafella5007 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 30th, 2009, 12:46 PM
  3. problem with Scanner nextLine() method
    By mia_tech in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: March 10th, 2009, 05:14 AM
  4. Replies: 2
    Last Post: March 4th, 2009, 06:32 AM
  5. Replies: 1
    Last Post: December 30th, 2008, 07:30 AM