Book Image

Hands-On Automation Testing with Java for Beginners

Book Image

Hands-On Automation Testing with Java for Beginners

Overview of this book

Java is one of the most commonly-used software languages by programmers and developers. Are you from a non-technical background and looking to master Java for your automation needs? Then Hands-On Automation Testing with Java for Beginners is for you. This book provides you with efficient techniques to effectively handle Java-related automation projects. You will learn how to handle strings and their functions in Java. As you make your way through the book, you will get to grips with classes and objects, along with their uses. In the concluding chapters, you will learn about the importance of inheritance and exceptions with practical examples. By the end of this book, you will have gained comprehensive knowledge of Java.
Table of Contents (17 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Introducing strings


A string is one of the most important concepts in Java programming. String is one of the prebuilt classes in Java. So if you want to manipulate strings, then you could simply create an object of this String class, and using that object, you can manipulate the string however you want. You can then break the string into two parts, based on the substring concept. We can also concatenate two strings. All of this can be done with the help of this String class.

Let's try manipulating a string ourselves. Create a new Java class and name it stringclassdemo.

One of the most common questions asked in almost all Java related interviews is how a programmer can define strings. The answer is that you can use either of the two following ways:

  • By defining the String literal
  • By creating an object of String

Now let's look at each method, one by one, in order to understand the different ways of declaring a string.

Defining the String literal

Defining the String literal can be done simply,as follows...