ULOG: Java Programming Basics 8 - Reference Data Types Solution

in #ulog6 years ago (edited)

Lecture 8: Reference Data Types Solution


Reference types coding exercise
Implement a ‘String’ data type, ‘someText’, initialized as ‘I am a student’

Reference types exercise solution
String someText = “I am a student”;

Reference types solution output
I am a student

L08.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’.

The solution code is:

String someText = "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 must be a capital letter.

Starting code

public class Lecture8 {
    public static void main(String[] args) {
        // TODO: Implement a ‘String’ data type, ‘someText’, initialized as ‘I am a student’
        System.out.println(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.

Complete solution

public class Lecture8 {
    public static void main(String[] args) {
        String someText = "I am a student";
        System.out.println(someText);
    }
}

With the TODO comment replaced by the solution code, String someText = "I am a student"; I can run my program. The output will be the text, I am a student. (See below)

L08_3 cropped.png

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 want to earn tokens on EVERY post you create use the referral URL below:

http://trybe.one/ref/2859/


This post was made from https://ulogs.org

Sort:  

This user is on the @buildawhale blacklist for one or more of the following reasons:

  • Spam
  • Plagiarism
  • Scam or Fraud

Congratulations @mariusclaassen! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:
SteemitBoard and the Veterans on Steemit - The First Community Badge.

You can upvote this notification to help all Steemit users. Learn why here!

Coin Marketplace

STEEM 0.18
TRX 0.15
JST 0.029
BTC 63607.88
ETH 2506.13
USDT 1.00
SBD 2.59