Java Basics 8 - Reference Data Type Solution

in #java6 years ago (edited)

Lecture 8: Reference Data Types Solution

REFERENCES PROBLEM STATEMENT:
// Implement a ‘String’ data type, ‘someText’, initialized as ‘I am a student’.

REFERENCES SOLUTION:
// String someText = “I am a student”;

I am a student

L08 tmp1.png

Hi there, I am Marius from AlefTav Coding. Today, I will again look at Java's 'reference' data type. The coding exercise homework was to Implement a ‘String’ data type, ‘someText’, initialized as ‘I am a student’.

As always when making a declaration in Java, you start with the data type, which is 'String' in this case. Then, the storage name as 'someText'. This is assigned to the words, 'I am a student', between quotation marks (" ").

'String' is Java's built-in data type for working with text. Also, note that 'String' is a Java 'class', and therefore the first letter, 'S' as a capital letter.

public class Lecture8 {
public static void main(String[] args) {
// TODO: Implement a String data type
System.out.print(someText);
}
}

My class, here, is 'Lecture8' with the method, main(). This is followed by the 'TODO' comment. Then I do a printout of the value that the storage location, 'someText' points to.

Now, I can remove the 'TODO' comment, and type in my solution String someText = "I am a student";.

When the code is all in order, and I run the program, the output will be the text, 'I am a student'.

In this lecture you learnt the solution to the coding exercise, implementing the 'String' reference type in Java. Next time I will show a program where Java asks you a question.

My name is Marius, from AlefTav Coding. Until next time, KEEP CODING.

If you found this post usefull don't be shy to upvote, comment and subscribe


▶️ DTube
▶️ IPFS

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63204.10
ETH 2560.70
USDT 1.00
SBD 2.79