Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Hands-On Automation Testing with Java for Beginners

You're reading from  Hands-On Automation Testing with Java for Beginners

Product type Book
Published in Sep 2018
Publisher Packt
ISBN-13 9781789534603
Pages 156 pages
Edition 1st Edition
Languages

Table of Contents (17) Chapters

Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
1. First Programming Steps in Java 2. Understanding Classes, Objects, and Their Usage in Java 3. Handling Strings and Their Functions in Java 4. Building Blocks for Java Programs – Loops and Conditions 5. Everything You Need to Know About Interfaces and Inheritance 6. Learn Everything about Arrays 7. Understanding Date Class and Constructors in Java 11 8. Importance of the super and this Keywords and Exceptions in Java 9. Understanding the Collections Framework 10. The Importance of the final Keyword, Packages, and Modifiers 1. Other Books You May Enjoy Index

Using methods


Basically, methods are blocks in our Java class. Let's write one block here as an example, and observe where the opened and closed brackets are placed. The following example shows one complete block:

public void getData()
{
    static int a=4;
}

In this code, we have named the block of code getData() and void is the return type for this method.

If we are expecting to return a number from the method, and the number is an integer, then we have to write integer in place of void. The same applies with strings; if we are planning to return a string from the getData() method, then we have to declare it as a string. If we are not returning anything, that is, if we are simply writing a few lines of code, then we leave it as void.

Take a look at the following screenshot:

Return type is given as void for getData()

Here, we are not returning anything, so we keep it as void.

Let's add a return 2; line below System.out.println(" I am in method");. Here, we are returning a number that is an integer...

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}