Hello, I'm Doug Schmidt, and I'd like to welcome you to the overview of our MOOC on Java for Android, where you'll learn how to apply Java programming language features and tools used in Android, which is the dominant platform for developing and deploying mobile apps. This knowledge will help you write apps for the millions of people around the world who use Android devices to direct them to the places they want to go, securely provide information about the people, locations, goods and services near them, and help them interact with the people they care about and do business with. The demand for Android app developers is large and growing, so you're making a wise investment in your future by completing this MOOC. Hi, I'm Jerry Roth. In this MOOC, we'll cover key object-oriented features that are supported by the Java programming language. These Java features enhance the clarity of an app by controlling its flow of execution, enhance app utility by enabling access to structured data, enhance app modularity by grouping related methods and fields into classes and interfaces that shield apps from implementation details that are likely to change, and enhance app extensibility by transparently customizing the behavior of existing classes via inheritance and polymorphism to meet new requirements. Hi, I'm Michael Walker. In this MOOC, you'll learn how to apply the Java features Jerry just outlined in the context of core Android components such as basic user interface elements and activities for displaying user-facing operations. You'll also learn how to create Android apps by using the integrated development environment provided by Android Studio, which comes bundled with many tools. Some of the tools we'll cover in this MOOC include a wizard for creating new apps, a visual editor for creating graphical user interfaces, an emulator for testing apps on your computer, and a debugger for locating errors in your code. Hi, I'm Julie Johnson. After completing this MOOC, you'll understand the key object-oriented features needed to program Java for Android as well as know how to install Android Studio and apply it and other tools to develop and debug Android apps. Java is a large and evolving language which contains new features that aren't yet supported in Android. However, the Java features we do cover will enable you to successfully complete the programming assignments in this MOOC and build the foundation to continue your mastery of Java and Android in other MOOCs offered on the Coursera platform. So let's get started. Welcome to the first module in our MOOC on Java for Android, which summarizes the MOOC's structure and contents, explains its prerequisites, workload and learning strategies, and presents an overview of key features in the Java language, focusing on its support for object-oriented programming concepts used to develop Android apps. After completing the lessons in this module, you'll be able to understand how to meet the course requirements, name the key object-oriented features in Java needed to write Android apps, and know where to find the information and resources you need to succeed in this MOOC. Much of this information is available in the Frequently Asked Questions or FACC website, so please read it carefully prior to watching the lessons in this MOOC. Welcome to the next lesson in this module, where we explain how this MOOC is organized and discuss steps you can take to master the material we cover. After completing this lesson, you'll understand the MOOC's structure and the main topics covered in each module of the MOOC, and recognize what's expected of you in terms of background knowledge and the steps you should take to complete the programming assignments and quizzes successfully. You'll also learn where to find more information on developing Android apps in Java effectively. Most topics we cover in this lesson apply to all the MOOCs in the specialization, so please watch it carefully. We'll start this lesson by summarizing the contents of this MOOC that follow the overview material in this first module. The second module presents an introduction to Android Studio, explaining how to install it, as well as how to apply it to develop simple apps written using the basic Java and Android features covered in this MOOC. The third module shows how to write other simple Android apps that use methods to define variables using primitive Java data types, assign values to those variables, and then output the variables to the Android display. Module 4 covers Java features that control the flow of execution through an app, including its various iteration constructs, such as for loops, while loops, and do while loops, as well as its conditional execution constructs, such as if-else statements. Module 5 provides more detail on Java features that enable apps to access structured data. These features include its built-in arrays, common classes in the Java collections framework, array list, and hash map, as well as the for-each loop, which can be used to iterate through each element in the Java collection. The sixth module covers Java features that group related operations and data into classes and interfaces. These features include Java's methods, generic parameters, fields, and exceptions. Module 7 examines Java features for customizing the behavior of existing classes via inheritance and polymorphism. These features make it possible to extend classes transparently and override their methods to customize the behavior. Finally, Module 8 guides learners through the creation of an Android app that implements a simple calculator, providing features for adding, subtracting, multiplying, and dividing numbers added by various means, such as a text string and via buttons on the Android user interface. The modules in this MOOC are structured uniformly. In particular, each module is composed of multiple lessons, which cover a set of related topics, such as Java classes, conditional statements, or the Android Studio app wizard. Each lesson is presented as a single lecture. Each lesson is composed of segments, including intros and outros that summarize the lesson's learning objectives, and one or more segments that present the technical content of the lesson. In-video quizzes periodically pop up to check if you've mastered the material covered in the lesson. If you download the videos and watch them locally on your computer, these quizzes won't appear, and some of the questions may show up on the weekly standalone quizzes, which we discuss later in this lesson. This MOOC specialization is intended both for learners who are just starting to program, as well as for learners switching to Java and or Android for the first time. The topics covered in the MOOC are based on material we teach to our undergrad students at Vanderbilt University. When teaching these courses to our students face-to-face, we can rely on them having taken the necessary prerequisites in the right order. In contrast, one challenge of teaching MOOCs is that we don't really know what you know, or whether you're prepared to master the topics we cover. We develop this specialization with certain expectations of learners who take the MOOCs. These expectations are summarized in the frequently asked questions or fact web page. In particular, this MOOC is intended for self-motivated learners interested in understanding both the concepts and practice of developing mobile apps. It's also intended for learners who are curious about the entire Android platform at the API level, as well as the inner workings of its software stack. Finally, we expect that learners are willing and able to read and follow the instructions in the MOOC assignments and announcements. We don't expect you to have a computer science background. However, we do expect you to have basic computer literacy skills, such as knowing how to send and receive emails, browse the web, participate in online discussion forums, and upload and download files on websites. Naturally, after you complete this MOOC specialization, we expect you to know how to use Android Studio, how to apply Java features needed to develop apps using core Android components, how to use the Git software version control system, as well as how and when to apply common software engineering concepts, methods, and programming skills to develop mobile apps for Android. There will be several programming assignments in this MOOC, all written in Java using Android Studio. The fact outlines which versions of Android and Java software to install so that everyone will have a common environment. All source code for the assignments and examples, as well as the source code for Java and Android, is available online via the links available at the MOOC GitHub website. The programming assignments will provide you with experience developing apps using a range of Java and Android features. The assignments may change a bit for each MOOC offering to keep the material fresh and aligned with enhancements in the Android platform. However, they are all designed to enable you to demonstrate mastery of each Java feature we cover. The stand-alone quizzes given weekly will be due at the end of the MOOC and are entirely auto graded. In contrast, the programming assignments will be assessed via a mixture of auto grading and peer grading, using the evaluation process discussed in the fact. If you're taking this MOOC to get a verified certificate, you're required to take the quizzes and complete the programming assignments, which will tally using the grading criteria described at the MOOC GitHub website. Learners taking this specialization are expected to devote time and effort each week to watch the lessons, take the quizzes, and complete the programming assignments. However, we recognize that everyone has different learning styles, backgrounds, motivations, aptitudes, and time commitments. Therefore, we can't precisely estimate how much time you'll require to complete the MOOCs in this specialization. In general, of course, the more time and effort you can expend on these MOOCs, the more benefits you'll receive. Naturally, you can also take these MOOCs solely to learn the material and expand your knowledge of Java and Android, in which case there's no need to take any quizzes or submit any programming assignment solutions at all. This MOOC specialization covers a wide range of topics, some of which require careful thinking and practice to master. To help you learn all this material, here are some strategies we suggest you consider when navigating through the lessons in these MOOCs. First, watch the lessons carefully before taking the quizzes and doing the programming assignments. Some topics we cover are technically deep, especially the more advanced Java features like inheritance and dynamic binding. So consider watching these videos multiple times, perhaps at different rates of speed, to fully comprehend the topics we're covering. Although we can't address all aspects of Java and Android in our limited time together, you may benefit from other online resources to learn more about these topics, either during or after these MOOCs. Therefore, many slides contain links to articles, tutorials, source code, and documentation that you can explore as your time and interest permits. No quiz questions relate to these supplemental materials, so feel free to examine them at your leisure. Although it's helpful to browse the freely available resources online, the list of suggested readings on the MOOCs GitHub website provides even more comprehensive information related to programming Java and Android. We therefore encourage you to read these books to gain additional insights into the material we cover in the lessons. We also recommend watching tutorials that provide additional coverage of topics related to Android and Java. For example, the videos and screencasts from the Coursera MOOCs and classes we teach at Vanderbilt University are a great online resource. Although MOOCs provide a flexible learning model, you may want a more immersive experience by attending Coursera Meetup groups near you, where you can join your fellow students for face-to-face conversations and further engage in the topics we cover. Another way to make this MOOC feel more like a face-to-face course is to participate in the online discussion forums, where you can interact with other students, post questions, give answers, clarify points of confusion, and learn who else is wrestling with some of the same challenges that you are. The teaching staff regularly monitors the forums and provides tips and pointers to mentor you through the learning process. However, they're only a handful of us, but tens of thousands of you, so please read the policies on forum posting at this link and be respectful of fellow students and staff. Now that you've completed this lesson, you should understand the overall structure of the MOOC and the main topics covered in each module, recognize what's expected of you to learn the material presented in the upcoming lessons in order to complete the programming assignments and quizzes successfully, and know where to find more information on topics related to developing Android apps in Java. Much of this information is available in the FAC, so please read it carefully prior to watching the remaining lessons, since it provides useful insights and suggestions to help you master the material in this MOOC. Welcome to the first part of the next lesson in this module, which begins our overview of the Java Object Oriented Programming Language. Java was originally created by James Gosling and his colleagues at Sun Microsystems in the early 1990s. Dozens of object-oriented programming languages have been developed over the past six decades. Although these languages differ in various ways, they all support key object-oriented programming concepts, such as abstraction, inheritance, and polymorphism. After completing this part of the lesson, you'll know what these concepts generally mean in the context of object-oriented programming, understand specifically how the concept of abstraction relates to the Java programming language, recognize the benefits abstraction provides developers of Java apps and Android, and be able to identify Java features that implement various data and control abstractions, such as Java's conditional statements, loops, classes, and interfaces. Neither parts of this lesson examine Java code examples in detail, since our goal here is just to provide the big picture of object-oriented concepts and Java features rather than give a detailed explanation of these topics, which is the focus of the rest of this MOOC. Therefore, feel free to race through this material quickly if you don't need a high-level overview of object-oriented programming concepts now, and then return later and re-watch this lesson after completing the remaining modules on the Java programming language. However, if you're interested in deepening your understanding of these object-oriented programming concepts at this point, we highly recommend that you read the material at the URLs listed on the slides to learn more about each topic we discuss. Java is an object-oriented programming language, which means that apps written in Java are organized in terms of structural elements, such as groups of classes, interfaces, and packages whose arrangements are guided by design patterns. These structural elements are used to create, access, and manipulate objects, which are instances of classes that perform certain operations and interact with other objects in and out. An object in Java resides in a memory location of a computer. It consists of state, represented by a Java data fields, and behavior, represented by a Java methods. Objects often correspond to entities found in the real world. For example, an online banking app might have objects like accounts. An account state keeps track of the account balance and whether overdraft protection is enabled. Likewise, its methods implement behaviors involving deposits, withdrawals, and checking the current balance of an account. In contrast, non-object-oriented programming languages, such as procedural languages like C, AIDA, or Fortran, organize apps in terms of functional elements, such as actions and logic. Naturally, object-oriented programs written in Java also perform actions and contain logic. However, these functional elements don't constitute the main focus of the way programs are structured and designed in Java. Instead, Java supports key concepts found in all object-oriented programming languages, including various data and control abstractions, such as classes and loops. These abstractions enhance the modularity and clarity of object-oriented app software by emphasizing important interfaces and operations and objects, and shielding app developers from unimportant implementation details that are likely to change over time. Other key object-oriented concepts supported by Java include inheritance, which enhances reusability by enabling a class to receive and extend methods and fields like transparent class and polymorphism, which enhances extensibility by enabling transparent customization of existing class behavior to meet new requirements. Many popular programming languages implementing these object-oriented concepts are in widespread use today, particularly Java, C++, C-sharp, and Python. Therefore, once you understand the features of Java covered in this MOOC, you should be able to learn other object-oriented programming languages quickly and easily. In Java, however, you may be bored by some portions of this MOOC. In this case, feel free to move through this material quickly, so you can start on the next MOOC in this specialization. However, make sure you really understand how to program Java for Android, since examples and assignments appearing later in this specialization assume you possess this knowledge. The first object-oriented concept supported by Java that we cover in this lesson is abstraction, which is an essential part of all object-oriented programming languages. Abstraction helps developers master the complexities of writing apps by emphasizing what's important and de-emphasizing what's unimportant at a particular level of detail. In particular, abstraction helps developers focus on what their apps are doing to meet the requirements rather than being distracted by lower-level implementation details of how their apps work in a given operating environment. Java supports many object-oriented abstractions that we cover throughout this MOOC. For example, it supports various data abstractions, such as classes and interfaces, which cleanly separate key abstract properties of a data type, such as its application programming interface, or API, from concrete implementation details, such as the use of a particular algorithm or data structure. This separation of concerns avoids breaking app code that uses the API when implementation details are modified or optimized. Java also supports a number of control abstractions, such as if statements and for loops, which determine the order in which individual statements or method calls are evaluated or run. We'll now summarize various examples of data and control abstractions supported by Java. Java supports data abstraction via the concept of an abstract data type, or ADT, which defines a set of data values and a set of operations on these values. For example, the Java integer class is an example of an ADT that contains a value, such as the number 42, together with operations on the value, such as methods that create an integer object from a primitive int value and vice versa, as well as methods that compare two integers for equality. At the heart of an object-oriented language's support for data abstraction is encapsulation, which hides an ADT's internal representation to ensure apps using the ADT can only access its public operations and can't access any of its implementation details that may change over time. Java supports ADT's via its class feature, which defines a blueprint for creating objects. A class provides both fields, which are used to store the state of an object, and methods, which are used to implement the behaviors of an object. For example, the Java string class contains fields that store a sequence of characters and a length of the sequence, along with methods that examine individual characters of the sequence, compare strings, search strings, extract substrings, and create copies of a string. In Java, all objects created from the same class share the same methods, but each object may store different data values in its fields. Another form of data abstraction supported by Java is the interface, which defines a contract specifying methods that classes implementing the interface must provide. A Java interface provides a subset of the features provided by a Java class. For example, an interface in Android cannot contain method implementations, only method signatures, which include the method name, and any parameters that indicate what values can be passed to a method when it's invoked at runtime. A Java interface can't be instantiated, but instead must be implemented by a class, which defines the interface's methods, along with any fields needed to implement these methods. For example, the Java comparable interface defines the compare-to method, that compares an object to another object to determine their relative order. This interface is implemented by classes like integer and string to define a natural order of their instances. Classes and interfaces can be grouped together into packages, which provide a namespace for organizing Java code in a logical manner. For example, the Java.lang package contains classes that are fundamental to the design of the Java programming language. The Java.util package contains a collection of common reusable ADTs, such as ArrayList, HashMap, and Vector. And the Java.io package contains a group of classes that perform system input and output via data streams, serialization, and the file system. Organizing classes and interfaces into packages makes it easier to manage large software projects with many team members by avoiding collisions between classes and interfaces that have the same common name, such as point, shape, or map. In addition to being grouped into packages, classes and interfaces can also be parameterized via the Java generics feature, which enables the passing of ADTs as parameters to the definition of classes, interfaces, and methods. For example, the Vector class in the Java.util package can be parameterized so that its methods operate on a particular ADT element, such as an integer or employee. Generics offer several benefits to Java programmers. For example, they eliminate the duplication of code by adhering to the Don't Repeat Yourself principle, which states that every piece of knowledge must have a single, unambiguous, authoritative representation within a system. Generics also ensure compiler type safety when operating on different types of ADTs. For example, a vector of integers will not accept a value of type double. Likewise, a vector of doubles will not accept a value of type integer. The Java collections framework uses generic classes and interfaces to implement common type-safe reusable ADT collections, such as ArrayList, Vector, and HashMap, which in turn can be parameterized by other ADTs, such as an ArrayList of integers, a vector of doubles, or a HashMap of employees. The Java garbage collector supports yet another form of data abstraction. Garbage collection is a memory management mechanism that automatically reclaims and recycles objects, not currently in use by an app. Java's garbage collector makes it easier to write apps by alleviating many tedious and error-prone aspects of releasing dynamically allocated memory in languages like C that lack garbage collection. For example, it abstracts the steps associated with manually keeping track of how long each object is used in an app so the object's memory can be released when it's no longer needed. Not all object-oriented languages support garbage collection, but it's an essential feature of Java. In addition to the data abstraction mechanisms we just covered, Java supports various control abstractions, which determine the order in which individual statements or method calls are evaluated or run. A fundamental type of control abstraction is the conditional statement, which can be used to selectively alter the flow of control through an app, so it performs different computations or actions, depending on whether or not a programmer-specified condition evaluates the true or false. An example of a conditional statement supported by Java is the if-else statement, which helps apps achieve flexible flows of control through their algorithms and data structures. Another type of control abstraction supported by Java is iteration, which enables the repetition of a block containing one or more statements within an app. Examples of iteration features supported by Java include for loops, while loops, and do-while loops. These iteration features are often combined with conditional statements to write Java apps with sophisticated control flows. Yet another form of flow control abstraction supported by Java is exception handling, which separates the control flow paths of normal app execution from the control flow paths of anomalous app execution. For example, by using exception handling, the control flow path of an app will differ in a nicely structured way if the file it attempts to open is available on the computer versus not being found. When used properly, exception handling makes Java apps more robust and easier to understand and evolve. Now that you've completed the first part of this lesson, you should know what the concepts of abstraction, inheritance, and polymorphism generally mean in the context of object-oriented programming understand specifically how the concept of abstraction relates to the Java programming language, recognize the benefits abstraction provides developers of Java apps and Android, and be able to identify Java features that implement various data and control abstractions, such as Java's conditional statements, loops, classes, and interfaces. The next part of this lesson provides further coverage of inheritance and polymorphism, which are more advanced object-oriented concepts supported by Java. Welcome to the second part of the lesson, which continues our overview of the Java object-oriented programming language. Most programming languages support a range of data and control abstractions, which make it easier to simplify the development of robust apps that are able to evolve flexibly over time. However, object-oriented languages go above and beyond data and control abstractions. In particular, Java supports more advanced object-oriented concepts, including inheritance, which enhances code reuse by allowing a class to receive methods and fields defined by another class, and polymorphism, which enables transparent customization of the methods inherited from an existing class. After completing this part of the lesson, you'll understand what these advanced object-oriented concepts mean, know the benefits they provide developers of Java apps and Android, and be able to identify Java features that implement these concepts. Although these advanced object-oriented concepts and Java features are powerful, they may take some time to understand fully. Subsequent lessons in this MOOC therefore examine Java inheritance and polymorphism in much greater detail, so you'll learn how to program these features effectively. Object-oriented programming languages enhance reuse by allowing classes to inherit commonly used state and behavior from other classes. Inheritance in Java is specified via its extends keyword. When a class, called a subclass, extends another class, called a superclass, the subclass automatically inherits all non-private fields and methods defined in the superclass. Private fields and methods are not visible to the subclass. For example, class B is a subclass that inherits mField 1 and method foo from the class A superclass. Apps that use instances of class B can therefore invoke both the method foo inherited from class A and the method bar defined by class B. This lesson uses the Java collections framework as a case study to demonstrate the capabilities and benefits of inheritance, which enables the reuse of existing Java software components. This framework defines a hierarchically organized set of classes and interfaces that implement commonly reusable collection data structures, such as lists and maps, which are covered later in this MOOC. Here we'll examine a portion of the list hierarchy, which are collections that implement the list interface and maintain an ordering for their elements. The Java Abstract Collection Superclass provides a skeletal implementation of the collection interface. This superclass forms the root of the hierarchy of collection subclasses that provide various implementations of ordered and unordered groups of abstract data type elements. Likewise, the Abstract List subclass extends abstract collection and skeletal implementation of the list interface, thereby minimizing the effort required to implement this interface using a random access data store, such as an array. Various concrete subclasses, such as Vector and ArrayList in the Java Util package, extend Abstract List to provide implementations of the list interface using dynamically resizable arrays. This inheritance hierarchy enhances systematic reuse of both data fields and methods for the subclasses of the Java collections framework. All Java classes directly or indirectly inherit from the Object Superclass that resides in the Java-Lang package. This superclass defines methods that can be used by all non-primitive types, such as classes and arrays. For example, Object defines methods that return an integer hash code for an object and use this hash code to check whether two objects are equal or not, as well as methods that objects can use for interactions and multi-threaded programs. Subclasses that don't explicitly extend a superclass implicitly inherit from Java-Lang Object. For example, the Java-Lang Process class doesn't explicitly extend any superclass, so the Java compiler implicitly inherits this subclass from Java-Lang Object. All instances of Java-Lang Process therefore also provide clients with access to the inherited Java-Lang Object methods. As you may have noticed, Java-Lang Object is the most general of all classes, since it serves as the root of the hierarchy of classes available to Java apps. Classes toward the bottom of this inheritance hierarchy provide more specialized behavior by overriding methods that are defined above them in the hierarchy. For example, the Vector, ArrayList, and LinkedList subclasses in the Java Util package implement their particular semantics by overriding certain methods higher up in the Java collections framework hierarchy. Subclass methods inherited from a superclass are generally used for three purposes. To make this discussion more concrete, we'll illustrate these purposes with an example of the generic stack subclass defined in the Java collections framework. This subclass extends the generic Vector superclass to define a last-in-first-out or LIFO data structure that enables apps to push and pop items to and from the stack, respectively. The first purpose for extending a superclass is to augment the methods defined in the subclass API. For example, the stack subclass inherits fields and methods from the Vector superclass. This code snippet shows how the isEmpty method inherited from Vector can be invoked on an instance of stack to determine if the stack is empty or not. The second purpose of inheritance is to use methods defined in the superclass to implement subclass methods. For example, the stacksPush method is implemented by the addElement method inherited from Vector, which is yet another example of systematic reuse that's enabled by inheritance. The third, and arguably the most important purpose of inheritance, is to override superclass methods in the subclass that have the same signatures. In Java, method signatures are considered the same if the method names are the same, and the number and types of method parameters are also the same. For example, the hashMap subclass in the Java collections framework overrides methods with the same signatures as abstractMap superclass methods, such as put and entrySet, which associate values with keys in a map and return a view of the mappings contained in a map, respectively. Method overriding enables a subclass like hashMap that transparently customize the behavior of a superclass like abstractMap, as we'll discuss next in our coverage of the Java polymorphism. This upcoming discussion will also explore the ways in which abstractMap methods can be overridden to define different mechanisms for associating values with keys in a map and returning a view of the mappings contained in a map. It's possible to apply inheritance in isolation to systematically reuse existing superclass methods and fields. In practice, however, inheritance is nearly always applied in conjunction with polymorphism, which is a key object-oriented concept that enables transparent customization of subclass methods inherited from a superclass. Polymorphism and inheritance are essential to achieving the benefits of the so-called open-closed principle in object-oriented design and programming, which states that a class should be open for extension but closed for modification. Installating a class implementation for modifications helps make the class more robust and flexible, since it can be extended and reused without introducing new bugs to existing code. In particular, the open-closed principle can be applied in conjunction with various patterns, such as factory method, which defines an interface for creating an object but leaves it to the implementation of that interface to decide which class to instantiate. In this case, the polymorphic methods of a class can be customized without modifying its existing source code or modifying the source code of apps that use instances of the class. Subclasses of a superclass designed in accordance with the open-closed principle can define custom behaviors that are more suitable for a particular use case while still reusing the structure and even some functionality provided by their parent superclasses. For example, vector and array lists are subclasses in the Java collections framework that inherit reusable methods from the abstract list superclass. However, the implementations of methods in the vector and array list subclasses emphasize different properties of a list, such as synchronized versus non-synchronized element access and different strategies for dynamically growing the underlying buffer when its size increases. Java apps apply polymorphism when a reference to a superclass is used to refer to an instance of a subclass. Methods in the subclass can selectively override methods with identical signatures defined in a superclass, thereby customizing their behavior to achieve the desired subclass semantics. For example, the abstract map class in the Java collections framework contains methods that can be overwritten by concrete subclasses, such as tree map, hash map, and concurrent hash map. In particular, the put and enter set methods in abstract map can be overwritten to define different mechanisms for associating values with keys in a map, and returning a view of the mappings contained in a map respectively. The subclasses of abstract map have different time and space tradeoffs that are appropriate for different apps in different circumstances. For example, hash map's implementation of put uses a hash function and an array of buckets to resolve collisions, which is suited for apps that want good performance in average and best cases. In contrast, tree map's implementation of put uses a balanced red-black tree data structure, which is suited for apps that want consistent performance even in the worst case. An app that invokes a put method call on a reference to an abstract map can be extended transparently by the open-close principle, so the appropriate put method implementation is dynamically dispatched at runtime based on the object type of the concrete subclass that extends the abstract map superclass, such as tree map, hash map, or concurrent hash map. By applying the factory method pattern together with the open-close principle, the app code needn't change, even if the make-tree factory method creates a different concrete subclass when it's called at runtime. Object-oriented programming concepts are at the heart of modern app development in mobile and cloud computing environments. Java has been one of the most popular object-oriented programming languages since its inception in the early 1990s, which is why Google selected it as the programming language of choice for developing Android apps. Now that you've completed both parts of this lesson, you should understand what key object-oriented concepts, like abstraction, inheritance, and polymorphism mean in the context of Java, know the benefits they provide developers of Java apps in Android, and be able to identify Java features that implement each of these concepts. However, don't worry if you don't fully understand all these object-oriented concepts and Java language features yet, since the remaining lessons in this MOOC examine each feature in greater depth, analyze detailed code walkthroughs, and reinforce the lessons with assignments that enhance your knowledge of programming Java for Android. There are also other excellent resources available online, including the official Java tutorials and the Android API documentation, so please leverage these online resources frequently as you progress through the MOOCs in this specialization. Now that you've completed the first module in our MOOC on Java for Android, you should be able to name the key object-oriented concepts and Java features needed to program Android apps, understand how to complete the course requirements, and the information and resources you need to succeed in this MOOC. Much of this information is available in the Frequently Asked Questions or FACC website, so please read it carefully prior to watching the lessons in this MOOC. If this MOOC inspires you to learn more about Android app development, please consider taking our mobile cloud computing with Android specialization, as well as watching the digital learning resources available at my website, which provide many more hours of lessons than object-oriented design and programming for Android apps, patterns and frameworks for concurrent and network software, and Android middleware and systems programming mechanisms. And now let's get on with the rest of our MOOC on Java for Android. Welcome to the second module in our MOOC on Java for Android, which presents an introduction to Android Studio and shows many examples of applying its tools and features to develop simple apps written using some basic Java and Android features covered in this MOOC. After completing the lessons within this module, you'll be able to install the Java Development Kit and the Android Studio Integrated Development environment. You'll also know how to create new app projects and import existing app projects into Android Studio, as well as know how to select and edit files that are commonly used windows and tools provided by Android Studio. Likewise, you'll learn how various types of files are organized and edited within Android Studio projects, including Gradle files to define how to compile and build an app, source code files that define the logic of your apps and resource files that control the apps look and feel. This module explains how to create and manage Android virtual machines. Which emulate the behavior of apps on your development machine so that they appear to run on physical Android devices. Finally, you'll learn how to use Android Studio's tools to help debug your apps and app projects. Additionally, the most effective way to learn the material is by opening Android Studio and following along with the examples in the lessons. In this video, we will show you how to install Android Studio on your computer. To start, open up your favorite browser and your favorite search engine, whatever they may be, and simply search for Android Studio Download. That's search for Android Studio Download. You will probably get the very first link will be to download Android Studio. You click on it and it will bring you to a page where you can download Android Studio. When you do that, you will always want to install and download the latest version. Currently, the current version is 4.0.1 at the time that this video is being made. Whatever time you're doing this, you always want to install the latest and greatest version of Android Studio. All you need to do is click on the download Android Studio button. You will get displayed their terms and conditions. Through them, if you'd like, click that you have read them and that you agreed to them and then click on download Android Studio. At this point time, the download will begin. Or your browser may ask you where you want to save. For me, my browser is already going to start downloading this software, the installer software to my computer and I can see this progress down here in the lower left. In the meantime, we're going to wait for this to finish and we're going to cut this portion of the video out and go right to the point where it's once it's completed. Now that our download has completed, we can click on this button over here and I can either open the software or actually I want to show it in this folder. I'm going to open it up in my download folder and I'm going to grab that executable and drag it on to my desktop. Once I've done this, I can close down the folder. I can close down my browser and then I can double click on the installer. It'll take a moment for the installer to open up and then usually your operating system will ask you if it's okay to have this installed so we're going to click yes and then the installer starts begins. At this point in time, we are just going to go through the installer and accept all the defaults. Please always accept all the defaults no matter what may be shown on the screen, just accept all the defaults. So here we want to install, yes, next. What components do we want to install? We're just going to accept the defaults. Next, where do we want to install it? We're going to install it in the default place. Next, what do we want to call it? We're going to call it the default, which is Android Studio. That's great. We're going to hit install. And now this installer will do the work to install Android Studio on your system. Again, we will edit this part out and you'll write to the point where the installation has been completed. Now that the installation is completed, we can just go ahead and click next. Then it says that it's been completed and do we want to start Android Studio? We're going to go ahead and start up Android Studio. Android Studio will then start up and you'll be displayed the open welcome splash screen, which is right here. Before we go in and do anything, the one thing we need to do is we need to make sure that we've loaded on your system the necessary SDK for the current version of this class. You need to have API 29 installed on your system. To do that, we just go to the configured drop-down menu down here and click that we want to go to the SDK manager. We want to click on that. The SDK manager will pop up and for me it shows that I already have API 29 installed. I also have API 22 installed. You can pick any API you want that's not necessary, but you're going to want to click that you want API 29 installed and then install it. I already have installed, so I go ahead and click OK. At this point in time, our Android Studio is ready to be used for this Coursera MOOC class. Our next video will show you how to open a project using Android Studio. In this little video, we are going to demonstrate how to get started on a program assignment. You first start by visiting the assignment page in Coursera. Here we are looking at the very first assignment on geometry calculations and you read through the introduction, the learning outcomes and the resources. Make sure you pay attention to all the information that's given to you that you can look at. You're going to want to read the project very carefully, but what we're interested in this demonstration is actually looking at the code. Under the supplied code is a zip file. You want to click on this zip file and download it to your computer. I have already downloaded it to my computer here. When we get down to these zip files, Android Studio does not operate on the zip file so you have to extract the contents of the zip file onto your computer. How you do that is based upon your operating system. For me, working on this Windows machine, I can just simply right click on it and specify extract all. I'm going to have this extracted to my desktop because that's where I have my current folder. I'm going to extract that file to my desktop and now we see that it shapes on my desktop. We can see right here, we click in it, we can see the application or the project. We're not interested in doing that. Now we're interested in opening this project in Android Studio. I'm going to bring up Android Studio and specify that I want to open an existing project. I always want to open an existing project. The project is provided for you. It's an existing project. We just simply want to open it. I'm going to click on open existing project. Then I need to find the project that I just created. For me, that's on my desktop. I need to expand my user ID. Go down to desktop. Expand desktop. Then we see here M3 shapes or whatever folder we just extracted. If I expand it, we will see inside of the app folder. We don't want to open up the app folder. We want to open up the folder that holds the app folder. M3 shapes, that is what we want to open up. We find this folder we just extracted and specify that we want to open it. I'm going to click on OK. Now this is where Android Studio needs to do a lot of work. Pay attention to all these messages down here on the lower bar. They're doing a lot of work and we have to wait until they are all done. Particularly this might take a while. The first time you open a project this is not the first time I've opened this project. This will be a little bit more quickly. Also pay attention to any messages down here about things being updated. Here I have enough things to say. My Android Gradle plugin is ready to be updated. I'm going to click on update. Always make sure your software is always updated. I'm going to go ahead and click update. I'm going to say update. This will take the time now to update the software here. This might take a while. It may not take very long at all. I see here that it's been updated. We can minimize that. At this point in time we now are ready to start working on the project. To do that we can click on to do to find out where the to do comments are. That's where we need to do our work. We see in here that they're in logic.java. We can double click on that. Here's our to do comments. This is where we need to work by adding our code. At this point in time you'll go back and refer to the project spec to find out all the things that you need to do. You'll add that code here at the to do comments. Again when you want to start working on a project you download the zip file you extract the contents of the zip file onto your computer. You then use Android Studio to specify that you want to open a project. You then select the file the project folder that you just extracted onto your computer and you open that so when you open and then you have to wait for all the progress messages to end. Once you do that then you can read the project spec and follow all the instructions to do your implementation for the assignment. That's all we're going to talk about in this video is how to open the project. In our next video we'll talk about after you've actually done your implementation how to test your project. We'll do that in the next video. Welcome to the next lesson in this module. Well you'll learn how to manage your projects within Android Studio. Android Studio allows you to not only create your own projects but also to import projects others have written. Therefore we'll show you how to create a brand new project using the new project wizard. This will allow you to create projects that you can practice and experiment on. Then we'll show you how to import an existing project into Android Studio. This will allow you to import the examples and assignments that we will give you in the future. After completing this lesson we'll understand how to create a new app project and how to import an existing app project into the Android Studio integrated development environment. When you have finished installing Android Studio you will have the following screen available to you. This screen allows you to both start new projects and to import existing projects. I will now show you how to create your own project with the built-in Android Studio. To start we click the top button here aptly labeled start a new Android Studio project. This will start the new project wizard. This wizard will guide you through creating a new project. The first step is to enter the name of the application you want to work on. By default it is my application. I will go ahead and alter that and it will ask you for your company domain name. This company domain does not have to be a real domain name. So we are going to go ahead and recommend you leave that as example.com for now. The project location is where on your file system your new project will be created. Adjust this as you see fit to easily track your files. I personally have a folder named in my user directory where I put my projects but this is up to you. Click next. This new screen will assist you in determining what kind of devices you wish your app to be able to run on. For now always pick phone and tablet and API level 21. We have chosen this API level so as to be able to teach you new features that aren't available in previous API versions. Click next. This next window will help you in creating the default user interface for your app. For simplicity's sake I will choose empty activity and recommend you do the same for now if you create any new projects on your own. Click next. The next window will allow you to change the names of some of the auto generated files that this wizard is about to create for you. I recommend leaving them as is for now and clicking finish. Android Studio will go ahead and go through the process of creating your new project for you. Once Android Studio's new project wizard has finished you will see the following window. The tip of the day will only show up until you click the show tips on startup button here. I recommend you leave this on for now and go through the tips and learn more about the Android Studio integrated development environment. For now we will go ahead and click close. And here you have your new project. After you extracted your project from a zip file you will want to go back to the Android Studio welcome screen. There you will want to click on the button labeled import project, eclipse ADT, Gradle, etc. Then a new window will pop up asking you to select the project you want to import. It is asking for the location on your file system where the project exists. There are helper buttons for your home folder and your desktop. So I will make use of the desktop button which is the second button up here at the top. Normally I would have put this project into my code directory but for simplicity of this example I am just making use of the desktop. Once you have found the location of your newly extracted project it may or may not have a green circular icon instead of the image of a folder. This is because I have already previously imported this project preparing for this video so my Android Studio knows that this folder is a Gradle project. You will want to select the folder of your project and click OK. Android Studio will use its automatic import wizards to auto-configure things for you and import the project. This may take some time or it may go quick depending on the complexity of the project you are importing and the speed of your machine. When it is done you will be able to view and edit the imported project just the same as if you had created the project yourself. Now that you have completed this lesson you should understand how to both create new projects and how to import existing projects within Android Studio. Welcome to the next lesson in this module where you will learn some of the major windows within Android Studio. Android Studio is comprised of a lot of tools and specialized editor windows that you will learn how to make use of. In particular this lesson will discuss the three most commonly used windows within Android Studio. The main editor window is where you will edit the source code files within your project. The project files window will show you the files within your current project and allow you to select and open files you want to edit. And the layout editor is where you will see the files that define what your apps use your interface look like and edit them. After completing this lesson you will understand what the main editor window the project window and the layout editor window look like and their function. Let us now take a tour of the Android Studio Integrated Development environment. The Android Studio IDE has a lot of features and tools available to us. We will only cover some of the most useful features. For example, the main window here is where you will view, create, and edit the files that will make up your project. The left hand side of the window is where you will have an overview of your project as a whole. But these windows are dynamic and movable. You can easily expand and shrink individual windows. Such as clicking on the project window right now it will open and close the project view for us. You can also drag and slide the windows once you put your cursor over the dividing line and two arrows appear. Then you can grab and pull in either direction. In the main editing window you can click the tab up here at the top and that will take you to the file that you want to view. In this example right now we are currently viewing the main activity.java. I'm going to click on the activity underscore main.xml. The main editor window here in the center is also where you will view your user interface layout files. Our automatically generated layout file activity underscore main.xml is what you are seeing right now. When we clicked on the new tab the visual representation of our user interface layout file was rendered for us to see. This editor right here is what is called a what you see is what you get editor. Meaning you can drag and drop a new user interface component onto the layout and it will appear how we place it. In this example I can grab a new button drag it onto the application, let go and a new button is applied to the user interface. However the layout files themselves are actually XML files. If you come down here to the bottom and click text it will show you the actual XML file that is creating the user interface that we were just looking at. Click back on design and you can see the rendered version of it. Now that you have completed this lesson you should understand how to navigate to and use these major windows within Android Studio. In particular where the main editor window is for editing source code files where the project view window is for viewing and selecting files and where the layout editor is for editing the apps user interface files. Welcome to the next lesson in this module. Where you'll learn how the files within an Android Studio project are organized. Android Studio projects have several different types of files that you'll have to learn how to interact with. The first set of files that we'll show you are Gradle files. Gradle files are the scripts that define how to compile and build your apps. We won't discuss these in much detail right now but we'll show you where they are for the time being. A second major group of files within the Android project are the source code files. These are the Java source code files that define the logic of your application. The third major group of files we'll show you are the resource files. The resource files are files that your app makes you sub while it is running. Such as the user interface layout files that define what different screens of your app look like. Any images that are included within your app including the app's icon itself and XML files containing values used by your app. One example XML file resource is called strings.xml. This file is where you put all the words displayed by your app. That way you can easily translate every word into a different language and easily swap in and out which language should be used based on the user's language settings. After you've completed this lesson, you should have an understanding of how the files within your project are organized, where to look for specific file types and how to edit those files. Now that we have a basic understanding of the Android Studio editors for both source code files and layout files let us take a look at how Android Studio organizes our projects for us. Within the project view window here on the left, we will see a hierarchy of folders and some files. I will now explain to you some of these folders and files so that you will understand where they are located. I will minimize or close the Java file right now and you will see that there exists two main sections of the project app and Gradle scripts Gradle scripts for now we will skip over these are not relevant to your assignments for this course. The app portion is where your projects files exist. There are three main categories of files in the Android Studio project. Manifests which are special XML files that describe how the Android platform should interact with your project. Java files which contain the source code and logic of our app and the resources folder abbreviated RES the resources folder contains things such as images, user interface layout files and other files that hold special values for us. Let us first examine briefly the manifest folder. The manifest folder will only contain a single file for your projects you work on for this course. That file is called androidmanifest.xml This file defines how the Android platform on each user's device will interact with our app but the specifics of this will be discussed later. The Java folder will contain two main groups of files. The first is the source code or logic files of your application The other is test files. These test files help us verify that our source code files are bug and error free. The test files are easily identifiable because of the android test here at the end. Within the main source code folder we have our main activity.java is what we are currently looking at right here. The .java is left out inside the project view but if you look at it up here you will see the .java is included within the file name. We will skip the test code for now but it goes inside this folder here. The resources folder or shortened to res is where we store our user interface layout files, images and other special files that our application makes use of. The layout files are in an aptly named folder called layout we only have a single layout file within our project right now so only that one is listed activity underscore main.xml This is the layout file we viewed previously. One of the most important special files in this section within the values folder. This file is called strings.xml This file is where the strings used within our app are stored as special xml values so they can be used easily throughout the rest of our project and when the app runs on a user's device. Now that you have completed this lesson you should understand how the files within a project are organized where to look for each type of file and how to edit source code and resource files. Welcome to the next lesson in this module where you'll learn how to edit the files within an Android project. Android Studio has two main sets of files that you will edit. Java source code files that contain the logic of your app and resource files such as the user interface layout files. There are a couple other types of files such as the Gradle build scripts which will very rarely be edited and which you won't be required to edit it all in this course. So we're going to focus in this lesson on how to create and edit Java source code files and resource files. As you progress learning how to develop for in the ant test okay. As you progress learning how to develop for the Android platform you will come to the point where you need to create your own Java classes. Java class is easy and is accomplished by right clicking on the Java package you wish to create your file in. So for example right clicking on this package then you go to the new menu option and click Java class. This will ask you the name of your new Java class. Java classes by convention have their first letter capitalized and then only capitalized the first letter of new words. So for example here is my custom logic class which only capitalizes the C and L. Click OK and you will create a new Java class file that you can work with. Creating a new resource file is easy and is accomplished by right clicking in the folder you wish for the new file to be created in. The new resource file wizard will pop up and ask you for details about the kind of resource file you are trying to create. The window will ask slightly different things depending on which resource folder you right clicked on. If this new resource file that we are creating is a layout file for our custom logic class then we will right click on the layout folder click layout resource file and enter the name custom underscore logic dot xml Click OK A new resource file will be created for us. Resource files are named in all under case with underscores between each name so in our case custom underscore logic. Now you have a resource file that you can edit just as you would your previous resource files. Now that you have completed this lesson you should understand how to create open and edit both Java source code files and resource files. Welcome to the next lesson in this module where you will learn how to manage android virtual machines. Virtual machines or VMs allow you to run code on your development machine or inside a physical android device. One of the reasons this is useful is for testing run time behavior of your app when you don't have a physical device to test your code on or the physical device or devices you have aren't of the exact same specifications as to what you want to test your code on. This could mean having a different slide screen having a physical keyboard or not or testing a different version of the android api. Therefore, in this lesson we will show you how to do four things manage your current virtual machines how to create a new virtual machine how to start a virtual machine and how to run your app on a virtual machine. The first step in managing, creating or starting a virtual device running android is to open the android virtual device manager. To do that you will click this button here when you mouse over it will say AVD manager click that and this window will appear this is a list of all the virtual machines you have created on your machine once you have a virtual device set up and you want to start it all you have to do is click the green play button right here to launch the virtual machine however if your virtual machine doesn't launch for some reason or if you want to create a new virtual device then you will want to click on the button labeled create virtual device a new window will pop up asking you to select which pre-configured hardware configuration you wish to select we will be using the Nexus 5 for all of our examples and assignments so go ahead and select that and click next and you will see a list of system images that you have installed on your system my list is probably a bit longer than yours but that doesn't matter the important thing is to understand what you are looking at this grid of information contains two key columns the API level and the ABI these are the two central columns the API level is the API level of the image or Android operating system version that you want to run on your virtual device the ABI or application binary interface is the specification of what kind of CPU architecture your virtual device will emulate the important thing to know from this is that the ARM EA BI version 7 is the most universal but it will run slower on our machines because it isn't of the same instruction set as our desktops or laptops therefore running an x86 or an x8664 image would be faster however your device meaning your laptop or desktop needs to have a CPU that allows for virtualization and needs to have a feature turned on I won't go into how to do this now because each CPU and each system is different and you will have to address this yourself therefore my recommendation is to use the ARM EA BI version 7 ABI with level 22 API if you do not have that listed in your window here then click the show downloadable system images check box here and you will see a list of system images that you can download on your system note that there will be two system images that contain both the ARM ABI and level 22 API you will want to download the system image that contains with google APIs once you have this downloaded and then selected click next this last window will display additional features that you can change but for now I will recommend not changing anything and just clicking finish the wizard will create that virtual machine for you and to start it you will just click that green triangle play button located here this will launch the android virtual device for you once the progress bar for the starting has completed you can close the android virtual device manager the android virtual device will appear such as this you can move the window as you normally would any other window and we will wait for the android virtual device to finish booting the boot process is similar to a physical device so therefore we will just need to wait for the virtual device to finish booting once it's finished booting we can interact with it as we would a normal physical device this enables us to test our application on a virtual device now we will show you how to run an android app on a virtual machine and or a physical device the term emulator is interchangeable with the term virtual machine in this context therefore I will use that now since it is what the on screen dialogues that you will see in a few moments will mention the phrase starting your app will also sometimes be called launching your app both are also fine to start with let us take a freshly created project that was just auto generated by the new project wizard in addition which window or windows you have open with an android studio and what you have selected generally doesn't matter when you attempt to launch your app there are some advanced topics which will impact this but we will cover those in the future when they become important for now the important thing to know is that all you have to do to start running your app on a device be it physical or an emulated one is to press the run app button this is a green triangle that looks like a play button this button is within the tool bar at the top of android studio you can see a zoomed in representation of this within the red highlighted box pressing the green button will tell android studio that you wish to run your app I will press it now each time you reopen an android studio project the following window will appear when you press the run play button for the first time this window is asking you how you would like to run your app there are main options you can choose to run on a currently running device or you can launch an emulator when making use of an emulator I always try to launch the emulator just after opening android studio this way it has had time to fully start up before I actually need it when you have an emulator currently running or you have a physical device connected to your development machine this is the first section of this window android studio allows you to have multiple emulators started at once that is if your hardware can physically support it and it allows you to have multiple physical devices connected at once also however when you would have multiple devices connected you need a mechanism to determine which device to direct your app to for it to run on the first section here in the window lists all currently connected emulators and physical devices I currently only have a single emulator running on my development machine if you don't already have an emulator running or if you want to start a new one you can do so by clicking on the second radio button labeled launch emulator there is a drop down box in this section that allows you to select previously configured emulators or you can press the button after it that will open up the android virtual device manager which we used earlier this allows you to edit or create a new emulator if you choose so I'll go ahead and close this window and go back to the device chooser window I'll click on the radio button labeled choose a running device and the emulator I currently have running will be selected as is the only option available if there were more devices currently running you could choose between them if you only have a single device be it an emulator or physical device that you are testing your app on right now then you can click the check box labeled use same device for future launches this will result in future presses of the green run app button skipping this device chooser window and automatically launching your app on the device you have chosen I will go ahead and uncheck this box for now and click ok to tell android studio to first build my app then to copy my app file over to the device and then to launch the app on the device I'll press ok now you'll notice that a new window has appeared at the bottom of android studio this new window is called the android monitor it allows us to monitor the device that our app is currently running on you can easily open and close the android monitor window by clicking in the tab below labeled android monitor the android monitor shows us information about the device that we are connected to such as memory cpu gpu and network usage it also shows us the log tab which is where the logs of both the system and apps are displayed this log cat tab in particular will be very useful later when you are trying to analyze your app's runtime behavior however this topic is beyond the scope of this lesson and will be discussed later in greater detail I will now switch to the emulator that I have had running in the background and show you that our app is now running on it our app doesn't yet have any logic in it so pressing the button won't do anything but we have successfully launched our app onto an emulator launching an app onto a physical device is the same process you just have to choose it from the list in the device chooser window when it appears now that you have completed this lesson you should understand how to manage your current vms how to create a new vm how to start a vm and how to run your app welcome to the next lesson in this module where you will learn how to use some of android studio's tools to help you debug your projects debugging refers to finding defects or bugs in your programs the term bug is credited to admiral grace hopper when in the 1940s she found a moth stuck inside a computer that she was working on at harvard for the us navy this bug created an electrical short and caused the program that the computer was running to fail she debugged the computer and got it working again hence the term became applied to computing when it comes to finding and resolving problems modern integrated development environment such as android studio come pre-packaged with advanced tools to assist you in finding and resolving bugs bugs and software can be categorized into two main groups logical and syntax logical errors are when your program runs and doesn't crash but instead it produces output which is incorrect fixing logical errors is something that requires practice and the experience of the developer to resolve the other type of bug is called syntax error syntax is the rules by which the programming language requires your program source code to be written for it to be a valid program syntax errors can cause your program to not compile which is called a compile time error or if it does happen to compile there can be advanced bugs that make it crash these bugs are called runtime errors since you only find them when you try to run your app both of these types of syntax errors or bugs can be caused by a lot of reasons ranging from the code missing some type of keyword a character in the source code files being in the wrong place perhaps a simple typo or more complex topics which we will discuss later in this course in this video we'll discuss some of the tools available to you in android studio that will help you try and resolve syntax errors while programming you will encounter times when your program syntax isn't correct syntax is the rules by which a programming language is required to be written for it to function when your program has syntax errors it won't be able to be compiled or tested I have a simple example program in front of us right now this file has no syntax errors but to create one all I have to do is delete this semicolon right here when I do this several things will happen now you will notice a red squiggly line where the semicolon used to be this is indicating that there is an error here you will also notice that in the left hand window showing the project that the main activity file the file that I'm currently working on has a red squiggly line underneath of it informing me at a high level that this file has a syntax error also on the right hand side of the scroll bar in the text editor window there is a red line that I can click on because the syntax error in my code is simple the editor gives me a hint as to what it thinks this problem is informing me that a semicolon is likely missing the editor doesn't always give a proposed solution for you nor is it always correct when it does make a suggestion but its suggestion is a good starting place for what might be causing problems for you if you click on the red line the editor will take you to the location of the error adding back in the semicolon removes the red warning lines from within the file from the project description and from the right hand side and indicates that the application is now back in proper syntax the first step in fixing bugs in your app is to first identify and locate them now that you've completed this lesson you should understand how to identify find and even how to read the suggested tool tips about syntax errors within your app hello and welcome to the next video in this lesson about debugging tools in this video we're going to introduce you to the concepts of logging and in particular logging with android's log cat first of all what is logging? logging is the process by which you create a log file obviously this leads to the question of what is a log file and it is a record of events that happen on a system specifically in android it is a record of system messages that both the android platform and the apps create while they are running these system messages can be a variety of things ranging from error messages notifications and even messages that a developer can write to help them examine their apps run time behavior as a developer you'll also be able to write these messages you just need to learn the specific statements to put in your source code additionally android studio comes with special tools to help you efficiently read and filter these messages therefore in this video we'll introduce you to the statements that you'll need to use to write log messages we'll discuss what log levels are and how they impact logging we'll go over how to read the log file and how to filter the output of the log and we'll discuss some good practices for you to use when writing your own custom log messages to demonstrate how to log your apps run time behavior I have written a simple application that does nothing other than display some text when the on screen button is pressed I will show you some simple source code that will demonstrate how to log information from your app while it is running first we must include the following line at the top of our class file with the other import statements this line will be explaining how to fill in another lesson but for now we include it to tell the source code which library or set of code to actually use for the log statements used below before we get to the log statements just mentioned let me first show to you and describe another line that is important this line which you can see now inside the red outlined zoom box is the local variable that identifies the class file from which the log statements will come from this is important later in larger projects that have multiple class files for two reasons because it allows you to quickly identify where a log statement came from and because it allows you to filter out log statements that don't come from a particular class file if that is what you want both of these really help the process of debugging run time behavior easier and faster now let us scroll down to where the log statements are you will see a method called button pressed this method is ran when the onscreen button is pressed therefore we have log statements at the very beginning and end of the method that will log when the method starts and stops additionally the log statement after the onscreen text view has its text changed now let us examine one of the log statements in more detail we'll first look at the one at the beginning of the method you can see this easier in the red outlined zoom box this statement starts with log has a dot i which I'll explain in a minute then has in parentheses two strings the first is log tag which references the string above that says which class the log came from and the second which is in green is the output which we wish to be in the log now let us examine the second log statement this one is similar to the first but you'll notice some differences the first being that after the log in the very beginning of the statement you will see a dot v where in the other statement it was dot i this indicates which log level the statement should be associated with android has six log levels assert error warn info the first letter of these words are used to indicate what level you want your log statement there does so dot i is an info level log statement and dot v is a verbose level log statement log statements exist in many programming languages and help the programmer to declare what the severity of an individual log statement should be this also helps in allowing developers to temporarily filter out statements that they don't deem significant at a current time when they are looking at logs by the log statements having a priority to their severity levels the log level assert has the highest severity meaning that if you filter on the assert level no other logs will be displayed that are below the assert level error has the next level of severity meaning that if you filter on error messages you will only see messages above or at that severity level meaning either assert or error this pattern continues with warning showing warning and the two higher severity levels error and assert with info displaying info statements and the three levels above it error, assert and warning then debug filtering shows debug and the previous levels and verbose has the lowest level severity meaning that if you filter on that level you will see all log statements getting back to the log statement we were previously examining it has the log tag variable as its first string which indicates it is from this class then it has a string in green similar to the previous log statement however after that green text it has a plus sign then the string value variable this will include the value stored in string value into our log statement this is how you log values of variables which is very useful when examining your app when trying to fix some kind of logical error in your source code that is producing incorrect output being able to look at a sequential log of log statements and the values that variables stored in time helps you build a better mental image of the runtime behavior of your app now let us run the app and examine how you do the filtering I was mentioning previously I have an emulator running in the background and I will launch the app on that emulator this will open up the android monitor window and display the log cat tab which is what we want we will click and drag this window up to give some more screen space for it to use now I will bring the emulator to the front and it is currently running I will press the button and the text will change we will go back to android studio editor and look at the log cat window you will see that new lines appeared in the log cat editor these relate to the log cat statements within our application if we look at the top and towards the center of the android monitor we will see what the current log level is set to for the filter currently it is set to verbose this means that all log statements are being shown this statement right here has a V at the beginning of it indicating that it is a verbose statement so if we select debug in the filter selection that statement will disappear the same is also true if we select info then the debug statements will disappear this pattern continues if we select warning then only warning and above are shown if we select error then no statements are shown because there are no error statements the last thing we will discuss in this video is the search bar next to the log level this allows you to search for particular text strings in log statements this is useful when you know what log statement in particular you are looking for the value of and can then search for that as an example let us enter the word changed and we will only show the log statement showing the value that the text was changed to you can narrow the search down to a particular class by entering that file's name if its log tag is set to the class name so for example main activity you can easily find all the main activity log statements that way I will now go back to the emulator and click the button a couple of times to show you another property of viewing logs within logcat that you should be made aware of you will now notice that all the logs are in order and that there is no clear separation visually between different button presses and for that matter the same would be true for you running your app multiple times the logs would just run together visually which is why it is a good idea to put log statements in the beginning of key methods so that you can identify when new executions of that part of your application have started so for example when you put in button pressed called indicating that a new button press started then hi and now that you have completed this video you should understand how log statements are written and how to write your own you should understand what log levels are and the impact they have on filtering you should be able to use logcat to read the log from a device and even how to filter the output and you should understand how the practices of consistent logging especially the beginning of key parts of your app can help make reading logs easier and more efficient welcome to the next video in this lesson where you will learn how to use a special set of comments called to do statements to do statements also called to do comments exist to help a programmer create a list of tasks that require additional attention this is useful in maintaining projects especially when the project size grows beyond a small simple app or when multiple people are working on the same project these to do comments exist to allow developers to leave easily traceable and findable comments within the source code that indicate further action is required in that location an example of this would be a developer leaving a message for themselves possibly others that they need to improve a section of code at some point in the future or check to see if there might be a more efficient way to accomplish what they have just wrote and have working in this course we will make use of to do comments within your assignments to indicate where you will need to complete the required code after completing this video you'll understand how to both use the special comments called to do statements to find the places within a program that require additional attention in future assignments we will make use of a feature of the android studio IDE called to do statements to do statements are comments that start with the word to do these comments are special because there is built in functionality into android studio that allows us to quickly find all the to do statements in our code to demonstrate this functionality I will create a to do comment here in the custom logic class then I will close this file and create a to do statement in the main activity class then I will close that file this example might seem simple because I only have two classes but if I had a project with hundreds of Java files it would be quite time consuming to search each file to see if it has a to do comment thankfully the IDE has a tool to help us at the bottom of the IDE there is a tab called to do if you click it it will list each to do statement within your project it will tell you how many to do items exist and in how many separate files in my case there are two to do statements in two files clicking the arrows will expand the view so that you can see more information the file name will be given and then each to do statement in that file will be listed the first number is on what line number the to do statement is so for example custom logic to do statement is on line number five if you double click a to do item listed here you can use this code file and take you to that to do statement it will do that for every to do statement you have listed here now I said line number and that can be important line numbers are used in lots of debugging methods within android studio and programming in general to view line numbers right click in the left hand window here of the editor and click on show line this I personally recommend you always leave it on now that you've completed this video you should understand how to enable line numbers within the editor and how to create to do comments along with how to use the to do window to quickly open and jump to existing to do statements visible line numbers along with to do statements will assist you in maintaining and improving the code within your projects these tools along with the tools from the previous video will by no means solve every bug you face while programming but they should help you to quickly identify and hopefully narrow down many potential bugs quicker and more efficiently in this video we are going to demonstrate how you can run your code to see that if it's working or not what we have provided we have provided three different ways for you to run and execute your code to verify that it works the first way is to actually run it in at the provided app to do that you would select app from the configuration drop down menu this menu right here just select app that you want to run the app next you need to select an AVD an android virtual device that can run on your machine this AVD needs to be running API 29 if you have not installed an AVD on your computer you can do so with the AVD manager again you can you should select any AVD that works on your machine you should probably select an ABI that is correct for your architecture particularly an x86 and for this course now you need to install API 29 so here I have some devices I have some API 22s and I have an API 29 device I actually have the API 29 device already running so here we can see my android virtual devices already running on my computer I started before this demonstration so we wouldn't have to wait for it to start up so again we select app we select our virtual device I already have my virtual device running and then we select the run button the run button will then compile your code and then install it onto the AVD for it to be run so we can click back over here to my AVD and we can see our app is now running on the android virtual device so here we see that we have input windows for a length, width, height and radius and we have a drop down menu here that we can select rectangle, box, circle, sphere or triangle so let's go ahead and select the rectangle since that was the default and we then press the process button and we see here the output that is produced by our code so a 10 by 10 rectangle has a perimeter of 40 and an area of 100 so we see that our perimeter method returned the value 40 and our area method returned the value 100 so it's similar we could select that we want to do the sphere and again press the process button again for now a radius 10 a sphere with a radius 10 has a volume of this value here 4 to 188 a sphere with a radius 10 has a surface area of this value a circle with a radius of 10 has a perimeter of this value and a circle with a radius 10 has an area of this value so we have and we can go in and we can change our values here let's go actually go in and change our radius from 10 to 150 and then press the process button we have to remove our keyboard and we can see the values for sphere volume, sphere area circle perimeter and circle area when our radius is 150 so we can actually go in and experiment and see if our values are getting if our code is producing the right values alright so that's one way to do it again here in android studio we select app we select an avd and then we press the run button another way that you can test your code is by running what we have what we call our unit tests these are tests that we have provided for you that actually do a very thorough job of testing your code to run the unit test we need to make sure that over here in the project when we're looking at the android view of the project so here again under this drop down menu you select that you want the project view or the packages view or the down at the bottom the android view we want to make sure that we select the android view for our project under that we have the app then under the app we have java under java we have two folders one is the shapes folder that's where our code actually is so we go under here we see logic and then logic.java there's our class that we are writing our code in okay this is at this file right here logic.java right here this file here is logic.java that we're editing right otherwise this other folder that says tests over here is our unit tests and all we do to run them all we have to do is right click on them we want to run the tests right click on the test folder we want to run the tests when we do that a run window will open up down here at the bottom and all the unit tests will be run so here we can see that expand this out we can see all these tests we can see this one failed we just got a green check mark now the green check mark just means that the test ran does not mean that the test ran successfully here at the test circle area it did not run correctly and it failed during its run right and that's because I introduced a bug in it so when we click on that one we can see over here that there was an assertion error while that test was running and that's because the test detected this value but my code actually produced this value and because of that that test stopped it had an exception and stopped so that's what that check mark excuse me not to check the X means the X means that this test did not run now the other test did run to completion but we don't know if they actually completed successfully or not to do that we need to scroll up here and check on the greater preview click on this and then we can take a look at here so this says our assignment has not been submitted our estimated score is 90 out of 100 again because in this case I introduced a slight error in my calculation of a circle area so my code is not correct for circle area and then we can scroll down here we see your solution received points for the following rubrics and we see oh hey our test of this circle circumference was correct we got 10 out of 10 testing of the box surface area was correct we got 10 out of 10 and we can keep scrolling down see all the tests that we passed and then down the bottom our solution missed points for these items ah test circle area we got 0 out of 10 right so there's a problem with our computation of a circle area again when I wrote that code I introduced a slight error again we can click on this test to get some information here hey this is the value that was expected and this is the value that I produced again they're not equal so again that is running the unit tests the third way that we have provided for you to test your code is with a gradle task to do that we need to come over here to the very far right and open up the gradle window click on the gradle over here on the far right under gradle window we have M3 shapes that's the assignment that we're working on the project we're working on underneath that there's tasks we'll open up that underneath that there's Coursera tools right so these are some tools that we have provided for you we're going to expand that and we will see that there are three tasks under here under the gradle Coursera tools the first one is grader preview all we need to do is double click on this and we will actually see what will happen when we submit our code to the auto grader on the Coursera servers so if we actually want to see what's going to happen when we submit our code for grading we just need to double click on grader preview so we double click on that we see down here on the bottom on the run window a lot of things are happening and then our test run in this window here you need to scroll up and scroll all the way up to the top and we see a bunch of messages of what's going on and then we see here hey there Simon's not been submitted this is just an estimate your estimated score is 90 out of 100 again we still have that error in calculating the circle area and then we again we see all the things we passed all the things we got right we see all those and we scroll down and again we see what we missed right and then we miss the computation of the circle area is incorrect again this is the feedback that you will get from the auto grader on the Coursera service the auto grader will not tell you what values were expected on what values you produced it will just tell you whether the things were right or wrong again if you want to know what was expected and what you got wrong you will need to run the unit test locally on your computer alright so there's again there's three ways that you can run the configuration drop down menu and select app and then select an android virtual device an avd and then hit the run button and actually run your code on an android device you can do the unit test right click on unit test over here and select that you want to run them or you can come over here to the grader window and specify under Coursera tools that you want to view the grader preview double click on that it will execute your code and give you the output that you will actually see or receive when you submit your code to the auto grader so three ways to run your test three ways of exercising your code and to see if your code is correct or not in this video we will show you how to submit your code for grading to the Coursera servers this is something that we've done some work to make this very easy for you so here we have an example of the first assignment that you will be completing we've run our unit test here we still fail the test circle area we haven't fixed our error yet but we want to submit anything anyway so up here under the gradle tab under the gradle tab Coursera tools M3 shapes, tasks, Coursera tools there is an option for submit for grading right and we will double click on this when we do that that will do a couple things it will actually execute this zip submission which will create a zip file for us that we need to submit and then this will also open up the webpage where you need to submit that zip file so let's do this, double click on submit for grading and we see a bunch of stuff going on and boom, our browser pops up and takes us to the page where we need to submit this solution to so here we are we are doing the geometry calculations again and this is now where we see here in my submissions tab and at this point time we can create a submission we see down below here that I have prior submissions but now we go ahead and do a click create submission and then here this is where you would add if this is the first time you would add your file at this point time for me I have already submitted so I would have to do a replace file but now to find the file that you need to submit you will submit a zip file let's go back to android studio and find out where that zip file got created again when we do this submit for grading it automatically does this zip submission which creates the zip file for you to find that zip file we are going to go over here to the left and we are going to change our view from the android view to the project view so again from this drop down menu here I am going to select project and then we will see here that there is a great little app all these things and then there is a zip folder and then behind that zip folder is submission.zip this is the file that you will submit for grading and so there is different ways to do that we can actually drag and drop this file onto our browser to submit the file or we can click here and like if I say replace file I will go here and then I will find that file here is the submission zip file right here if you do it this way this will always take you back to the most recent it will assume that you want to resubmit something from what you have done before so you need to make sure that you are always submitting from the latest one so I recommend to go back to your desktop and then go into the right folder whether it is m3 shapes or m4 diamond whatever you want to go in there and then find the zip folder and then find your zip file that you want to submit so here it is going to replace the file we can select our zip file again once you do that once it is uploaded you have to hit the submit button so if you upload it it is not submitted until you hit the submit button so don't forget to hit that submit button once you do that they will do some work let's go ahead and submit after we hit submit it is going to make sure that we have done our own work so that we understand the honor code and that the work that we are submitting is our own and we are going to continue and then we will get this little message here that your submission is being graded and this page will update automatically when it happens while we are doing that we will take a look at this prior submission that I did again I got scored out of 90 out of 100 why did I get so I can show the greater output and the greater output here is here I passed all these tests right down here at the bottom I am still failing the test circle area because I still have that bug but again we can see our output we can see what grade we score we can see the greater output the greater output here doesn't give us as much information as running the unit tests in android studio so always make sure that you run the unit test in android studio first before you submit to the auto grader in android studio to submit you can just double click on submit for grading in the gradle task under coursera tools coursera tools submit for grading double click on that that will create the zip file for you and it will pop open the correct page where you want to submit that zip file and then again we can just come over here make sure we look at our project view we will see the zip file and then that is the zip file we want to drag and drop when we are done and we have already submitted our file we want to go back to our android view of our project we will also want to come over here if we want to run the app we have to select the app from the configuration drop down menu that will get us back to where we were prior to doing our submission but again when we are done with our code and we are ready to submit it to the auto grader so we actually get a grade again go to the gradle window the gradle pane here and under task coursera tools double click on submit for grading that will create the zip file for you it will create a new zip file for you and it will open up the web page to where you want to submit that zip file and it is that easy good luck welcome to the end of this module which covered a range of topics related to the android studio integrated development environment now that you have completed the lessons in this module you should know how to install both the java development kit and android studio you should also be able to create and import projects into android studio as well as have learned its major windows and tools and know how to use them likewise you should understand how the files within an android project are organized and how to create and edit them in addition you should know how to manage create and run android virtual devices as well as how to run your apps on them finally you should have learned some basic debugging techniques for both syntax and logical errors in your apps understanding the material covered by the lessons in this module will become more important to us through this MOOC and beyond in particular knowledge of android studio will provide the foundation for other MOOCs in this specialization as well as enhance your ever growing knowledge and experience in developing java for android apps welcome to our next module in our MOOC on java for android programming which begins our introduction to computer programming java programming language in particular since this MOOC does not have any prerequisites we expect learners will come from a wide variety of backgrounds there will be some learners in this MOOC who have no prior programming experience while other learners may already know java and simply want to learn about programming java for the android platform since some learners have no prior experience however the first several lessons of this module will start with the very basics of computer programming while later lessons focus specifically on the java programming language the topics covered in this module lay the foundation for all future modules of this MOOC after completing the lessons in this module you will recognize key programming concepts and terminology you will also be familiar with the concepts of data types variables, assignment tasks in addition, you will understand key aspects of printing, mathematical functions and string processing finally, you will know how to define your own methods that can be reused to perform work for your apps depending upon your prior programming experience some of the lessons in this module may be a review for you so feel free to move through it quickly if you already know this material welcome to the next lesson where we provide some background on the computing system components needed to employ the java programming language to develop android apps after completing this lesson you will be able to identify the main components of a computing system and differentiate hardware components from software components you will also recognize some basics of how the hardware works since that knowledge is necessary to understand how the software works which in turn is necessary for your apps finally, you will understand the purpose of high level programming languages and the role of the compiler and virtual machine in creating and executing java programs you can probably speed through this lesson if you have prior programming experience to start things off let's define what a computer is a computer regardless of whether it is a desktop computer or a mobile phone is a device which can execute a program or what we call an algorithm and an algorithm is simply a precise, unambiguous, step by step process for completing a task note that all three of those attributes are extremely important a computer which is a marvel of engineering is by itself a very stupid device it can only do what humans tell it to do and when we tell it to do something we have to do it in a very precise, unambiguous step by step manner I like to make the analogy that programming is like creating a recipe that we've never baked before we've all seen the TV sitcom where the little kids are in the kitchen attempting to cook something without any help from adults and when the recipe says to add two eggs the kids simply drop two whole eggs shells and all into the bowl programming a computer is similar as the computer cannot know what you intend rather it only does exactly what you say now a computer system is made up of hardware and software that you can see and touch where the software is all the programs that run on the hardware even though this class is about creating software knowing some of the basics of the hardware helps us to understand how some things work and why we must do some things in a specific way the main component of a computer system is the central processing unit or CPU this is the chip that forms the brains of the computer it has two main components which are the ALU which does all the mathematical and logic computations and the control unit that really directs what happens there is also the memory where the programs and data are stored there are different types of memory including RAM or random access memory ROM which is read only memory and high speed cache and then there are the input devices that allow users to put information into the computer and output devices and now the computer to provide information back to the user now the main RAM memory of the computer stores the program that is running in any data that is used by that program in current computing devices this memory is usually measured in gigabytes where a gigabyte is a billion bytes so then the next question is what is a byte after all well inside the computer all information is stored by electrical charges the charges can be present or absent or on or off and each of these charges is called a bit and for ease of discussion we say it is either a one or a zero since a single bit by itself can only represent two values one and zero we group them into sets of eight and call that a byte the computer is able to access byte size chunks of information in memory by an address every byte has a unique address now all information that we store in the computer, regardless of what it represents is encoded as ones and zeros and since a byte which is eight bits can only represent 256 different values we usually have to group bytes together so that they can represent even larger sets of values for example to represent an integer in the computer we usually group four bytes together which allows us to represent over four billion different values now that we've covered some of the basics of computer hardware let's consider computer software since that is the focus of this class again software is simply the set of instructions that we want the computer to execute everything that is running on the computer is considered software all the way from the operating system that controls how the computer operates down to the games that you play on the computer now when we create these sets of instructions for the computer to execute we cannot use English which is neither precise or unambiguous which are two of the required properties of algorithms that we discussed earlier so we need to create special languages and thus programming languages are invented a programming language allows us to specify our algorithm or what we want the computer to do in such a way that the computer can understand it and actually do it for Android programming we use the Java programming language now Java programming languages such as C++ Python and Ruby are considered high level languages since they are easy for humans to understand but unfortunately computers do not understand such languages since they only understand ones and zeros thus we need a way to transform a program written in a high level language down into the ones and zeros that the computer understands to do that we use a program that is known as a compiler the compiler takes your high level program known as the source code and converts it into object code or the ones and zeros that the computer understands this object code is platform specific and thus the object code created for a Windows machine will not run on a Mac or an Android device now Java is a bit different in that its compiler does not produce object code that only runs on a particular computer instead the Java compiler produces what is known as a byte code which is object code for a hypothetical computer or what we call a virtual machine this byte code is a low level code that can run on any computer that has a piece of software known as the Java virtual machine or JVM this allows the same byte code to be executed on any computer regardless of what operating system it is running this lesson gave you an overview of the components of a computing system and concepts of hardware and software now that you have completed this lesson you should be able to identify the main components of a computer system recognize the basics of how computer hardware and software works and understand the purpose of using a high level programming language to create apps as well as understand the role of the Java compiler and the Java virtual machine in creating and executing Java programs welcome to the next lesson in our module on basic Java features for developing Android apps which introduces you to the concept of variables and types after completing this lesson you will recognize the important role that variables play in computer programming you will also learn the rules for Java identifiers that we use to give names to various entities in our programs moreover you will understand the concept of the data type and why it is important for us to specify the types of values in our programs to give a new value to a variable as with the previous lesson you can probably speed through this lesson if you have prior programming experience in a language similar to Java to motivate this discussion let's first answer the question of why do we need variables let's say we want to create a calculator app it would be very easy to create an app that adds 2 plus 2 but users of a calculator app want to do more than just add 2 plus 2 they may also want to add 3 and 21 or maybe they want to perform subtraction instead of addition or multiplication or division such an app is doing the same thing performing a calculation between two numbers but the numbers and the type of calculation may vary thus our app needs things called variables to hold these things that may vary variables allow our program to store information such as numbers and letters and the information is stored in the computer's memory we call the stored information the variables value and the key property of a variable is that it can be given different values while the program is running every variable has two key attributes a name and a type we'll consider these one at a time starting with the name in Java an identifier is a name that we give to a variable we also use identifiers to give names to other things we will see later such as methods and classes Java requires that identifiers be constructed from a sequence of characters containing only letters digits and the underscore character and they cannot start with a digit these restrictions mean that you cannot use characters that are allowed in naming files on your computer such as the space character or a dot or a hyphen and Java identifiers are case sensitive and thus a lower case stuff and a capitalized stuff and an uppercase stuff are all different identifiers and Java allows you to create identifiers that contain as many characters as you want but some identifiers have special meaning to the Java language we call these reserved words and thus you are not allowed to use them as identifiers in your program we will make note of these reserved words as we encounter them as this class progresses we as Java programmers follow some conventions as we create the names in our programs these are just common conventions that are not hard and fast rules that the Java language enforces the first convention is that names given to variables and methods will begin with a lower case letter if the name contains multiple words we use capital letters to highlight the other words we call this camel case since there are humps in the middle of the identifier the next convention is that the names given to classes begin with a capital letter and finally, good style says that the names we use should be descriptive of what is being stored or performed so again a variable has a name and a type now that we know about names let's move on to types recall that everything in a computer is represented by a sequence of 1's and 0's and thus we need to tell the computer to have a sequence of 1's and 0's so that it knows that this sequence represents a number while this other sequence represents a word so a type defines how to interpret a sequence of 1's and 0's as data and also defines what operations are valid for that data value Java has several types that are called primitive types since they are built into the actual computer hardware there are four types that can be used to hold whole numbers we refer to as integer types most often we will simply use the type int then there are two types that can be used to hold floating point numbers of which we will most often use the type double there is one type for holding a single character and that is the type char you may hear people pronounce it as type care since it is short for character but I've always pronounced it as the type char and the last primitive type is boolean which can hold a single true false value any type that is not primitive type will be an object type and we will see those later here is a slide showing the different primitive types in Java and how many bytes are used to store them and what range of values they can represent as you can see the int type uses four bytes and can represent integer values from slightly lower than negative 2 billion to slightly higher than positive 2 billion and here are some examples of values of these different types integer values will always be whole numbers while floating point values will have fractional parts note that negative 22.0 is a floating point value since the presence of the decimal point tells the compiler to represent this number as a floating point value rather than an integer value and they have very different representations as a sequence of ones and zeros character values are always a single character and use a single quote mark around that character and finally boolean values are either true or false now that we know about names and types we can combine the two to declare variables to declare a variable you need to specify both the type and the name the type appears first and then you specify the name you want to give the variable in this case we are declaring that we want to have a variable named number of rings that will be if type int java requires that we declare a variable before we can use it and it is important to remember to use descriptive names since we want other programmers to be able to read and understand our programs more formally the syntax to declare variables is to specify the type desired and then follow the type with a comma separated list of identifiers that we want to have that type and the list is terminated with a semicolon here are some examples from the circus we see we have two variables number of rings in attendance whose purpose is fairly clear from their descriptive names since the number of rings in the circus and the number of people in attendance are whole numbers we have declared these variables to be if type int we also have variables to keep track of the diameter of the ring and the weight of the lion since those values may have fractional parts we have declared them to be if type double and finally we have a variable to keep track of whether the lion has been fed or not which might be very important information for the lion tamer it is declared to be type boolean since it has a simple yes no or true false value we learned earlier that a variable must be declared before it can be used there are two standard places where we declare variables we either declare a variable just before it is used the first time or we declare at the beginning of the section of code that uses it that is at the section of code enclosed in curly braces you will see plenty of examples as you go through the rest of this course now that we can declare variables we want to give them values to do that we use an assignment statement the assignment statement gives or assigns a new value to a variable for those of you who are familiar with the novel the hitchhiker's guide to the galaxy may understand why we are assigning the value 42 to the variable named answer in this context the equal sign is called the assignment operator and it has a different meaning than the equal sign that we use in algebra the syntax of the assignment statement places the variable on the left followed by the assignment operator and then finally an expression that produces the value you wish to assign to the variable we will learn more about expressions in a moment note that the variable to be given a new value is always on the left of the assignment operator the expression is on the right some simple examples include assigning the value 4 to the variable num of stacks or assigning the value of the character q to the variable top card or assigning the value 10 times the value of the cards played to the variable score note that in evaluating the assignment statement the expression on the right of the assignment operator is evaluated first to produce a value and then that value is assigned to the variable on the left of the assignment operator in this example we first evaluate the expression on the right by getting the current value of cards in hand which is the value 8 and then subtracting 1 from it this new value 7 is then assigned to change the variable card in hands this is an example that the equal sign does not mean mathematical equality as this statement does not make any sense in mathematics it can be used in expressions and it can be given new different values in this example we see that the variable x is assigned the value 3 is then used in several expressions and then is assigned a new value that it will hold until it is possibly changed again this lesson gave you an overview of variables and types now that you have completed this lesson you should recognize the important role of variables as well as learn the rules you must follow to understand what a variable is you should also understand what a data type is and know the primitive types that are built into the Java language finally you should know how to use an assignment statement to give a new value to a variable welcome to the next lesson in our module on basic Java features for developing Android apps which introduces you to the concept of Java expressions that can produce values after completing this lesson you will understand Java's arithmetic operators and its interesting behavior you will also know how some of Java's specialized assignment statements allow short hand notation for common assignment operations that occur frequently in practice finally you will learn the concept of type compatibility in Java and its relationship to assigning values to variables as well as recognize how type casting can allow you to selectively modify Java's default assignment behavior next we will explore the expressions on the right hand side of an assignment operation an expression is simply a value or operation that produces a value the simplest expression is a little value which simply produces it itself or complex expressions can be created using operators and parentheses just as in mathematics arithmetic expressions can be created using the standard set of mathematical operators for addition subtraction, multiplication, and division there is a fifth operator the percent sign that is the mod operator but before we discuss the mod operator let's briefly talk about the division operator now division works as one would expect if one of the operands is a floating point value and in that case you get a floating point result but when both operands are integers you get integer division which produces an integer result the integer result is truncated and not rounded so if you divide the integer 14 by the integer 4 the result is the integer 3 if you did not want integer division you would have to make one of the operands a floating point value and that could be accomplished by simply adding a point zero to the little value now the mod operator can be used to produce the remainder that occurs after integer division so when we divided 14 by 4 the answer was 3 but there was a remainder of 2 that was lost the mod operator allows us to get that remainder and thus 14 mod 4 produces the value 2 students new to programming often wonder what such an operator is good for but it is interesting just how many applications it has in computer programming it can be used to easily determine if an integer is even or odd we can determine that by doing mod division by 2 and seeing if the result is zero meaning that the number was even or 1 meaning that the number was odd when creating expressions you can use parentheses just as you do in mathematics to force a specific order of operations in the examples shown we can use parentheses to force the addition to occur before the multiplication or to force the multiplication to occur before the addition without parentheses we will use the standard rule of precedence to determine the order of operations in evaluating an expression the rule of precedence are similar to mathematics where our unary operations have highest precedence followed by the multiplicative operators which are then followed by our additive operators when binary operators have equal precedence they are evaluated left to right in this example we see that the leftmost addition will occur first followed by the subtraction operator and then finally the rightmost addition will occur last when unary operators have equal precedence they are evaluated right to left when the operands of an operator are mixed ints and doubles the result will be a double value the compiler will automatically convert the integer value into a floating point value so that floating point arithmetic will be used so if we multiply 4.2 by 3 the integer 3 is converted to a floating point 3.0 for the multiplication and the result is a floating point 12.6 now this conversion is done per operator affecting only its operands so given the displayed expression the first operation to be performed is the leftmost division operation since both of its operands are integer values we get integer division and the integer value 2 is produced the next operation to be performed is the multiplication since its operands are mixed the value 2 will be converted to 2.0 and the multiplication produces a value 2.4 the next operation is the rightmost division operation again since both of its operands its operands are integers, we get integer division and the result is the integer value 1. Finally, the addition is performed to produce the value 3.4. Because programmers perform certain operations again and again, Java provides several specialized assignment operations that ease the writing of code. In particular, Java allows the assignment operators to be combined with arithmetic operators so that it becomes easier to update a variable. For example, we often want to update a variable by adding or subtracting a value from the variable. In this example, we want to update the variable time by adding 10 to it. This can be done more compactly using the plus equal operator that performs addition and assignment in one step. This can be done with all five mathematical operators. Note that the expression on the right hand side of the specialized operator is fully evaluated before the specialized operator is performed. This is important if the expression on the right hand side has lower precedence operators than the specialized operator. Another common operation is to increment or decrement a variable by 1 and Java provides special operators for this. The plus plus operator is the increment operator and it will increase the value of a variable by 1. Similarly, the decrement operator is minus minus which decreases a variable by 1. These operators are easy to use and they are important to recognize when you read code written by others. So if you ever need to increment a variable, there are several ways to do so and you are free to choose any of them. One is not necessarily preferred over the other as in the end the same code will be executed. Similarly, there are several ways to decrement a variable and you can use anyone you wish. But before we move on, let's talk a bit more about the increment and decrement operators. Besides incrementing or decrementing a variable, these operators also return a value. In the case of pre-increment where the plus plus operator precedes the variable being incremented, not only is the variable incremented but the new value is returned as the result of the expression. In the case of post increment where the plus plus operator follows the variable being incremented, not only is the variable incremented but the original value of the variable is returned as a result of the expression. In most cases we are only using these operators to increment a variable and we ignore the return value in which case you can use either pre-increment or post increment. Returning to the topic of declaring variables, a variable is said to be uninitialized if it has been declared but not yet assigned a value. In Java, the compiler will not allow you to use a variable that has not been initialized. So it is good programming practice to give a variable a value when it is declared. This