<< Chapter < Page Chapter >> Page >
These learning object concern methods in Java. A method enables a sequence of statements to be collected together and then invoked by using the method's name.

Learning objects for methods

Concept Methods are the simplest construct for abstraction in Java. A method starts with a declaration that defines its signature : the name of the method, the number and types of the formal parameters and the return type . The body of the method consists of local variable declarations and of statements.A method is called or invoked by writing the name of the method followed by a list of values, called actual parameters , one for each formal parameter. A method can return a value or it can be declaredas void if no value is returned.

These source code of these learning objects can be found in method.zip .

LO Topic Java Files (.java) Prerequisites
"A void method" A void method Method01
"A method returning a value" A method returning a value Method02
"Calling one method from another" Calling one method from another Method03 1, 2
"Recursion" Recursion Method04 2
"Calling methods on an object" Calling methods on an object Method05 2, *
"Calling a method on the same object" Calling a method on the same object Method06 5, *
"Objects as parameters" Objects as parameters Method07 5, *
"Returning objects" Returning objects Method08 7, *
"Returning locally instantiated objects" Returning locally instantiated objects Method09 8, *

* This LO assumes knowledge of the declaration of classes and the instantiation of objects.

A void method

Concept When a method that is declared void is called, it allocates memory for its parameters and local variables, executesits statements and then returns. The call is a statement constructed from the name of the method followed by a list of actual parameters.

Program: Method01.java

// Learning Object Method01 //    void methodspublic class Method01 {     static void printMax(int a, int b) {        int max;         if (a > b)             max = a;        else             max = b;        System.out.println(max);     }      public static void main(/*String[] args*/) {         int x = 10, y = 20;        printMax(x, y);         Method01.printMax(10, y);    } }

The program computes the maximum of two integer values.

  • The variables x and y are allocated and initialized.
  • The method is called with the values of the actual parameters x and y .
  • Memory is allocated for the formal parameters of the method and the local variables. This is called an activation record and is displayed by Jeliot in the upper left hand part of the screen labeled Method Area . The new activation record hides the previous ones which are no longer accessible.
  • The actual parameters are used to initialize the formal parameters in the activation record.
  • The local variable max is allocated within the activation record.
  • The statements of the method are executed.
  • After the last statement has been executed, the method returns and the activation record is deallocated.
  • Execution continues with the statement after the method call. Here, the method is called again, this time with an integer literalas an actual parameter instead of a variable.

Questions & Answers

what is a good calculator for all algebra; would a Casio fx 260 work with all algebra equations? please name the cheapest, thanks.
Kevin Reply
a perfect square v²+2v+_
Dearan Reply
kkk nice
Abdirahman Reply
algebra 2 Inequalities:If equation 2 = 0 it is an open set?
Kim Reply
or infinite solutions?
Embra Reply
if |A| not equal to 0 and order of A is n prove that adj (adj A = |A|
Nancy Reply
rolling four fair dice and getting an even number an all four dice
ramon Reply
Kristine 2*2*2=8
Bridget Reply
Differences Between Laspeyres and Paasche Indices
Emedobi Reply
No. 7x -4y is simplified from 4x + (3y + 3x) -7y
Mary Reply
is it 3×y ?
Joan Reply
J, combine like terms 7x-4y
Bridget Reply
im not good at math so would this help me
Rachael Reply
how did I we'll learn this
Noor Reply
f(x)= 2|x+5| find f(-6)
Prince Reply
Need to simplify the expresin. 3/7 (x+y)-1/7 (x-1)=
Crystal Reply
. After 3 months on a diet, Lisa had lost 12% of her original weight. She lost 21 pounds. What was Lisa's original weight?
Chris Reply
what is nanomaterials​ and their applications of sensors.
Ramkumar Reply
what is nano technology
Sravani Reply
what is system testing?
preparation of nanomaterial
Victor Reply
Yes, Nanotechnology has a very fast field of applications and their is always something new to do with it...
Himanshu Reply
good afternoon madam
what is system testing
what is the application of nanotechnology?
In this morden time nanotechnology used in many field . 1-Electronics-manufacturad IC ,RAM,MRAM,solar panel etc 2-Helth and Medical-Nanomedicine,Drug Dilivery for cancer treatment etc 3- Atomobile -MEMS, Coating on car etc. and may other field for details you can check at Google
anybody can imagine what will be happen after 100 years from now in nano tech world
after 100 year this will be not nanotechnology maybe this technology name will be change . maybe aftet 100 year . we work on electron lable practically about its properties and behaviour by the different instruments
name doesn't matter , whatever it will be change... I'm taking about effect on circumstances of the microscopic world
how hard could it be to apply nanotechnology against viral infections such HIV or Ebola?
silver nanoparticles could handle the job?
not now but maybe in future only AgNP maybe any other nanomaterials
can nanotechnology change the direction of the face of the world
Prasenjit Reply
At high concentrations (>0.01 M), the relation between absorptivity coefficient and absorbance is no longer linear. This is due to the electrostatic interactions between the quantum dots in close proximity. If the concentration of the solution is high, another effect that is seen is the scattering of light from the large number of quantum dots. This assumption only works at low concentrations of the analyte. Presence of stray light.
Ali Reply
the Beer law works very well for dilute solutions but fails for very high concentrations. why?
bamidele Reply
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Got questions? Join the online conversation and get instant answers!
QuizOver.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, Learning objects for java (with jeliot). OpenStax CNX. Dec 28, 2009 Download for free at http://cnx.org/content/col10915/1.2
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Learning objects for java (with jeliot)' conversation and receive update notifications?