<<Previous Post << Complete Tutorial>> Next Post>>
In the previous article, I have explained about boolean data type in Java.
In this article, I am going to explain and practically demonstrate String non-primitive data in Java.
Java for Testers – String non-primitive data type
The sequence of characters can be stored into a variable which is declared as String.
For example:
String e = "This is a sample text";
In the above example, we have declared the variable e with the String data type, and hence we are able to store the string values like “QAFox – Software Testing Tutorials” into the variable.
Follow the below steps for practically implementing String data type in Java:
1) Let’s create a Java program and create a Demo class as shown below:
Note: If you are not aware of creating a Java project and a Class in Java, refer to our previous article – Creating a Java project in Eclipse IDE
2) Inside the main() method, let’s create a variable, declare the variable with String data type and assign the variable with the string value “QAFox – Software Testing Tutorials” as shown below:
Note: The sequence of characters should be enclosed with double quotes to store into the String declared variable as shown below:
3) Now print the value stored in the variable by printing the variable using the print statement as shown below:
4) Save the Project and click on the ‘Run’ button.
Observe that the Program got executed and the String value stored in the variable e got printed as shown below:
Copy the above-explained code from the below section:
public class Demo { public static void main(String[] args) { String e = "QAFox - Software Testing Tutorials"; System.out.println(e); } }
I will explain more about Strings in the upcoming articles.
Here concludes this article.
In the next article, I will explain and demonstrate the byte data type in Java.
Next Steps:
- > To learn more about Java, continue to the next post (Click on Next Post link below)
- > Check complete Java Tutorial Contents here (Click here)
Please leave your questions/comments/feedback below:
Happy Learning ?
Arun Motoori (www.QAFox.com)
On a mission to help the Testing Community in all possible ways.
<<Previous Post << Complete Tutorial>> Next Post>>