ULOG: Java Programming Basics 5 - Primitive Data Types

in ulog •  6 years ago  (edited)

Lecture 5 - Primitive Data Type Example


Primitive types problem statement
Implement a ‘double’ data type, ‘doubleNumber’, initialized as 9781.3

Primitive types example solution
double doubleNumber = 9781.3;

Primitive types example output
9781.3

L05_0.png

Problem statement

Hi there, I am Marius from AlefTav Coding. In this lecture I will look at an example of Java's primitive data types. You will learn how to 'Implement a double data type, named, ‘doubleNumber’, initialized as 9781.3'

public class Lecture5 {
    public static void main(String[] args) {
        // TODO: Implement a ‘double’ data type, ‘doubleNumber’, initialized as 9781.3
        System.out.println("doubleNumber");
   }
}

How Java stores information

Inside your computer there are many storage locations where different pieces of data are stored. You as a Java developer must first prepare each one of these storage locations before your Java program can use it. Technically, you must first declare a storage location. This declaration pattern in Java is to identify the type of data that can be stored at a location. Then you give that storage location a name. In this example, the data type is double and the storage name is doubleNumber.

Now, after you have told Java what type of data to store at a location, the next step is to put a value at that location. The equals symbol, (=) means to assign a value. You assign the value 9781.3 to the location named, doubleNumber. The technical term for this step is initialization. I have combined the declaration step and initialization step into one as follows: double doubleNumber = 9781.3;.

The reason I am using the Java data type, double is because here I work with a fractional number, 9781.3. The data type, double is one of Java's primitive data types. Java allocates a set storage size for each of the different primitive data types. Because Java knows the sizes at the time of declaration, it will store primitive types at those locations.

L05_2.png

My class in this lesson is, Lecture5 with the usual main() method. The solution code must be typed in the line with the TODO comment. After that, I do a printout. So, I instruct Java to print the value stored at the location named doubleNumber.

 // TODO: Implement a ‘double’ data type, ‘doubleNumber’, initialized as 9781.3

Next, I remove the TODO comment, and I type in my solution, double doubleNumber = 9781.3;. The complete program is as follows:

public class Lecture5 {
    public static void main(String[] args) {
        double doubleNumber = 9781.3;
        System.out.println("doubleNumber");
   }
 }

When I run this program the value, 9781.3 will be displayed, indicating that my program works correctly.

Coding Exercise

In this lecture you learnt how to implement the primitive data type, double. Below is a coding exercise for you to complete as homework:

public class Lecture6 {
    public static void main(String[] args) {
        // TODO: Implement an ‘int’ data type, intValue, initialized as 4326
        System.out.println(intValue);
    }
}

My name is Marius from AlefTav Coding. Thanks for reading and KEEP on STEAMING.


You can earn extra steem and basic income at the referral URLs below:

https://steemengine.net/join?r=4539
https://old.steemfollower.com/?r=18345
https://minnowsmith.party/
https://www.mannabase.com/?ref=2a6bce2ce9
https://www.swiftdemand.com/?referred_by=mariusclaassen
https://litecoin-faucet.com/page/faucet
http://sociali.io/ref/Fd15253240

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

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

I thank you for your contribution. Here are my thoughts;

  • Contributions on Utopian must be open source and contain correct repository from GitHub. This one does not contain a repository. As there is no official repository for Java, you can include whitelisted unofficial repository for it. You can find whitelisted repositories on the guidelines page.

  • Main purpose of the tutorial is to teach the user something unique, not to show ubiquitous functions and replicate well-documented concepts. What you've shown here can easily be found on the internet, with great quality. So, what I suggest is changing the topic or increasing both the quality and the volume of the tutorial to provide a better alternative to those ones over the internet.


Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you for your review, @yokunjon!

So far this week you've reviewed 2 contributions. Keep up the good work!

Hi @mariusclaassen,

Sadly, your tutorial doesn't follow the tutorials template. And the presentation needs improvement, I suggest spending some of your time reading the top contributions for Tutorials category which is a weekly publication of Utopian, as for period 2nd to 8th of August, click here. And your tutorial is a bit basic and is well-documented in the web, like this one. Try looking for open source projects and do tutorials that are unique and that gives value to open source. Lastly, you may try following @drsensor, both here in Steemit and Github, to see how he does his tutorials and you can use his methods for your reference.

I thank you for your feedback. But, I have to correct something to avoid confusions. Contributions might not follow the templates if they are well organized. That is only a guideline which shows a good way to structure the posts, but it isn't the only way.

Hey @josephace135
Here's a tip for your valuable feedback! @Utopian-io loves and incentivises informative comments.

Contributing on Utopian
Learn how to contribute on our website.

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

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

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