Загрузка...

Java Variables, Data Types & Android Views - Android Virgin 4

There goes the flannel, you're so close, feeling overloaded… with information? In this lesson we’re going to make shit happen, but first let’s learn a little bit about variables in Java. Variables are containers, they hold stuff in your program, from strings, which are usually words and sentences, to numbers and more complex objects. Lets do an example, here we set the variable pickupLine equal to “Hey girl, you had me at hello world”. Let’s break this down, In Java we use camel case when declaring variables, so no spaces, but the second word L is capitalized. The first word String is the data type which specifies the type of data pickupLine will hold. Here’s a list of the more common data types, int holds a number, float holds a decimal, boolean holds true or false, char holds a single character, and String. Notice String is capitalized, that’s because its a complex data type while the others are known as primitives. All this means is String is actually an object that we can call methods on. If you’ve done any other coding you probably know about functions, well methods are pretty much the same thing except they exist within an object. So we can do something like String dot length and it will return the length of the string. Length is a method in the String object. Of course if we wanted to set that value to a variable we’d have to set the type to be int because it returns a number. Strings are always enclosed in double quotes.

Now that we know about variables, let’s jump back into Android studio and open the main activity java class. In Java the file name is the same as the class it contains, so MainActivity.java contains the MainActivity class. This is where the magic happens. Let’s do a few things to help us get started, first turn on line numbers by right or control clicking in the gutter, the little area to the left of the open file. Second lets turn off automatic code folding, if you click that little plus icon next to import at the top of the page it will unfold that bit of code, it’s good to see everything that’s going on when you’re a newb, and let’s make sure automatic importing is turned on, which means Android Studio will automatically add a line to import stuff when you use it in your code. Go into preferences, or settings for windows, editor, general, code folding and turn all of that off. Next, go to auto Import and make sure everything is checked. We’ll show what this does in a second. Click apply then ok.

Видео Java Variables, Data Types & Android Views - Android Virgin 4 канала CodeBabes
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять