Wednesday, 5 September 2012

Methods of Java :D

Add caption

A Java method is a collection of statements that are grouped together to perform an operation. When you call the System.out.println method, for example, the system actually executes several statements in order to display a message on the console.
Now you will learn how to create your own methods with or without return values, invoke a method with or without parameters, overload methods using the same names, and apply method abstraction in the program design.

39 comments:

  1. Java methods are helpful for more flexible codes.

    ReplyDelete
  2. A Java method is a collection of statements that are grouped together to perform an operation. When you call the System.out.println method, for example, the system actually executes several statements in order to display a message on the console.

    Now you will learn how to create your own methods with or without return values, invoke a method with or without parameters, overload methods using the same names, and apply method abstraction in the program design.

    ReplyDelete
    Replies
    1. ryt princess, but is there any further more explanations?

      Delete
  3. Java Methods are very great and exciting to write. Through methods, we are able to discern the most significant concept of OOP which is code reuse. Haha.

    ReplyDelete
  4. now i know how to create methods..........<3

    ReplyDelete
  5. this is so useful...good job!

    ReplyDelete
  6. i understand it. nice.
    just click this link to know more . :)

    http://www.tutorialspoint.com/java/java_methods.htm

    ReplyDelete
  7. The method declaration is the first line, or header, of a method. It contains the
    following:
    » Optional access modifiers
    » The return type for the method
    » The method name
    » An opening parenthesis
    » An optional list of method parameters (you separate multiple parameters
    with commas)
    » A closing parenthesis

    ReplyDelete
  8. Method in Java is a little bit complex.

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. java method is very helpful especially in complicated codes.. you can reuse this method.

    ReplyDelete
  11. Example for java method:

    Here is the source code of the above defined method called max(). This method takes two parameters num1 and num2 and returns the maximum between the two:

    /** Return the max between two numbers */
    public static int max(int num1, int num2) {
    int result;
    if (num1 > num2)
    result = num1;
    else
    result = num2;

    return result;
    }

    ReplyDelete
  12. in naming a method , a method can be any legal identifier, code conventions restrict method names.

    ReplyDelete
    Replies
    1. ah... + AND IN CONVENTION, METHOD names should be a verb in lower case or a multi-word name that begins with a verb in lower case, followed by adjectives,nouns,etc.

      Delete
  13. This comment has been removed by the author.

    ReplyDelete
  14. cool.....guys..to know more about java methods, you can check out this link....

    http://www.tutorialspoint.com/java/java_methods.htm


    hope it's helpful..

    ReplyDelete
  15. Here is the source code of the above defined method called max(). This method takes two parameters num1 and num2 and returns the maximum between the two:

    /** Return the max between two numbers */
    public static int max(int num1, int num2) {
    int result;
    if (num1 > num2)
    result = num1;
    else
    result = num2;

    return result;
    }

    ReplyDelete
  16. In creating a method, you give a definition of what the method is to do. To use a method, you have to call or invoke it. There are two ways to call a method; the choice is based on whether the method returns a value or not.

    ReplyDelete
  17. creating a method
    calling a method ..
    fr more info , visit this link, . java tutorial is also available :) keep smiling

    http://www.tutorialspoint.com/java/java_methods.htm

    ReplyDelete
  18. hey guys.. check this for the tutorial in methods..

    http://docs.oracle.com/javase/tutorial/java/javaOO/methods.html

    http://www.homeandlearn.co.uk/java/java_method_calling.html

    *hope it can help. :))

    ReplyDelete
  19. a method must include the ff:
    - a declaration
    - an opening curly braces
    - body
    - closing curly braces

    ReplyDelete
  20. A java method is a series of statements that perform some repeated task. Instead of writing 10 lines of code we can put those ten lines in a method and just call it in one line. It is like a shortcut.

    ReplyDelete
  21. Two types of Methods are static and instance.
    In static you can code it inside the class file and can be use by just calling the method. The instance is in another class file that when called it is put into an object that will be use to when calling the method. :)

    ReplyDelete
  22. methods are very useful and easy to understand.

    ReplyDelete
    Replies
    1. this link might help us in understandinf methods..

      http://www.tutorialspoint.com/java/java_methods.htm

      Delete
  23. The access modifier for Java method can be any of the following modifiers:
    Public, private, protected or if left unspecified, package.

    ReplyDelete
  24. Java methods is AMAZING.. It is very helpful in creating codes...

    ReplyDelete
  25. Without a method you cannot perform an operation.

    ReplyDelete
  26. Java Method
    A method is a set of code which is referred to by name and can be called (invoked) at any point in a program simply by utilizing the method's name. Think of a method as a subprogram that acts on data and often returns a value.

    :)

    ReplyDelete
    Replies
    1. method in java have six components...it helps a lot

      Delete
  27. nice that there are methods to follow but still we need more time to master those methods

    ReplyDelete
  28. Java Method
    A method is an operation on a particular object. An object is an instance of a class. When we define a class we define its member variables and its methods. For each method we need to give a name, we need to define its input parameters and we need to define its return type.

    clone() is a method in the Java programming language for object duplication. In Java, objects are manipulated through reference variables, and there is no operator for copying an object—the assignment operator duplicates the reference, not the object. The clone() method provides this missing functionality.

    ReplyDelete
  29. this link will lead you into an example on how to call JAVA methods

    http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/method.html

    ReplyDelete
  30. Java method is a collection of statements that are grouped together to perform an operation. When you call the System.out.println method, for example, the system actually executes several statements in order to display a message on the console.

    ReplyDelete
  31. http://www.tutorialspoint.com/java/java_methods.htm

    just check this site guys..it is very help of full..:)

    ReplyDelete
  32. A method definition consists of a method header and a method body. Here are all the parts of a method:

    Modifiers: The modifier, which is optional, tells the compiler how to call the method. This defines the access type of the method.

    Return Type: A method may return a value. The returnValueType is the data type of the value the method returns. Some methods perform the desired operations without returning a value. In this case, the returnValueType is the keyword void.

    Method Name: This is the actual name of the method. The method name and the parameter list together constitute the method signature.

    Parameters: A parameter is like a placeholder. When a method is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of a method. Parameters are optional; that is, a method may contain no parameters.

    Method Body: The method body contains a collection of statements that define what the method does.

    ReplyDelete