0% found this document useful (0 votes)
32 views31 pages

Sanjeev Jantwal 2271288MOOC File-Compressed-Compressed - EXTREME - Compressed

The document outlines a MOOC course on Android App Development using Java, detailing the history of Java, its significance in modern computing, and the steps to install necessary software like JDK and Android Studio. It explains the workflow of Java programs, the advantages of using Java for Android development, and provides instructions for creating and running Java projects within Android Studio. The content serves as an introductory guide for students in the BCA program at Graphic Era Hill University.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
32 views31 pages

Sanjeev Jantwal 2271288MOOC File-Compressed-Compressed - EXTREME - Compressed

The document outlines a MOOC course on Android App Development using Java, detailing the history of Java, its significance in modern computing, and the steps to install necessary software like JDK and Android Studio. It explains the workflow of Java programs, the advantages of using Java for Android development, and provides instructions for creating and running Java projects within Android Studio. The content serves as an introductory guide for students in the BCA program at Graphic Era Hill University.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
y Graphic Era DAIVveRelTy MOOC COURSE ANDROID APP DEVEKOPMENT USING JAVA Session2024-25 Submitted to: Submitted by: Devendra singh Sanjeev Jantwal Assistant Professor BCA Section c School of Computing Roll No: 2271288 Graphic Era Hill University Bhimtal Campus 11 First Step in JavaAND~404 The History of Java In the early 90s, extending the power of network computing to the activities of everyday life was a radical vision. In 1991, a smalll group of Sun Microsystems engineers called the "Green Team’ believed that the next wave in computing was the union of digital consumer devices and computers. Led by James Gosling, the team worked around the clock and created the programming language that would revolutionize our world ~ Java The Green Team demonstrated their new language with an interactive, handheld homeentertainment controller that was originally targeted at the digital cable television industry. Unfortunately, the concept was much too advanced for the team at the time. But it was just right for the Internet, which was just starting to take off. In 1995, the team announced that the Netscape Navigator Intemet browser would incorporate Java technology. Orac e Corporat on s the current owner of the offc a mp ementat on of the Java SE platform, following their acquisition of Sun Microsystems on January 27, 2010. This implementation is based on the original implementation of Java by Sun. Today, Java not only permeates the Intemet, but also is the invisible force behind many of the applications and devices that power our day-to-day lives. From mobile phones to handheld devices, games and navigation systems to ebusiness solutions, Java is everywhere. Java is, one of the most popular programming languages in use in the IT industry. To read mere information about Java history you can find them on Oracle web site on the following link: http://oracle.com edgesuite net/timeline/javar To find more detentions, practical examples and details about Java you may explore the Oracle web site through the following link: https://docs.oracle.com/javase/ tutorial/ How Java Programs work? Imagine you want to createa Microso't word file thal includes reports or any other contents, what's the first step you need to take? The answer is you will open the software that you will use to create this file, which means you will open the Microsoft word software, where this software will help you create this word document and anyone who wants to read this file also needs this Microsoft Word software to read the content of the file The same thing for Java, you need software to write or open the source code fie, this software is called Java Compiler or IDE (Integrated Development Environment). We have a lot of IDE software like Eclipse, NetBeans, Android Studio and others. They are called Javac. Here in this book, we will use Android Studio as the Java compiler, The Java source codes which were written in Android Studio (IDE) will be considered as 12 irst Step in JavaAND~404 project.claes files that have the ability to run and get results, where this class file will be moved to JRE (Java Runtime Environment). JRE in turn has a part called Class Loader , which is responsible for receiving the class file and executes it by the Execttion Engine part of the JRE. The following flow chert will display the work flow peth of any Java file from being written to run and produce the output. ntegited development envienment) Java Program Work Flow 13 First Step in JavaAND~404 The previous chart displays that there is a main part of creating and running Java program called JDK (Java Development Kit), this software includes the part, which is responsible to write and run the code and then send the result to the operating system Install Java JDK and JRE To start creating the Java program, we must install the Android Studio (IDE) and to install it, we need to install the prerequisites of it which are the JDK and JRE. You may down oad the JDK and JRE for free from the offc a webs te of Orac e, be ow s the download link: hitp://www.oracle.com/technetwork/java/javase/downloads/ ick8downloads-2133151.html Java SE Development Kit 7u79 ‘Youmust accept the Oracle Binary Code License Agreement for Java SE to download this Accept License Agreement‘ Decline License Agreement Product | Fie Description File Size Download Linux 88 1304NB _ jdi-7u70sInu588 rpm Linux 86 147.6NB _ }tk-7u70-inux-586 targz Linus «64 $3160 MB— jék-7070-Hinur«64 rpm Linux x64 {484 MB jfk 7479.inu 4 targe Mac 08 xx64 19680 j4i-7U79-macosi-x64 dmg ) $40.70MB _jek-7470-colans-1588 iar 96.56 MB jai 7470-s0lane Solan x64 (SVR package) 2467 NB jek-7u76-sola Solan: x64 1638NB — jdk-7079-solans-n64 coz Solaris SPARC (SVR4 pactage) 140MB___}4h-7u70-solare-eparctar2 is SPARC 99.4MB _ j4k-7u70-colans-cparetargz is SPARC 64-bit (SVR4 package) 24MB__ jtk-7u70-colane-cparcv9 tarz 1F SPARC Babe 18.4Me _ jae-7u79-solans-sparcvd tar gz Windows x86 138.31 MB jk-7479-windows-580 018 Windows x64 180.06 NB jA-7u70-windows-x64 eve This Java SE kit which you will select includes the JDK & JRE thus your selection will depend on your operating system which you have on your computer. Select “Accept License Agreement” and click the JDK ‘ile type which is most suitable for your operating system. The selected file will be downloaded on your system. One the file is downloaded on your system, double click on it and your will sec the following screen: Then, click Next on the following dialog box: 14 First Step in JavaAND~404 43va Masion Contrl profing and dagnostes tools sulte snow avaliable a part of On the following dialog box, click Next. 15 First Step in JavaAND~404 The nsta atonw start ke fo owng; wa tfor tto fin sh. |B) Jn SE Development Kit8 Update 111 (64-bit) - Progress (alate Once the installation is complete, you will see the following screen. Click “Close” to fnsh the nsta at on procedure. ‘B9) Java SE Development Kit 8 Update 111 (64-bit) ~ Complete BL .Jnva SE Development tS Updete 11 (4-5) Successful nstaed (lek Next steps to acess tutorials, API docamentaton, developer ude, release notes ‘sd more toe you get started withthe 306. (CC ertsieoe To verify if you have successfully installed JDK on your Windows machine. follow the steps below: 16 1. _ Open a command prompt by clicking Start->Run, then type “cmd”, then click OK 2. In the window that opens, type java -version then press Enter if you are using Microsoft Windows You should see the following message in the console if your installation was completes successfully. SOs ee) est RCE oa ts Prat ee SCT NEON meres tL Cee ee Herren th ONG SC a RC re Oem oD jotSpot (IM) 64-Bit Server UM Chuild 25.73-b82, nixed node bs First Step in JavaAND~404 Why did Google choose Java over other programming languages? The basic advantages of having Java programming language for Android SDKs (software development kits) are given below. 1. Java is a known programming language; developers know it. Java has yet again emerged as one of the world’s most popular programming language. Also, there are many engineers who specialize in Java making a vast developers’ community which collaborates with each other. 2. It's harder to shoot yourself with Java than with C/C++ code since it has no pointer arithmetic. 3. Itruns in a VM, sono need to recompile it for every phone out there and Java is easy to secure. This is Java's very important feature. Running on a VM (thus no recompiling) is a huge plus. Also, it easily separates processes from each other, preventing a rogue application from destroying your phone or interfering with other applications. Every App has assigned its own address. 4. As said in point number 1 above, since Java is the most popular programming language, a large number of development tools are available for developers. Java has huge open source support, with many libraries and tools that are available to make developers life easier. Several mobile phones already use Java ME, so Java is known in the mobile industry and the engineering industy. 6. _ Also, Android as an operating system runs on many different hardware platforms including smart TVs, Android wear ete. Given that almost all VMs JIT compile down to native code, raw code speed is often comparable with native speed. A lot of delays attributed to higher-level languages are less to do with the \M overhead than other factors (a complex object runtime, ‘safety’ checking memory access by doing bounds checking, etc.) 7. Java allows developers to create sandbox applications, and createa better security model so that one bad App can't take down your entire OS. Android OS Structure Before you start coding, you will learn Android OS structure on which your app will run. Android uses Linux 2.6 kemel as the hardware abstraction, below is the Android OS structure. The below picture shows: Java code working on the application layer of the Android operating system structure. 18 aAND-~404 5 = Noelia? 5 wsw/d Install Android Studio Following are the steps to install Android Studio on your system 1. Open the following link to download Android Studiohttps:// developer.android.com/studio/index.html Android Studio The Official IDE for Android 2: Click the “Download Android Studio” button. 19 First Step in JavaAND~404 Terms and Conditions 1. Introduction 3. Accept the terms and conditions then click on “Download Android Studio for W ndows" button, Th s w_ startthe down oad of an executab ef eca edandod studio-bundle-xxx.xxxxxxx.exe, where xxx.xxxxxxx refers the build number. Note that the button abe and f ename wou d change f youareusnga 2Qs Mac machine because the download webpage will automatically your system. 4. Run the W ndows nsta erf e to start the nsta at on wzard, 1-10 &@ Android Studio Setup - x Welcome to Android Studio Setup Setup wil guide you through the instalation of Android Studo. Itisrecommended that you dose all other arplcations before starting Setup. This wil make tposstle to update relevant system fies without having to reboot your computer. Cick Next to continue. SDK Location and checking the Use embedded JDK checkbox. 5. Select the components you have to install and click, Next. 1-11 First Step in JavaAND~404 ax Andioid Studio Setup Choose Components px Choose which features of Android Stic you want to instal Check the componerts you want tointal and uncheck the components you den't want ta instal. ick Next to continue. Select components to insta Zango SOK andro vrtuaiDevce |» Space reaured: 4.868 URTESe ie Saratew avasieiaae Atte a T arate bt 2972061236 AM Windows 8 ae locterooene: tnaans #RCDERTES Fe Le setingsgatle vagpass XEFle 18 9. To create Java Library, click on File menu > New > New Module... 10.In the image below, we will get the below dialog box. Select “Java Library” and click Next. 11.11n the following dialog box, enter the “Library name’. /ibTest and the “Java class 1-18 First Step in JavaAND~404 name’: Mainand then click Finish. You will get the following illustrator on the left side of the Android Studio: In the left side, there are three main elements where the solution explorer resides: App 2,Libtest (Library Name) 3.Gradle Scripts Note: You will be dealing with only the Libtest module, where you will be writing the Java Code. Writing a Java Program 1-19 First Step in JavaAND~404 Java program or Java project consists of group of classes; each class will achieve part of a Java program. At the start of each project you should start with write class, to create a class you must consider the following three items: 1. Class type (Public, Private, or Protected). 2. Write “class” keyword to declare the class. 3. Next to “class” keyword is the name of your java class. The following image may display what | mean more: Class type (Public, Private, or Protected) ihe aE Tce public class Mein { (Main is the name of the class The following screenshot shows the Main class you have created. le Est Yew Nevawte Code Anahze Befector Build Run Took VCS Window Heb DHS ++ XOH AR +> tiki Peek ea PES 7 Eifintenen Sititet Ee) Simon) SSjew |g de Anand Gh BF | EMoidetny jo x | B cone maim! XE Mange « Che os Cait ey Ope public class Mein ( + Beemesrep , E6 Me 1 i > @ crn ergs Each Java project consists of group of classes, and there are three types of classes: 1.Public is the default class type end it exposes the class to other classes outside the package which means any class can refer to the field or call the method of the public class 2.Private hides from other classes within the package, which means that only the current c ass w have access to the fed or 3.Protected is a version of public restricted only to subclasses, which means that only 1-20 First Step in JavaAND~404 the current class and subclasses (and sometimes also same-package classes) of thscassw have access to the fed or method of the protected c ass, Before starting Java with Android Studio keep in mind the following: 1-The red marks in Android Studio refer to compile-time errors in your Java code. A le-time error (also known as a compiler error) is an error thet prevents the Oypputer from translating your code 2-Java is case-sensitive, which means that system.out.printLn isn't the same as System.OutPrintin Java class starts with the following function: Public static void main (String arasll) The following table displays what's the meaning of each part: Public means that main ( ) can be called from anywhere. Static means that man () doesnt be ong to 4 spec Tc object Void means that main() returns no value Tain is the name of a function. Main ( ) is Special because itis the Main start of the program. Siing | means the data type args is the argument passed to the function, “args” Is not special, you Args could name it anything else and the program would work the same. The Java program will include the following at the start Public class Main { public static void main (String arasll) { t Java Methods Ifyou run the above code it will not give you any result, you have to add the Java conf gurat on, whch whe p bu dig a Java program by add ng methods, A Java method is a collection of statements that are grouped together to perform an operation 1-21 First Step in JavaAND~404 When you call the System out printin() method, for example, the system actually executes several statements in order to display a message on the console. Print out on screen method: The following example will show how you can use the System. out printin() method to print out whatever is written between the two parentheses public class Main { public static void main (String argsll) { System.out printin(“Hello Android ATC"); H When you will run the above class you will get Hello Android ATC as output on the screen. Running a Java Program You can run a Java class by clicking the run butt on the Android Studio tool Ele i View Navigate Cove Anabne Bdacor ull Run Tost VES inflow Heo OO|4 + ¥OR AR\¢o|4 me Oe ee Ph Ae 7 Or by press Shift + F10 keys. Also, you can run the class by right clicking anywhere on the class and then select 1-22 First Step in JavaAND~404 Run on the shortcut menus the folowing figure ilustrates: jn ee ae ! se Ba Se ! Fevers ae i i When you click the Run option first time only, you will get the following dialog box which is asking you about the device details that the Java code will run on. The Java code in Android Studio can be tested on phone, tablet, wear or TV. Click the wizard button which is beside the Android virtual device O cheese uming device Descente [Comes — Tse Murer] Aoceovinuataevice [one 1 bese dee for frances Then, click “Create Virtual Device..."button. 1-23 First Step in JavaAND~404 Select “Nexus 5” under “Phone’ category as displayed on the hardware device, then click Next. Seco In the following sereen, click Next. 124 First Step in JavaAND~404 Per Mie A | vention ‘woe (Sex Avo Nene mes oman ce aie te edie To You will get the following screen: 125 First Step in JavaAND~404 See Peat: x TE tess Tl tesatin hina ans cngeony ask Ch TE tatnanss senesTe lies a8 aN mewn IneceiB io aes 1k You will get the following: Now when you will run the below class code again, it will ask again about the virtual device this time select "Nexus 5 AP! 24” as Android virtual device and click "Ok" to see the output of your code. 1-26 First Step in JavaAND~404 Zl L “GMinjee* ard es Sy cates Sy Cw public class Main ( Ce ena anh scatde wid ain (Sey ast 9 on Man t Syaten.oet.prinein elie Androts ATC")! sruawe You will see the following output, where you will get the "Hello Android ATC” text printed. This text can be anything you wrote above between parentheses of System.out printin. | Run = Main *C:\Program ..- Hello Android ATC + Process finished with exit code 0 dt 2:Favortes é8 Si gies ‘Add more text using the System.out print as shown below: public static void main ( Stringl] args) { System out print("Hello Android ATC"); System out print("Java Fundamentals for Android” Development"); System.out.print(‘Android” Application Development”); System.out.print(“Android™ Security Essentials”); System. out print("Monetize Android” Applications"); System.out.print("For more information check www.androidate.com”); First Step in JavaAND~404 When you run the Java program you will get the following result: All the output of the System out print methods will be on the same line; however, if you replace System. out.print method with System.out printin in the previous code, we will get the following result: (C\Provram Piles\wava\jahi.o. Hello Android ATC + Gave Fundamentals for Android™ Development EB Android™ application Development a Android™ Security Essentials o o |_73\bin\ java" Bi LJ] Monetize Android™ Applications For more information check yvy.androidatc. com Process finished with exit code 0 Write a Comment We have two ways to wr te the Java comment; you candefne line comments or block comments. Line comments: Any line starting with double forward slash the Java compiler will considerit as comment, which means that this part will not run or appear to those who use this. application, it will remain internal. Comments are used to write short description about different parts of the Java program. Example: 1-28 First Step in JavaAND~404 public class Main { public static void main (String arqsf]) ‘ // This my first line comment, it consists of one line | System.out.printin(“Hello Android ATC”); y Block comments: Itis like a line comment but it includes more than one line and it starts with /* and ends with */. This is used to add multiple lines as comments in the code without adding // in start of each line. Example: public class Main { public static void main (String args{]) I This is a block comment Itconsists of more than one line I can write here info about this part of Java program / System.out.printin(“Hello Android ATC”); y You can comment or uncomment any line or multiple lines of code in addition to adding description about code. Java Variables and Their Data Type ‘A Java variable is a piece of memory that can contain a data value. Variables are typically used to store information which your Java program needs to do its job. A variable thus has a data type. All variables in Java must be declared before they can be used For example: Int x=1; Doing so tells your program that a field (variable) named °x" exists, holds numerical data, having an initial value of "I" and the data type of this field is integer. A variable’s data type determines the values it may contain, plus the operations that may be 129 First Step in JavaAND~404 performed on it. We have two categories of data types as follow 1. Primitive data types. 2. Composite data types. Aprimitive data type uses a small amount of memory to represent a single item of data. Itis preserved by the programming language and reserved keywords are used for naming the primitive data types. In addition to int, the Java programming language supports seven other data types. The following table displays the Primitive data types: Data Description Default Type Value byte The byte data type is an &-bit signed integer. 0 short | The short data type is a 16-bit signed integer. 0 The integer data type is a 32-bit signed integer. thas a int maximum value of 2,147,483,647, 0 Tong The long data type is a 64-bit signed integer. OL float__ | The float data type is a single-precision 32bit floating point. oof double | The double data type is a doubleprecision 64-bit floating point. | 0.0d Boolea | The Boolean data type has only two possible values: true and | \u0000 n false ? ‘char The char data type is a single 16-bit Unicode character. null Composite data types will be explained in the next lessons. Java has the following rules and conventions for naming variables: Variable names are case-sensitive and white space is not permitted. Beginning with a letter, the dollar sign "$", or the underscore character "_" is allowed Subsequent characters may beletters, digits, dollar signs, or underscore characters. By convention, you should name your variables using “camel case’, i.e. if the name consists of only one word, its all lowercase letters. If it consists of more than one word, the frst etter of each subsequent word s cap ta zed, Also by convention, constants are all capitalized and contain underscore. The following is an example which will show how to declare two integer variables (a &b) and declare the another variable c which will be the sum of a & b 1:30 Udemy OM Android App Development Master Course with Java | Android Instructors Oak Academy, OAK Academy Team, Mehmet ONGEL Sanjeev Jantwal Dato June 2.2004 Langth $45 total hours

You might also like