Chapter 7. Java Variables, Operators, and Expressions

In this chapter and the next, we are going to learn and practice the core fundamentals of Java data and manipulating that data. In this chapter, we will focus on the creation and understanding of the data itself, and in the next, we will see how to manipulate and respond it.

We will also quickly recap what we learned in the earlier chapters about Java, and then dive into learning how to write our very own Java code. The principles we are about to learn are not limited to Java, but are also applicable to other programming languages as well.

By the end of the chapter, you will be comfortable writing Java code that creates and uses data within Android. This chapter takes you through the following:

  • Java syntax and jargon
  • Variables
  • Operators
  • Expressions

Let's learn some Java.

Java is everywhere

The core Java fundamentals that we are about to learn apply when working within classes that we inherit from (such as Activity/AppCompatActivity), as well as classes that we write ourselves (as we will start to do in Chapter 10, Object-Oriented Programming).

As it is more logical to learn the basics before we write our own classes, we will be using the extended Activity class, AppCompatActivity, to add lots of different code in a whole bunch of mini-projects in the next few chapters to learn and practice Java. We will use Log and Toast again to see the results of our coding. In addition, we will use more methods that we will write ourselves (called from buttons), as well as the overridden methods of the Activity class to trigger the execution of our code. We will finally get the full details on methods in Chapter 9, Java Methods.

When, however, we move onto Chapter 10, Object-Oriented Programming, and start to write our own classes, as well as understand more about how classes written by others work, everything we have learned here will apply then too. In fact, this applies to all the Java that you learn in this chapter and the next, if you strip it out of the Activity class and paste it into another Java environment, such as any of the following:

  • Any of the major desktop operating systems
  • Many modern televisions
  • Satellite navigation systems
  • Smart fridges
  • and more...

The Java will work there too!

Tip

Calling all Java gurus!

If you have already done some Java programming and understand the following words: if, else, while, do while, switch and for, you can probably skip to Chapter 10, Object-Oriented programming. Or you might like to skim over this information as a refresher.

Let's get on with learning how to code in Java.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.225.173