Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Java and Algorithmic Thinking for the Complete Beginner

You're reading from  Java and Algorithmic Thinking for the Complete Beginner

Product type Book
Published in Jun 2024
Publisher Packt
ISBN-13 9781836200130
Pages 957 pages
Edition 1st Edition
Languages
Author (1):
Aristides Bouras Aristides Bouras
Profile icon Aristides Bouras
Toc

Table of Contents (11) Chapters close

Preface 1. Part I Introductory Knowledge 2. Part II Getting Started with Java 3. Part III Sequence Control Structures 4. Part IV Decision Control Structures 5. Part V Loop Control Structures 6. Part VI Data Structures in Java 7. Part VII Subprograms 8. Part VIII Object-Oriented Programming 9. Part IX Files 10. Some Final Words from the Author

Chapter 35
Introduction to Subprograms

35.1 What Exactly is a Subprogram?

In computer science, a subprogram is a block of statements packaged as a unit that performs a specific task. A subprogram can be called several times within a program, whenever that specific task needs to be performed.

In Java, a built-in method is an example of such a subprogram. Take the well-known Math.abs() method, for example. It consists of a block of statements packaged as a unit under the name “abs”, and it performs a specific task—it returns the absolute value of a number.

If you are wondering what kind of statements might exist inside the method Math.abs(), here is a possible block of statements.

if (number < 0)
return number * (-1);
else
return number;

Generally speaking, there are two kinds of subprograms: functions and procedures. The difference between a function and a procedure is that a function returns a result, whereas a procedure doesn't. However, in some computer...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime