# Table of Contents - [Initial page | CISC 349](#initial-page-cisc-349) - [GitHub Instructions | CISC 349](#github-instructions-cisc-349) - [Introduction to Java programming | CISC 349](#introduction-to-java-programming-cisc-349) - [Your First Android Application | CISC 349](#your-first-android-application-cisc-349) - [Android and Model-View-Controller | CISC 349](#android-and-model-view-controller-cisc-349) - [The Activity Lifecycle | CISC 349](#the-activity-lifecycle-cisc-349) - [Your Second Activity | CISC 349](#your-second-activity-cisc-349) - [List View | CISC 349](#list-view-cisc-349) - [Custom ArrayAdapter | CISC 349](#custom-arrayadapter-cisc-349) - [Network Image View | CISC 349](#network-image-view-cisc-349) - [Networking HTTP | CISC 349](#networking-http-cisc-349) - [Code of Ethics | CISC 349](#code-of-ethics-cisc-349) - [Flask | CISC 349](#flask-cisc-349) - [MongoDB Code | CISC 349](#mongodb-code-cisc-349) - [ASSIGNMENTS | CISC 349](#assignments-cisc-349) - [Fragments | CISC 349](#fragments-cisc-349) - [Java Introductory Exercise | CISC 349](#java-introductory-exercise-cisc-349) - [Bottom Navigation Bar in Android | CISC 349](#bottom-navigation-bar-in-android-cisc-349) - [Upload Images to Server | CISC 349](#upload-images-to-server-cisc-349) - [Programming Project 02: Dynamic List View | CISC 349](#programming-project-02-dynamic-list-view-cisc-349) - [Programming Project 03: HUstagram | CISC 349](#programming-project-03-hustagram-cisc-349) - [Programming Project 04: Machine Learning with TFLite | CISC 349](#programming-project-04-machine-learning-with-tflite-cisc-349) - [Programming Project 01: Calculator | CISC 349](#programming-project-01-calculator-cisc-349) - [Project Proposal | CISC 349](#project-proposal-cisc-349) - [Your First Android Application | CISC 349](#your-first-android-application-cisc-349) - [Introduction to Java programming | CISC 349](#introduction-to-java-programming-cisc-349) - [Programming Project 01: Calculator | CISC 349](#programming-project-01-calculator-cisc-349) - [Project Proposal | CISC 349](#project-proposal-cisc-349) --- # Initial page | CISC 349 [NextGitHub Instructions](https://developer-mina.gitbook.io/cisc-349/github-instructions) Last updated 4 years ago Was this helpful? --- # GitHub Instructions | CISC 349 [](https://developer-mina.gitbook.io/cisc-349/github-instructions#work-submission) Work Submission ------------------------------------------------------------------------------------------------------- In this course, you will be using [https://github.com/](https://github.com/) to submit your code, your repository should be private, make sure to add me as a contributor so I can check your work, you will find me on Github under this email: `phil@insufficient-light.com`, you will be asked to submit a link to your repository on CANVAS. To add a contributor you need to go to settings →\\rightarrow→ Manage Access →\\rightarrow→Invite a collaborator your repository should be called: Copy {your first name}_{your last name}_CISC349 The repository folder structure should look like this: Copy John_Smith_CISC349/ ├─ exercises/ │ ├─ exercises_00 │ ├─ exercises_01 │ ├─ exercises_02 │ ├─ exercises_ ... │ ├─ exercises_n ├─ projects/ │ ├─ project_01 │ ├─ project_02 │ ├─ project_03 │ ├─ project_04 ├─ assignments/ │ ├─ assignment_01 │ ├─ assignment_02 │ ├─ assignment_03 │ ├─ assignment_04 ├─ final_project Copy │ ├─ exercises_00 ( put any java code for testing) you will need to use 4 simple commands: clone your repository Copy > git clone {link} add new files and folder Copy > git add . commit your changes Copy > git commit -m "{message}" push your changes to Github Copy > git push > **If you add, commit and push your assignment to GitHub after the due date and time posted in CANVAS you will be graded according to the late policy in the syllabus.** **in canvas, you need to submit your repository link, you can find the link here:** ![](https://developer-mina.gitbook.io/cisc-349/~gitbook/image?url=https%3A%2F%2F2651897257-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-MQn09wCCuaTvN4Loe8S%252Fuploads%252FTjKw3p45J5gRNDUheJul%252Fimage.png%3Falt%3Dmedia%26token%3D94866a48-1c41-49d1-ab99-7353148a96e1&width=768&dpr=4&quality=100&sign=fa7b1eaf&sv=2) [PreviousInitial page](https://developer-mina.gitbook.io/cisc-349) [NextIntroduction to Java programming](https://developer-mina.gitbook.io/cisc-349/introduction-to-java/introduction-to-java-programming) Last updated 2 years ago Was this helpful? --- # Introduction to Java programming | CISC 349 [](https://developer-mina.gitbook.io/cisc-349/introduction-to-java/introduction-to-java-programming#ide) IDE ----------------------------------------------------------------------------------------------------------------- In this tutorial, I will use [https://repl.it/](https://repl.it/) as my IDE, and then we will move to Android Studio [](https://developer-mina.gitbook.io/cisc-349/introduction-to-java/introduction-to-java-programming#write-code) Write Code ------------------------------------------------------------------------------------------------------------------------------- when you create a new repl using the Java language you will see the following code: Copy class Main { public static void main(String[] args) { System.out.println("Hello world!"); } } run the previous code you should see "Hello world!" output on the right screen [](https://developer-mina.gitbook.io/cisc-349/introduction-to-java/introduction-to-java-programming#base-java-language-structure) Base Java language structure ------------------------------------------------------------------------------------------------------------------------------------------------------------------- ### [](https://developer-mina.gitbook.io/cisc-349/introduction-to-java/introduction-to-java-programming#class) Class A class is a template that describes the data and behavior associated with an instance of that class. A class is defined by the _class_ keyword and must start with a capital letter. The body of a class is surrounded by {}. Copy class MyClass { } The data associated with a class is stored in _variables_ the behavior associated with a class or object is implemented with _methods_. A class is contained in a text file with the same name as the class plus the `.java` extension. It is also possible to define inner classes, these are classes defined within another class, in this case, you do not need a separate file for this class. ### [](https://developer-mina.gitbook.io/cisc-349/introduction-to-java/introduction-to-java-programming#object) Object An object is an instance of a class. The object is the real element that has data and can perform actions. Each object is created based on the class definition. The class can be seen as the blueprint of an object, i.e., it describes how an object is created. ### [](https://developer-mina.gitbook.io/cisc-349/introduction-to-java/introduction-to-java-programming#inheritance) Inheritance A class can be derived from another class. In this case, this class is called a _subclass_. Another common phrase is that _a class extends another class._ Inheritance is an important pillar of OOP(Object Oriented Programming). It is the mechanism in java by which one class is allowed to inherit the features(fields and methods) of another class. **Important terminology:** * **Super Class:** The class whose features are inherited is known as a superclass(or a base class or a parent class). * **Sub Class:** The class that inherits the other class is known as a subclass(or a derived class, extended class, or child class). The subclass can add its own fields and methods in addition to the superclass fields and methods. * **Reusability:** Inheritance supports the concept of “reusability”, i.e. when we want to create a new class and there is already a class that includes some of the code that we want, we can derive our new class from the existing class. By doing this, we are reusing the fields and methods of the existing class. **Example:** In **the** below example of inheritance, class Bicycle is a base class, class MountainBike is a derived class that extends Bicycle class and class Test is a driver class to run the program. Copy //Java program to illustrate the // concept of inheritance // base class class Bicycle { // the Bicycle class has two fields public int gear; public int speed; // the Bicycle class has one constructor public Bicycle(int gear, int speed) { this.gear = gear; this.speed = speed; } // the Bicycle class has three methods public void applyBrake(int decrement) { speed -= decrement; } public void speedUp(int increment) { speed += increment; } // toString() method to print info of Bicycle public String toString() { return("No of gears are "+gear +"\n" + "speed of bicycle is "+speed); } } // derived class class MountainBike extends Bicycle { // the MountainBike subclass adds one more field public int seatHeight; // the MountainBike subclass has one constructor public MountainBike(int gear,int speed, int startHeight) { // invoking base-class(Bicycle) constructor super(gear, speed); seatHeight = startHeight; } // the MountainBike subclass adds one more method public void setHeight(int newValue) { seatHeight = newValue; } // overriding toString() method // of Bicycle to print more info @Override public String toString() { return (super.toString()+ "\nseat height is "+seatHeight); } } // driver class public class Test { public static void main(String args[]) { MountainBike mb = new MountainBike(3, 100, 25); System.out.println(mb.toString()); } } Copy No of gears are 3 speed of bicycle is 100 seat height is 25 **How to use inheritance in Java** The keyword used for inheritance is **extends** Copy class derived-class extends base-class { //methods and fields } **Types of Inheritance in Java** Below are the different types of inheritance which are supported by Java. **Single Inheritance:** In single inheritance, subclasses inherit the features of one superclass. Copy class one { public void print_geek() { System.out.println("Geeks"); } } class two extends one { public void print_for() { System.out.println("for"); } } // Driver class public class Main { public static void main(String[] args) { two g = new two(); g.print_geek(); g.print_for(); g.print_geek(); } } Copy Geeks for Geeks ### [](https://developer-mina.gitbook.io/cisc-349/introduction-to-java/introduction-to-java-programming#java_interfaces) Java interfaces #### [](https://developer-mina.gitbook.io/cisc-349/introduction-to-java/introduction-to-java-programming#javadef_interface) What is an interface in Java? An _interface_ is a type similar to a class and is defined via the `interface` keyword. Interfaces are used to define the common behavior of implementing classes. If two classes implement the same interface, other code that works on the interface level can use objects of both classes. Like a class an interface defines methods. Classes can implement one or several interfaces. A class that implements an interface must provide an implementation for all abstract methods defined in the interface. Copy public interface MyInterface { // constant definition String URL = "https://www.vogella.com/"; // public abstract methods void test(); void write(String s); // default method default String reserveString(String s){ return new StringBuilder(s).reverse().toString(); } } #### [](https://developer-mina.gitbook.io/cisc-349/introduction-to-java/introduction-to-java-programming#javadef_interfaceimplementing) Implementing Interfaces Copy public class MyClassImpl implements MyInterface { @Override public void test() { } @Override public void write(String s) { } public static void main(String[] args) { MyClassImpl impl = new MyClassImpl(); System.out.println(impl.reserveString("Lars Vogel")); } } #### [](https://developer-mina.gitbook.io/cisc-349/introduction-to-java/introduction-to-java-programming#reference) Reference: [![Logo](https://developer-mina.gitbook.io/cisc-349/~gitbook/image?url=https%3A%2F%2Fwww.geeksforgeeks.org%2Fwp-content%2Fuploads%2Fgfg_200X200.png&width=20&dpr=4&quality=100&sign=455da969&sv=2)Inheritance in Java - GeeksforGeeksGeeksforGeeks](https://www.geeksforgeeks.org/inheritance-in-java/) [![Logo](https://developer-mina.gitbook.io/cisc-349/~gitbook/image?url=https%3A%2F%2Fwww.vogella.com%2Ffavicon.ico&width=20&dpr=4&quality=100&sign=1dae8115&sv=2)Introduction to Java programming - Tutorialwww.vogella.com](https://www.vogella.com/tutorials/JavaIntroduction/article.html) [PreviousGitHub Instructions](https://developer-mina.gitbook.io/cisc-349/github-instructions) [NextYour First Android Application](https://developer-mina.gitbook.io/cisc-349/android-programming/your-first-android-application) Last updated 4 years ago Was this helpful? --- # Your First Android Application | CISC 349 The application you are going to create is called GeoQuiz. GeoQuiz tests the user’s knowledge of geography. The user presses TRUE or FALSE to answer the question on screen, and GeoQuiz provides instant feedback. ![](https://developer-mina.gitbook.io/cisc-349/~gitbook/image?url=https%3A%2F%2F2651897257-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-MQn09wCCuaTvN4Loe8S%252F-MQwvcotUlbDamiNdPvl%252F-MQwxOGRbXP4aG3OdMP5%252Fimage.png%3Falt%3Dmedia%26token%3D59c6bfc1-e360-459c-bd82-4dbde0da9bb2&width=768&dpr=4&quality=100&sign=9dbb9831&sv=2) [](https://developer-mina.gitbook.io/cisc-349/android-programming/your-first-android-application#app-basics) App Basics ---------------------------------------------------------------------------------------------------------------------------- Your GeoQuiz application will consist of an activity and a layout: * An activity is an instance of Activity, a class in the Android SDK. An activity is responsible for managing user interaction with a screen of information. * A layout defines a set of UI objects and their positions on the screen. A layout is made up of definitions written in XML. The relationship between QuizActivity and activity\_quiz.xml is diagrammed in the figure below ![](https://developer-mina.gitbook.io/cisc-349/~gitbook/image?url=https%3A%2F%2F2651897257-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-MQn09wCCuaTvN4Loe8S%252F-MQwvcotUlbDamiNdPvl%252F-MQwxvhnQDlLtnOaUI6V%252Fimage.png%3Falt%3Dmedia%26token%3D474a9955-eaf0-41cb-81b5-865a064b1389&width=768&dpr=4&quality=100&sign=f4f4e718&sv=2) [](https://developer-mina.gitbook.io/cisc-349/android-programming/your-first-android-application#creating-an-android-project) Creating an Android Project -------------------------------------------------------------------------------------------------------------------------------------------------------------- The first step is to create an Android project. An Android project contains the files that make up an application. To create a new project, first open Android Studio. ![](https://developer-mina.gitbook.io/cisc-349/~gitbook/image?url=https%3A%2F%2F2651897257-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-MQn09wCCuaTvN4Loe8S%252F-MQwvcotUlbDamiNdPvl%252F-MQwy6XHf4xnZBLrQ4Gr%252Fimage.png%3Falt%3Dmedia%26token%3D23dfbcfe-c18f-46f5-9025-e197d31ad8c4&width=768&dpr=4&quality=100&sign=2c1b50ff&sv=2) Creating a new application ![](https://developer-mina.gitbook.io/cisc-349/~gitbook/image?url=https%3A%2F%2F2651897257-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-MQn09wCCuaTvN4Loe8S%252F-MQwvcotUlbDamiNdPvl%252F-MQwyGGF1gwwwZ5azTly%252Fimage.png%3Falt%3Dmedia%26token%3D903d6829-8b20-416e-9060-efd08f0c5fe8&width=768&dpr=4&quality=100&sign=b21b8f73&sv=2) Specifying device support ![](https://developer-mina.gitbook.io/cisc-349/~gitbook/image?url=https%3A%2F%2F2651897257-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-MQn09wCCuaTvN4Loe8S%252F-MQwvcotUlbDamiNdPvl%252F-MQwyO0gjPdJGP9lbVMh%252Fimage.png%3Falt%3Dmedia%26token%3Deac8357b-3296-4374-a145-c0bdbe8a942f&width=768&dpr=4&quality=100&sign=b3952443&sv=2) Choosing a type of activity _If your wizard looks very different, then the tools have changed more drastically. Do not panic._ ![](https://developer-mina.gitbook.io/cisc-349/~gitbook/image?url=https%3A%2F%2F2651897257-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-MQn09wCCuaTvN4Loe8S%252F-MQwvcotUlbDamiNdPvl%252F-MQwyWI_s5ncg-t9jfts%252Fimage.png%3Falt%3Dmedia%26token%3De3ee2586-ad09-4325-8e15-23717ff20421&width=768&dpr=4&quality=100&sign=78b97592&sv=2) [](https://developer-mina.gitbook.io/cisc-349/android-programming/your-first-android-application#navigating-in-android-studio) Navigating in Android Studio ---------------------------------------------------------------------------------------------------------------------------------------------------------------- The lefthand view is the project tool window. From here, you can view and manage the files associated with your project. ![](https://developer-mina.gitbook.io/cisc-349/~gitbook/image?url=https%3A%2F%2F2651897257-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-MQn09wCCuaTvN4Loe8S%252F-MQxBOgWe7K_tiliWa6C%252F-MQxEZXJczjPwCiRY3ag%252Fimage.png%3Falt%3Dmedia%26token%3D13b72820-e78c-4643-b77a-36fb7ef05c6d&width=768&dpr=4&quality=100&sign=baef4a16&sv=2) [](https://developer-mina.gitbook.io/cisc-349/android-programming/your-first-android-application#laying-out-the-ui) Laying Out the UI ------------------------------------------------------------------------------------------------------------------------------------------ Copy Widgets are the building blocks you use to compose a UI. A widget can show text or graphics, interact with the user, or arrange other widgets on the screen. Buttons, text input controls, and checkboxes are all types of widgets. The Android SDK includes many widgets that you can configure to get the appearance and behavior you want. Every widget is an instance of the View class or one of its subclasses (such as TextView or Button). But these are not the widgets you are looking for. The interface for QuizActivity requires five widgets: * a vertical LinearLayout * a TextView * a horizontal LinearLayout * two Buttons ![](https://developer-mina.gitbook.io/cisc-349/~gitbook/image?url=https%3A%2F%2F2651897257-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fassets%252F-MQn09wCCuaTvN4Loe8S%252F-MQxGU7pVoK668iJJ2J0%252F-MQxI7aPMmjMaQQrDb7o%252Fimage.png%3Falt%3Dmedia%26token%3D52a52be7-3e3b-485e-99ee-a53ad5c4e594&width=768&dpr=4&quality=100&sign=cbeeffe&sv=2) Copy