JAVA_6 - memory and how a method knows where to return...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
memory and how a method knows where to return after it completes execution . We will take a brief diversion into simulation techniques with random- number generation and develop a version of the casino dice game called craps that will use most of the programming techniques you have used to this point in the book. In addition, you will learn two techniques for declaring values that cannot change (i.e., constants) in your programs . Many of the classes you will use or create while developing applications will have more than one method of the same name. This technique, called overloading, is used by programmers to implement methods that perform similar tasks for arguments of different types or possibly for different numbers of arguments . 6.2 . Program Modules in Java OBJECTIVES In this chapter you will learn : How static methods and fields are associated with an entire class rather than specific instances of the class . To use common Math methods available in the Java API .
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
To understand the mechanisms for passing information between methods . How the method call/return mechanism is supported by the method call stack and activation records . How packages group related classes . How to use random-number generation to implement game-playing applications . To understand how the visibility of declarations is limited to specific regions of programs . What method overloading is and how to create overloaded methods 6.1 . Introduction Most computer programs that solve real-world problems are much larger than the programs presented in the first few chapters of this book. Experience has shown that the best way to develop and maintain a large program is to construct it from small, simple pieces, or modules . This technique is called divide and conquer . We introduced methods in Chapter 3 . In Chapter 6 , we study methods in more depth. We emphasize how to declare and use methods to facilitate the design, implementation, operation and maintenance of large programs . You will see that it is possible for certain methods, called static methods, to be called without the need for an object of the class to exist. You will learn how to declare a method with more than one parameter. You will also learn how Java is able to keep track of which method is currently executing, how local variables of methods are maintained in Figure 6.2. Math class methods . Method Description Example abs( x ( absolute value of x abs( 23.7 ) is 23.7 abs( 0.0 ) is 0.0 abs( -23.7 ) is 23.7 ceil( x ( rounds x to the smallest integer not less than x ceil( 9.2 ) is 10.0 ceil( -9.8 ) is -9.0
Background image of page 2
cos( x ( trigonometric cosine of x (x in radians ( cos( 0.0 ) is 1.0 exp( x ( exponential method e x exp( 1.0 ) is 2.71828 exp( 2.0 ) is 7.38906 floor( x ( rounds x to the largest integer not greater than x floor( 9.2 ) is 9.0 floor( -9.8 ) is -10.0 log( x ( natural logarithm of x (base e ( log( Math.E ) is 1.0 log( Math.E * Math.E ) is 2.0 max( x , y ( larger value of x and y max(
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/14/2011 for the course MATH 401 taught by Professor H.ayad during the Spring '11 term at Cairo University.

Page1 / 29

JAVA_6 - memory and how a method knows where to return...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online