0% found this document useful (0 votes)
5 views

SDLLab Manual Updated - Google Docs

Uploaded by

sarthakjain1112
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

SDLLab Manual Updated - Google Docs

Uploaded by

sarthakjain1112
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

‭ORIENTAL INSTITUTE OF SCIENCE &‬

‭TECHNOLOGY,BHOPAL‬
‭DEPARTMENT OF ARTIFICIAL INTELLIGENCE & MACHINE‬
‭LEARNING‬

‭LAB MANUAL‬

‭Name: - Skill Development‬


‭Course Code: - AL-705‬
‭Course: - B.Tech‬
‭Session: -‬ ‭July-Dec, 2024‬

‭Prepared By-‬ ‭Submitted to: -‬


‭ oll No- 0105AL211076
R Prof.Sandeep Piplotia‬
‭Name - Nipun Dehariya ‬ ‭CSE-AIML, OIST‬
‭LIST OF EXPERIMENTS‬

‭S.no‬ ‭ ‬‭EXPERIMENTS‬
‭.‬
‭1.‬
‭Design‬‭a‬‭system‬‭with‬‭the‬‭help‬‭of‬‭advanced‬‭data‬‭structures‬‭in‬‭Java‬‭and‬‭enhance‬‭the‬‭system‬
‭using collections and generics.‬

‭2.‬ ‭Enhance the system with the help of socket programming using client server‬
‭architecture.‬

‭3.‬ ‭Enhance system by using JDBC, Multithreading, concurrency, synchronous and‬


‭asynchronous callbacks, Thread Pools using Executor Service‬

‭4.‬ ‭Transform the system from command line system to GUI based application using applet.‬

‭5.‬ ‭Download Install and Configure Android Studio on Linux/window platform.‬

‭6.‬ ‭Design a mobile app for a media player.‬

‭7.‬ ‭Design a mobile app to store data using internal or external storage.‬

‭8.‬ ‭Design a mobile app using Google Map and GPS to trace the location.‬
‭ExperimentNo:01‬

‭Problem Statement::‬

‭Design a system with the help of advanced data structure inJava and enhance the system‬
‭using collection and generics.‬
‭Objectives:‬

‭●‬‭To adapt the usage of modern tools and recent software.‬

‭●‬‭To evaluate problems and analyze data using current technologies‬

‭●‬‭To learn the process of creation of data-driven web applications using current‬
‭technologies‬

‭●‬‭Tounderstandhowtoincorporatebestpracticesforbuildingenterpriseapplications‬

‭●‬ ‭To‬ ‭learn‬ ‭how‬ ‭to‬ ‭employ‬ ‭Integrated‬


‭Development‬‭Environment (IDE)‬ ‭for implementing and testing of software solution‬
‭●‬‭To Construct software solutions by evaluating alternative architectural patterns.‬

‭SoftwareRequirements: -‬

‭-Ubuntu 14.04,Geditor, JDK‬

‭HardwareRequirements: -‬

‭-Any Processor above Pentium 4‬

‭Theory Concept:‬
‭IntroductiontotheCollectionFramework‬

‭We‬‭can‬‭use‬‭an‬‭array‬‭to‬‭store‬‭a‬‭group‬‭o f‬‭elements‬‭o f‬‭the‬‭same‬‭type‬‭(either‬‭primitives‬


‭o r‬‭o bjects).Thearray,however,doesnotsupportso-called‬‭dynamicallocation‬‭-‬‭it‬‭has‬‭a‬‭fixed‬
‭length‬ ‭which‬ ‭cannot‬ ‭be‬ ‭changed‬ ‭o nce‬ ‭allocated.‬ ‭Furthermore,array‬ ‭is‬ ‭a‬ ‭simple‬ ‭linear‬
‭structure.‬‭Many‬‭applications‬‭may‬‭require‬‭more‬‭complex‬‭data‬‭structures‬‭such‬‭as‬‭linked‬
‭list,stack,hash‬ ‭table,sets,or‬ ‭trees.‬ ‭In‬ ‭Java‬ ‭dynamically‬ ‭allocated‬ ‭data‬
‭ArrayList,LinkedList,Vector,Stack,HashSet,HashMap,Hashtable)aresupportedina‬ ‭unified‬
‭architecture‬ ‭calledtheCollectionFramework,which‬ ‭mandatesthecommonbehaviorsofall‬
‭the‬
‭classes.‬

‭Collection:-‬

‭Collections‬ ‭in‬ ‭java‬ ‭is‬ ‭a‬ ‭framework‬ ‭that‬ ‭provides‬ ‭an‬ ‭architecture‬ ‭to‬ ‭store‬ ‭and‬
‭manipulate‬‭the‬‭group‬‭o f‬‭o bjects.‬‭Each‬‭item‬‭in‬‭a‬‭collection‬‭is‬‭called‬‭an‬‭element.‬‭All‬‭the‬
‭o perationsthatyouperformonadatasuchas‬
‭searching,sorting,insertion,manipulation,deletionetc.canbeperformedbyJavaCollection‬
‭s.JavaCollectionsimply‬ ‭meansa‬
‭singleunitofobjects.JavaCollectionframeworkprovidesmanyinterfaces(Set,List,Queue,D‬
‭equeetc.)‬ ‭and‬ ‭classes‬ ‭(Array‬ ‭List,‬ ‭Vector,‬ ‭LinkedList,Priority‬
‭Queue,HashSet,LinkedHashSet,Treeset Etc.).‬

‭Framework‬‭:-‬
‭A‬ ‭framework‬ ‭by‬ ‭definition‬ ‭is‬ ‭a‬ ‭set‬ ‭o f‬ ‭interfaces‬ ‭that‬ ‭force‬ ‭you‬ ‭to‬ ‭adopt‬ ‭some‬
‭design‬‭practices.‬‭A‬‭well-designed‬‭framework‬‭can‬‭improve‬‭your‬‭productivity‬‭and‬‭provide‬
‭ease of maintenance.‬

‭Thecollectionframeworkprovidesaunifiedinterfacetostore,retrieveandmanipulatet‬
‭heelementsofacollection,regardlessoftheunderlyingandactualimplementation.‬ ‭This‬
‭allows the programmers toprogramat the interfaces, insteadoftheactualimplementation.‬

‭TheJavaCollectionFrameworkpackage(java.util)contains‬
‭1.‬ ‭Aset Interfaces,‬
‭2.‬ ‭Implementation Classes,and‬
‭3.‬ ‭Algorithms(such as sorting and searching).‬
‭HierarchyofCollectionFramework‬
‭Letusseethe Hierarchy Collection Framework.The Java.util package contains‬
‭all the classes and interfaces of Collection Framework.‬
‭IntroductiontoGenerics‬
‭Java‬ ‭Generics‬ ‭Programming‬ ‭is‬‭introduced‬‭in‬‭J2SE5‬‭to‬‭deal‬‭with‬‭type-safe‬‭o bjects.‬
‭We‬ ‭can‬ ‭store‬ ‭any‬ ‭type‬ ‭o f‬ ‭o bjects‬ ‭in‬ ‭collection‬ ‭i.e.‬ ‭non-generic.‬‭Now‬‭generics,forcesthe‬
‭java programmer tostorespecifictypeofobjects.‬
‭AdvantageofJavaGenerics‬
‭1)‬ ‭Type-safety:We‬‭canholdonlyasingletypeofobjectsingenerics.Itdoesn’tallowstorin‬
‭gotherobjects.‬
‭2)‬ ‭Typecastingisnotrequired:‬‭Thereisnoneedtotypecasttheobject.BeforeGenerics,w‬
‭eneed totypecast.‬
‭e.g.‬
‭List‬
‭List=‬‭new‬‭ArrayList();list.ad‬
‭d(‬‭"hello"‬‭);‬

‭Strings=(String)list.get(‬‭0‬‭);‬‭//typecasting‬
‭AfterGenerics,we don't need to typecast the object.‬
‭e.g.‬
‭List<String>‬ ‭list‬
‭=‬‭new‬‭ArrayList<String>();‬
‭list.add(‬‭"hello"‬‭);Strings=list.get(‬‭0‬‭);‬

‭3)‬ ‭Compile-Time‬ ‭Checking:‬‭It‬ ‭is‬ ‭checked‬ ‭at‬ ‭compile‬ ‭time‬ ‭so‬ ‭problem‬ ‭will‬
‭not‬‭o ccur‬‭at‬‭runtime.‬‭The‬‭good‬‭programming‬‭strategy‬‭says‬‭it‬‭is‬‭far‬‭better‬
‭to handle the problem at compile time than runtime.‬

‭Syntaxtousegenericcollection‬
‭ClassOrInterface<Type>‬
‭e.g.‬ ‭ArrayList<String>‬

‭ExampleofGenericsinJava‬
‭Import Java.util‬‭.*;‬
‭class‬‭TestGenerics1‬

‭{‬

‭public static void main‬‭(String Args[])‬

‭{‬

‭ArrayList<String>‬ ‭list=‬‭new‬
‭ArrayList<String>();list.add(‬‭"rahul"‬‭);‬

‭list.add(‬‭"jai"‬‭);‬

‭Strings=list.get(‬‭1‬‭);‬ ‭//type‬ ‭casting‬ ‭is‬ ‭not‬


‭required‬‭System.out.println(‬‭"elementis:"‬‭+s);‬

‭Iterator<String>itr=list.iterator();‬

‭while‬‭(itr.hasNext())‬
‭System.out.println(itr.next())}}‬
‭Output:‬
‭elementis:jai‬
‭rahul‬
‭jain‬

‭Conclusion:-we learn advanced data structures‬‭inJavausing collections generics.‬


‭Experiment No: 02‬

‭ProblemStatement::‬

‭Enhance the system with the help of socket programming client server‬
‭architecture.‬
‭Objectives::‬

‭TounderstandClient-Server Communication Using Socket.‬

‭SoftwareRequirements: -‬

‭- Ubuntu 14.04 ,geditor,JDK‬

‭HardwareRequirements: -‬

‭–‬ ‭Any Processor above Pentium4‬

‭Theory Concept::‬
‭W hat Is Socket?‬

‭A‬ ‭socket‬ ‭is‬ ‭o ne‬ ‭end-point‬ ‭o f‬ ‭a‬ ‭two-way‬ ‭communication‬ ‭link‬ ‭between‬ ‭two‬
‭programs‬‭running‬‭o n‬‭the‬‭network.‬‭Socket‬‭classes‬‭are‬‭used‬‭to‬‭represent‬‭the‬‭connection‬
‭between‬ ‭a‬ ‭client‬ ‭program‬ ‭and‬ ‭a‬ ‭server‬ ‭program.‬ ‭The‬ ‭java.net‬ ‭package‬ ‭provides‬ ‭two‬
‭classes--Socket‬‭and‬‭ServerSocket--that‬‭implement‬‭the‬‭client‬‭side‬‭o f‬‭the‬‭connection‬‭and‬
‭theserverside the connection,respectively.‬

‭Client/ServerCommunication‬

‭At‬ ‭a‬ ‭basic‬ ‭level,‬ ‭network-based‬ ‭systems‬ ‭consist‬ ‭o f‬ ‭a‬ ‭server,‬ ‭client,‬ ‭and‬ ‭a‬ ‭media‬ ‭for‬
‭communication.‬‭A‬‭computer‬‭running‬‭a‬‭program‬‭that‬‭makes‬‭a‬‭request‬‭for‬‭services‬‭is‬‭called‬‭a‬
‭client‬ ‭machine.‬ ‭A‬ ‭computer‬ ‭running‬ ‭a‬ ‭program‬ ‭that‬ ‭o ffers‬ ‭requested‬ ‭service‬ ‭from‬ ‭o ne‬ ‭o r‬
‭more‬ ‭clients‬ ‭is‬ ‭called‬ ‭a‬ ‭server‬ ‭machine.‬ ‭The‬ ‭media‬ ‭for‬ ‭communication‬ ‭can‬
‭bewiredorwirelessnetwork.Generally,programsrunningonclientmachinesmakerequests‬ ‭to‬ ‭a‬
‭program‬ ‭(often‬ ‭called‬ ‭as‬ ‭server‬ ‭program)‬ ‭running‬ ‭o n‬ ‭a‬ ‭server‬ ‭machine.They‬ ‭involve‬
‭networking‬ ‭services‬ ‭provided‬ ‭by‬‭the‬‭transport‬‭layer,‬‭which‬‭is‬‭part‬‭o f‬‭the‬‭Internet‬‭software‬
‭stack‬‭,often‬‭called‬ ‭TCP/IP‬ ‭(TransportControlProtocol/InternetProtocol)‬‭The‬‭transport‬‭layer‬
‭comprises‬ ‭two‬ ‭types‬ ‭o f‬ ‭protocols,‬ ‭TCP‬ ‭(Transport‬
‭ControlProtocol)andUDP(UserDatagramProtocol).The Most Widely Used Programming‬

‭interfacesfortheseprotocolsaresockets.TCPisaconnection-orientedprotocolthatprovides‬ ‭a‬
‭reliable‬‭flow‬‭o f‬‭data‬‭between‬‭two‬‭computers.‬‭Example‬‭applications‬‭that‬‭use‬‭such‬‭services‬
‭HTTP,FTP,andTelnet.‬

‭SocketsandSocket-basedCommunication‬

‭Sockets‬ ‭provide‬ ‭an‬ ‭interface‬ ‭for‬ ‭programming‬ ‭networks‬ ‭at‬ ‭the‬ ‭transport‬
‭layer.Network‬‭communication‬‭using‬‭Sockets‬‭is‬‭very‬‭much‬‭similar‬‭to‬‭performing‬‭file‬‭I/O.‬
‭Infact,‬ ‭socket‬ ‭handles‬ ‭are‬ ‭treated‬ ‭like‬ ‭file‬ ‭handles.‬ ‭The‬ ‭streams‬ ‭used‬ ‭in‬ ‭file‬ ‭I/O‬
‭o peration‬ ‭are‬ ‭also‬ ‭applicable‬ ‭to‬ ‭socket-based‬ ‭I/O.‬ ‭Socket-based‬ ‭communication‬ ‭is‬
‭independent‬ ‭o f‬ ‭the‬ ‭programming‬ ‭language‬ ‭used‬ ‭for‬ ‭implementing‬ ‭it.‬ ‭That‬ ‭means,‬ ‭a‬
‭socket‬ ‭program‬ ‭written‬ ‭in‬ ‭Java‬ ‭language‬ ‭can‬ ‭communicate‬ ‭to‬ ‭a‬ ‭program‬ ‭written‬ ‭in‬
‭non-Java‬ ‭(say‬ ‭C‬ ‭o r‬ ‭C++)socket‬ ‭program.‬ ‭A‬ ‭server‬ ‭(program)‬ ‭runs‬ ‭o n‬ ‭a‬ ‭specific‬
‭computer‬ ‭and‬ ‭has‬ ‭a‬ ‭socket‬ ‭that‬
‭isboundtoaspecificport.Theserverlistenstothesocketforaclienttomakeaconnectionreque‬
‭st(seeFig.13.4a).If‬ ‭Everything‬ ‭Goes‬ ‭Well,the‬ ‭server‬ ‭accepts‬ ‭the‬ ‭connection‬ ‭(see‬ ‭Fig.‬
‭13.4b).‬ ‭Upon‬ ‭acceptance,‬ ‭the‬ ‭server‬ ‭gets‬ ‭a‬ ‭new‬ ‭socket‬ ‭bound‬ ‭to‬ ‭a‬ ‭different‬ ‭port.‬ ‭It‬
‭needs‬ ‭a‬ ‭new‬ ‭socket‬ ‭(consequently‬‭a‬‭different‬‭port‬‭number)‬‭so‬‭that‬‭it‬‭can‬‭continue‬‭to‬
‭listen to the original socket for connection requests while serving the connected client.‬

‭SOCKET PROGRAMMING AND JAVA.NETCLASS‬

‭A‬‭socket‬‭is‬‭an‬‭endpoint‬‭o f‬‭a‬‭two-way‬‭communication‬‭link‬‭between‬‭two‬‭programs‬
‭running‬ ‭o n‬ ‭the‬ ‭network.‬ ‭Socket‬ ‭is‬ ‭bound‬ ‭to‬ ‭a‬‭port‬‭number‬‭so‬‭that‬‭the‬‭TCP‬‭layer‬‭can‬
‭identify‬ ‭the‬ ‭application‬ ‭that‬ ‭data‬ ‭is‬ ‭destined‬ ‭to‬ ‭be‬ ‭sent.‬ ‭Java‬ ‭provides‬ ‭a‬ ‭set‬ ‭o f‬
‭classes,definedinapackagecalledjava.net,toenabletherapiddevelopmento‬ ‭network‬
‭applications.‬ ‭Key‬‭classes,‬‭interfaces,‬‭and‬‭exceptions‬‭in‬‭java.net‬‭package‬‭simplifying‬‭the‬
‭complexity involved in creating client and server programs are:‬

‭TheClasses‬

‭•‬ ‭Content Handler‬

‭•‬ ‭Datagram Packet‬


‭•‬ ‭Datagram Socket‬

‭•‬ ‭DatagramSocketImpl‬

‭•‬ ‭HttpURLConnection‬

‭•‬ ‭InetAddress‬

‭•‬ ‭MulticastSocket‬

‭•‬ ‭ServerSocket‬
‭•‬ ‭Socket‬

‭•‬ ‭SocketImpl‬

‭•‬ ‭URL‬

‭•‬ ‭URLConnection‬

‭•‬ ‭URLEncoder‬

‭•‬ ‭URLStreamHandler‬

‭TheInterfaces‬

‭•‬ ‭ContentHandlerFactory‬

‭•‬ ‭FileNameMap‬

‭•‬ ‭SocketImplFactory‬

‭•‬ ‭URLStreamHandlerFactory‬

‭ExceptionsinJava‬

‭•‬‭BindException‬

‭•‬‭ConnectException‬

‭•‬‭MalformedURLException‬

‭•‬‭NoRoutetoHostException‬

‭•‬‭ProtocolException‬

‭•‬‭SocketException‬
‭Client-ServerCommunicationStructure‬

‭The InetAddressClass: -‬

‭•‬‭HandlesInternetaddressesboth ashostnames andasIPaddresses‬


‭•‬ ‭StaticMethodgetByNamereturnstheIPaddressofaspecifiedhostnameasanInetAdd‬
‭ressobject‬

‭•‬‭Methods For Address/name conversion:‬

‭public‬ ‭static‬ ‭InetAddressgetByName(String‬ ‭host)‬ ‭throws‬


‭UnknownHostExceptionpublicstaticInetAddress[]getAllByName(Stringhost)throwsUnknown‬
‭HostExceptionpublicstatic InetAddressgetLocalHost() throwsUnknownHostException‬

‭publicbooleanisMulticastAddress()pu‬
‭blicStringgetHostName()‬
‭public‬ ‭byte[]‬

‭getAddress()publicStringgetHos‬

‭tAddress()public inthashCode()‬

‭public boolean equals(Objectobj)‬

‭publicStringtoString()‬

‭e.g.‬

‭Retrieving The Current Machine's Address‬

‭importjava.net.*;‬

‭publicclassMyLocalIPAddress‬

‭{‬

‭public static void main(String[]args)‬

‭{‬

‭try‬

‭{‬

‭InetAddressaddress=InetAddress.getLocalHost();Syste‬

‭m.out.println(address);‬

‭}‬

‭catch(UnknownHostException)‬
‭{‬

‭System.out.println("Could Not Find Local Address!");‬

‭}‬

‭}‬

‭}‬

‭TheJava.net.SocketClass‬

‭•‬ ‭Connectionisaccomplishedthroughtheconstructors.EachSocket‬ ‭o bjects‬


‭associated‬ ‭with‬ ‭exactly‬ ‭o ne‬ ‭remote‬ ‭host.‬ ‭To‬ ‭connect‬ ‭to‬ ‭a‬ ‭different‬ ‭host,‬ ‭you‬
‭mustcreateanewSocketobject.‬

1‭ )‬ p‭ ublicSocket(String Host,int port)throwsUnknownHostException,IOException‬


‭2)‬ ‭publicSocket(InetAddressaddress,intport)throwsIOException‬

‭3)‬ ‭publicSocket(String Host,int port,InetAddress‬


‭localAddr,intlocalPort)throwsIOException‬

‭4)‬ ‭publicSocket(InetAddressaddress,intport,InetAddress localAddr,intlocalPort)‬


‭throwsIOException‬

‭•‬ ‭Sendingandreceivingdataisaccomplishedwithoutputandinputstreams.‬
‭There‬ ‭are‬ ‭methods‬ ‭to‬ ‭get‬ ‭an‬ ‭input‬ ‭stream‬ ‭for‬ ‭a‬ ‭socket‬ ‭and‬
‭anoutputstreamforthesocket.‬

‭1)‬ ‭publicInputStreamgetInputStream()throwsIOException‬

‭2)‬ ‭publicOutputStreamgetOutputStream()throwsIOException‬
‭ExampleofJavaSocketProgramming‬

‭1)‬ ‭MyServer.java‬

‭import java.io.*;‬

i‭mportjava.net.*;public‬
‭class Server{‬

‭public static void main(String[]args){try{‬

‭ServerSocketss=newServerSocket(6666);Soc‬

‭ket s=ss.accept();//establishes connection‬

‭DataInputStream‬

‭dis=newDataInputStream(s.getInputStream());String‬

‭Str=(String)dis.readUTF();System.out.println("messa‬

‭ge=‬

‭"+str);ss.close();‬

‭}catch(Exceptione){System.out.println(e);}‬

‭}‬
‭}‬

‭ )‬‭MyClient.java‬
2
‭import‬

‭java.io.*;import‬
‭java.net.*;publicclass‬

‭MyClient{‬

‭public‬ ‭static‬ ‭void‬ ‭main(String[]‬ ‭args)‬

‭{try{‬

‭Sockets=newSocket("localhost",6666);Da‬

‭taOutputStreamdout=new‬

‭DataOutputStream(s.getOutputStream());dout.writeUTF("Hello‬

‭Server");‬

‭dout.flush();‬

‭dout.close();‬

‭s.close();‬

‭}catch(Exceptione){System.out.println(e);}‬

‭}‬

‭}‬

‭Conclusion:-‬

‭Welearnsocketprogrammingusingclientserverarchitecture‬
‭ExperimentNo:03‬

‭ProblemStatement::‬

‭Enhance system by using JDBC, Multithreading, concurrency, synchronous and‬


‭asynchronous callbacks, Thread Pools using Executor Service‬
‭Objectives::‬

‭1)‬‭To understand the JDBC concept.‬

‭2)‬‭To understand java mysql connectivity‬


‭SoftwareRequirements:-‬

‭-Ubuntu 14.04 , Geditor ,JDK‬

‭HardwareRequirements:-‬

‭-AnyProcessor abovePentium4‬

‭Theory Concept::‬
‭Java JDBC:‬
‭Java JDBC is a java API to connect and execute queries with the database. JDBC API‬
‭uses jdbc drivers to connect with the database.‬

‭W hyuseJDBC‬
‭Before‬‭JDBC,‬‭ODBC‬‭API‬‭was‬‭the‬‭database‬‭API‬‭to‬‭connect‬‭and‬‭execute‬‭query‬‭with‬
‭the‬ ‭database.But,ODBCAPIuses‬ ‭ODBCdriverwhichis‬ ‭written‬ ‭in‬ ‭language‬ ‭(i.e.platform‬
‭dependent‬ ‭and‬ ‭unsecured).‬ ‭That‬ ‭is‬ ‭why‬ ‭Java‬ ‭has‬ ‭defined‬ ‭its‬ ‭own‬ ‭API‬
‭(JDBCAPI)thatusesJDBCdrivers(writteninJavalanguage).‬

‭JDBCConnectionBasics‬
‭Java‬ ‭Database‬ ‭Connectivity(JDBC)isa‬ ‭standard‬ ‭application‬ ‭programming‬
‭interface‬ ‭(API)‬ ‭specification‬ ‭that‬ ‭is‬ ‭implemented‬ ‭by‬ ‭different‬ ‭database‬ ‭vendors‬ ‭to‬
‭allowJava‬ ‭programs‬ ‭to‬ ‭access‬ ‭their‬ ‭database‬ ‭management‬ ‭systems.‬ ‭The‬ ‭JDBC‬ ‭API‬
‭consists‬ ‭o f‬ ‭a‬ ‭set‬ ‭o f‬ ‭interfaces‬ ‭and‬ ‭classes‬ ‭written‬ ‭in‬ ‭the‬ ‭Java‬‭programming‬‭language.‬
‭Interestingly,JDBCis‬ ‭notanacronymandthus‬ ‭stands‬
‭fornothingbutpopularas‬‭JavaDatabaseConnectivity‬‭.‬ ‭According‬ ‭toSun‬ ‭(now‬ ‭merged‬ ‭in‬
‭Oracle) JDBC is a trademark term note acronym. It Was Named toby redolent ofODBC.‬

‭JDBC‬ ‭implementation‬ ‭comes‬ ‭in‬ ‭form‬ ‭o f‬ ‭a‬ ‭database‬ ‭driver‬ ‭for‬ ‭a‬ ‭particular‬
‭DBMSvendor.‬ ‭A‬ ‭Java‬ ‭program‬ ‭that‬ ‭uses‬ ‭the‬ ‭JDBC‬ ‭API‬ ‭loads‬‭the‬‭specified‬‭driver‬‭for‬‭a‬
‭particularDBMSbeforeit actually connects to the database.‬

‭JDBCConnection-JDBCDesign‬

‭JDBC‬ ‭--a‬ ‭trademark‬ ‭comes‬ ‭bundled‬ ‭with‬ ‭Java‬ ‭SE‬ ‭as‬ ‭a‬ ‭set‬ ‭o f‬ ‭APIs‬ ‭that‬ ‭facilitates‬ ‭Java‬
‭Programs‬ ‭to‬ ‭access‬ ‭data‬ ‭stored‬ ‭in‬ ‭a‬ ‭database‬ ‭management‬ ‭system,‬ ‭particularly‬ ‭in‬
‭aRelationalDatabase.AtthetimeofdesigningJDBC(Java‬ ‭Database‬ ‭Connectivity),following‬
‭goals were kept in mind:‬
‭•‬ ‭JDBC(Java‬ ‭Database‬ ‭Connectivity)shouldbeanSQLlevelAPI;therefore,it‬ ‭should‬
‭allow‬ ‭users‬ ‭to‬ ‭construct‬ ‭SQL‬ ‭statements‬ ‭and‬ ‭embed‬‭them‬‭into‬‭Java‬‭APIcalls‬‭to‬
‭run‬ ‭those‬ ‭statements‬ ‭o n‬ ‭a‬ ‭database.‬ ‭And‬ ‭then‬ ‭results‬ ‭from‬ ‭the‬ ‭database‬
‭returned as Java objects(ResultSets)and access-problems as exceptions.‬

‭•‬ ‭JDBC‬ ‭(Java‬ ‭database‬ ‭connectivity)‬ ‭should‬ ‭provide‬ ‭a‬ ‭driver‬‭manager‬‭to‬‭allow‬


‭third‬ ‭party‬ ‭drivers‬ ‭to‬ ‭connect‬ ‭to‬ ‭specific‬ ‭databases,‬ ‭where‬ ‭database‬
‭vendorscouldprovidetheir owndriverstoplugintothedrivermanager.‬
‭For‬ ‭example‬ ‭MySQL‬ ‭provides‬ ‭its‬ ‭driver‬ ‭in‬ ‭form‬ ‭o f‬ ‭a‬ ‭JAR‬ ‭archive‬ ‭(e.g.,‬
‭mysql-connector-java-***-bin.jar).‬ ‭This‬ ‭driver‬ ‭first‬ ‭should‬ ‭be‬ ‭loaded‬ ‭into‬
‭memory‬ ‭inorder‬ ‭connect‬ ‭MySQL‬ ‭database,and‬ ‭thendrivermanagercreates‬
‭connection‬‭with‬‭help‬‭o f‬‭the‬‭loaded‬‭driver.‬‭Whole‬‭process‬‭will‬‭be‬‭explained‬‭step‬
‭by step in this article.‬
‭•‬ ‭JDBC(Javadatabaseconnectivity)shouldbesimple;therewouldthenbeasimplemech‬
‭anismtoregisterthirdpartydriverswiththedrivermanager.Finally,‬ ‭JDBC‬ ‭came‬ ‭into‬
‭existence‬ ‭as‬ ‭a‬ ‭result‬ ‭o f‬ ‭above‬ ‭goals,‬ ‭and‬ ‭two‬ ‭APIs‬
‭werecreated.ApplicationprogrammersusetheJDBCAPI,anddatabasevendorsuse‬
‭the JDBC Driver API.‬

‭JDBCConnection-CreateDatabaseforUse‬

‭To‬ ‭start‬ ‭using‬ ‭JDBC‬ ‭(Java‬ ‭database‬ ‭connectivity)‬ ‭first‬ ‭you‬ ‭would‬ ‭need‬ ‭a‬
‭database‬ ‭system,‬ ‭and‬ ‭then‬ ‭a‬ ‭JDBC‬ ‭(Java‬ ‭database‬ ‭connectivity)‬ ‭driver‬ ‭for‬ ‭your‬
‭database.‬ ‭During‬ ‭This‬ ‭article‬‭JDBC‬‭(Java‬‭database‬‭connectivity)‬‭will‬‭be‬‭explained‬‭with‬
‭MySQL,‬ ‭but‬ ‭you‬ ‭can‬ ‭use‬ ‭it‬ ‭with‬ ‭any‬ ‭database‬ ‭system‬ ‭(such‬ ‭as‬ ‭Microsoft‬ ‭SQL,‬ ‭Oracle,‬
‭IBM‬ ‭DB2,‬ ‭PostgresQL),provided‬ ‭that‬ ‭you‬ ‭have‬ ‭a‬ ‭JDBC‬ ‭(Java‬ ‭database‬ ‭connectivity)‬
‭driver for your database system.‬

‭Suppose‬ ‭you‬ ‭have‬ ‭MySQL‬ ‭and‬ ‭a‬‭functional‬‭Java‬‭environment‬‭installed‬‭o n‬‭your‬


‭system,‬ ‭where‬ ‭you‬ ‭write‬ ‭and‬ ‭execute‬ ‭Java‬ ‭programs.‬ ‭ForMySQL,‬
‭downloadMySQLConnector/J‬ ‭the‬ ‭o fficial‬ ‭JDBC‬ ‭(Java‬ ‭database‬ ‭connectivity)‬ ‭driver‬ ‭for‬
‭MySQL.‬ ‭You‬ ‭will‬ ‭get‬ ‭JDBC‬ ‭driver‬ ‭mysql-connector-java-***-bin.jar‬ ‭in‬ ‭a‬ ‭zipped‬ ‭driver‬
‭bundle.‬‭Place‬‭this‬‭JAR‬‭in‬‭Java's‬‭class‬‭path‬‭because‬‭this‬‭JAR‬‭is‬‭the‬‭JDBC‬‭driver‬‭for‬‭MySQL‬
‭and will be used by JDBC(Java Database Connectivity).‬

‭After‬ ‭having‬ ‭the‬ ‭environment‬ ‭ready‬ ‭to‬ ‭experiment‬ ‭with‬‭JDBC‬‭connectivity‬‭you‬


‭need‬ ‭to‬ ‭create‬ ‭a‬ ‭database‬ ‭and‬ ‭at‬ ‭least‬ ‭o ne‬ ‭table‬ ‭in‬ ‭the‬ ‭database‬ ‭containing‬ ‭a‬ ‭few‬
‭records,‬ ‭wename‬ ‭the‬ ‭example‬ ‭database‬ ‭EXPDP,‬ ‭and‬ ‭the‬ ‭table‬ ‭inside‬ ‭EXPDP‬ ‭is‬
‭ACCEPTABLE.‬‭I‬‭create‬‭this‬‭database‬‭with‬‭root‬‭privileges,‬‭if‬‭you‬‭do‬‭so‬‭it's‬‭fine‬‭but‬‭if‬‭you‬
‭create‬‭a‬‭database‬‭with‬‭different‬‭user‬‭then‬‭ensure‬‭that‬‭you‬‭have‬‭permissions‬‭to‬‭create,‬
‭update‬ ‭and‬ ‭drop‬ ‭tables‬ ‭in‬ ‭the‬ ‭database‬ ‭you‬
‭created(toperformabovestatedoperationsbyJDBC-Java‬ ‭Database‬ ‭connectivity).‬ ‭Now,‬
‭let's‬ ‭create‬ ‭an‬ ‭EXPDP‬ ‭database,‬‭a‬‭table‬‭EXP‬‭TABLE‬‭in‬‭EXPDP,and‬‭insert‬‭a‬‭few‬‭records‬
‭as‬ ‭follows.‬ ‭Following‬ ‭steps‬ ‭we‬ ‭are‬ ‭executing‬ ‭manually,‬ ‭later‬ ‭we‬ ‭will‬ ‭connect‬ ‭the‬
‭database with the help JDBC- Java Database Connectivity.‬

‭JDBCConnection-UsingJDBC‬

‭1.‬‭JDBC Connection-Database URL or String‬


‭DatabaseURLforJDBC‬ ‭connectionJDBC2‬ ‭connection‬ ‭string‬ ‭follows‬ ‭more‬ ‭o r‬‭less‬
‭similar‬ ‭syntax‬ ‭to‬ ‭that‬ ‭o f‬ ‭o rdinary‬ ‭URLs.‬ ‭It‬ ‭tells‬ ‭the‬ ‭protocol‬ ‭used‬ ‭to‬ ‭connect‬ ‭to‬
‭database,‬ ‭subprotocol,‬ ‭location‬ ‭o f‬ ‭database,‬ ‭port‬ ‭number‬ ‭o n‬ ‭which‬ ‭database‬
‭listensclientrequests,and‬ ‭databasename.Theexamplesyntaxmaylooklike‬
‭Jdbc:mysql://localhost:3306/EXPDB.‬ ‭Aforementioned‬ ‭URL‬ ‭specifies‬ ‭a‬ ‭MySQL‬
‭databasenamedEXPDBrunningonlocalhostonport3306.‬

‭2.‬‭JDBCConnection-DriverClass‬
‭As we have obtained theJDBC driver info mofaJAR file(mysql-connector-java-‬
‭***-‬‭bin.jar)‬‭in‬‭which‬‭the‬‭driver‬‭for‬‭MySQL‬‭database‬‭is‬‭located.‬‭This‬‭driver‬‭needs‬‭to‬‭be‬
‭registeredinordertoaccessEX‬ ‭PDB.DriverfilenameforMySQLi‬ ‭com.mysql.jdbc.Driver.‬
‭This‬‭file‬‭has‬‭to‬‭be‬‭loaded‬‭into‬‭memory‬‭before‬‭you‬‭get‬‭connected‬‭to‬‭the‬‭database,‬‭else‬
‭you will result in java.sql. SQL Exception: No suitable driver exception.‬

‭3.‬‭JDBCConnection-DatabaseUserNameandPassword‬
‭To‬ ‭get‬ ‭a‬ ‭JDBC‬ ‭connection‬ ‭to‬ ‭the‬ ‭database‬ ‭you‬ ‭would‬ ‭require‬ ‭the‬‭username‬‭and‬
‭password,‬ ‭it‬ ‭is‬ ‭the‬ ‭same‬ ‭username‬ ‭and‬ ‭password‬ ‭which‬ ‭we‬ ‭used,‬ ‭while‬ ‭connecting‬
‭toMySQL.‬

‭JavaProgramforJDBCConnection‬

‭Nowe‬ ‭willstartwritingJavaprogramtoconnect‬ ‭EXPDP(our‬ ‭example‬ ‭database)‬


‭through‬‭JDBC‬‭(Java‬‭database‬‭Connectivity)‬‭and‬‭perform‬‭INSERT‬‭and‬‭SELECToperations‬
‭for‬ ‭demonstration.‬ ‭To‬ ‭illustrate‬ ‭this‬ ‭piece‬ ‭o f‬ ‭work,‬ ‭we‬ ‭would‬ ‭take‬‭followingsteps,and‬
‭finallycollectallpiecesofcodetoassemblethecompleteprogram.‬
‭1.‬‭RegisterJDBCDriverClass‬
‭Registering‬‭JDBC‬‭driver‬‭class‬‭with‬‭the‬‭Driver‬‭Manager‬‭means‬‭loading‬‭JDBC‬‭driver‬
‭class in memory.‬
‭e.g.‬
‭try‬
‭1.‬‭ConnecttoDatabasethroughJDBCDriver‬
‭Inordertoconnecttoexampledatabase‬‭EXPDB‬‭youneedtoopenadatabaseconnectioninJ‬
‭avaprogram thatyou cando asfollowsbyusingJDBCdriver:‬
‭e.g.‬
‭//jdbc driver connection string,db username and password‬

‭UsingDriverManagergetsyouaconnectiontothedatabasespecifiedbyconnection‬
‭Url.‬‭When‬‭above‬‭code‬‭fragment‬‭is‬‭executed,‬‭the‬‭DriverManager‬‭iterate‬‭through‬‭the‬
‭registered‬ ‭JDBC‬ ‭drivers‬ ‭to‬ ‭find‬ ‭a‬ ‭driver‬ ‭that‬ ‭can‬ ‭use‬ ‭the‬ ‭subprotocol‬ ‭specified‬‭in‬
‭the‬ ‭connectionUrl.‬ ‭Don't‬ ‭forget‬ ‭to‬ ‭surround‬ ‭getConnection()‬ ‭code‬ ‭by‬ ‭try‬
‭block,because it can throw SQLException.‬

‭2.‬‭ExecuteSQLStatementsthroughJDBCConnection‬

‭Now‬ ‭that‬ ‭you‬ ‭have‬ ‭a‬ ‭JDBC‬ ‭Connection‬ ‭o bject,‬ ‭you‬ ‭would‬ ‭like‬ ‭to‬ ‭executeSQL‬
‭statements‬ ‭through‬ ‭the‬ ‭conn‬ ‭(JDBC‬ ‭connection)‬ ‭o bject.‬ ‭A‬ ‭connection‬ ‭in‬ ‭JDBC‬ ‭is‬ ‭a‬
‭session‬ ‭with‬‭a‬‭specific‬‭database,‬‭where‬‭SQL‬‭statements‬‭are‬‭executed‬‭and‬‭results‬‭are‬
‭returned‬ ‭within‬ ‭the‬ ‭context‬ ‭o f‬ ‭a‬ ‭connection.‬ ‭To‬ ‭execute‬ ‭SQL‬ ‭statements‬ ‭you‬ ‭would‬
‭need‬ ‭a‬ ‭Statement‬ ‭o bject‬ ‭that‬ ‭you‬ ‭would‬ ‭acquire‬ ‭by‬ ‭invoking‬
‭createStatement()methodonconn as illustrated below.‬

‭e.g.‬
‭try‬

‭Statementobjectstmtbyexecutingabovepieceofcode.Bydefinition,createStatement()‬
‭throwsanSQLExceptionsothecodelineStatementstmt=conn.createStatement();‬ ‭should‬
‭either‬ ‭surrounded‬‭by‬‭try‬‭block‬‭o r‬‭throw‬‭the‬‭exception‬‭further.‬‭On‬‭successful‬‭creation‬
‭o f‬ ‭stmt‬ ‭you‬ ‭can‬ ‭send‬ ‭SQL‬ ‭queries‬ ‭to‬ ‭your‬‭database‬‭with‬‭help‬‭o f‬‭executeQuery(),‬‭and‬
‭executeUpdate() methods. Also the Statement has many more useful methods.‬

‭Next,‬‭form‬‭a‬‭query‬‭that‬‭you‬‭would‬‭like‬‭to‬‭execute‬‭o n‬‭the‬‭database.‬‭For‬‭instance,‬
‭we‬ ‭will‬ ‭select‬ ‭all‬ ‭records‬ ‭from‬‭EXPDP,‬‭o ur‬‭example‬‭database.‬‭Method‬‭executeQuery()‬
‭will‬ ‭get‬ ‭you‬ ‭a‬ ‭ResultSet‬ ‭o bject‬ ‭that‬ ‭contains‬ ‭the‬ ‭query‬ ‭results.‬ ‭You‬ ‭can‬ ‭think‬ ‭a‬
‭ResultSetobject‬ ‭as‬ ‭two‬ ‭dimensional‬ ‭array‬ ‭o bject,‬ ‭where‬ ‭each‬ ‭row‬ ‭o f‬ ‭an‬ ‭array‬
‭represents‬ ‭o ne‬ ‭record.‬ ‭And,‬ ‭all‬ ‭rows‬ ‭have‬ ‭an‬ ‭identical‬ ‭number‬ ‭o f‬ ‭columns;‬ ‭some‬
‭columns may contain null values.Itisal Depends upon what is stored in the database.‬

‭e.g.‬

‭String‬‭queryString‬‭=‬‭"SELECT*FROM EXP TABLE"‬


‭MethodexecuteQuery()throws‬‭SQLException,soitshouldeitherb‬‭surrounded‬‭by‬
‭try‬‭block‬‭o r‬‭further‬‭throw‬‭the‬‭exception.‬‭After‬‭getting‬‭a‬‭ResultSetobject‬‭is‬‭you‬‭may‬
‭like‬ ‭to‬ ‭process‬ ‭records‬ ‭for‬ ‭further‬ ‭use.‬ ‭Here,‬ ‭for‬ ‭illustration‬ ‭we‬ ‭would‬ ‭print‬ ‭the‬
‭o nscreen.‬

‭e.g.‬

‭System‬‭.‬‭out‬‭.‭p
‬ rintln‬‭(‬‭"ID‬‭\t‬‭NAME"‬‭)‬‭;‬

‭We‬ ‭process‬ ‭o ne‬ ‭record‬ ‭at‬ ‭a‬ ‭time‬ ‭o r‬ ‭you‬ ‭say‬ ‭o ne‬ ‭row‬ ‭at‬ ‭a‬ ‭time.‬
‭ResultSet'snext()method‬ ‭helps‬ ‭us‬ ‭to‬ ‭move‬ ‭o ne‬ ‭record‬ ‭forward‬ ‭in‬ ‭o ne‬ ‭iteration,‬ ‭it‬
‭returns‬ ‭true‬
‭untilreachestolastrecord,falseiftherearenomorerecordstoprocess.WeaccessResultSet's‬
‭columns‬ ‭by‬ ‭supplying‬ ‭column‬ ‭headers‬ ‭to‬ ‭getXxx()‬ ‭methods‬ ‭as‬ ‭they‬ ‭are‬‭inEXPTABLE‬
‭e.g.,‬ ‭rs.getInt("id").‬ ‭You‬ ‭can‬ ‭also‬ ‭access‬ ‭those‬ ‭columns‬ ‭by‬‭supplying‬‭columnindices‬‭to‬
‭getXxx()‬ ‭methods‬ ‭e.g.,‬ ‭rs.getInt(1)‬ ‭will‬ ‭return‬ ‭you‬ ‭the‬ ‭first‬ ‭column‬ ‭o f‬ ‭currentrow‬
‭pointed byrs.‬
‭2.‬‭CloseJDBCConnection‬
J‭ DBCconnectiontodatabaseisasession;ithasbeenmentionedearlier.Assoon‬
‭as‬ ‭you‬ ‭close‬ ‭the‬ ‭session‬‭you‬‭are‬‭no‬‭longer‬‭connected‬‭to‬‭the‬‭database;‬‭therefore,‬‭you‬
‭wouldn't‬ ‭be‬ ‭able‬ ‭to‬ ‭perform‬ ‭any‬‭o peration‬‭o n‬‭the‬‭database.‬‭Closing‬‭connection‬‭must‬
‭be the verylaststep when you aredonewithall databaseoperations‬

‭e.g.‬

‭JAVAMySQLConnectivityProgram:‬

‭importjava.sql.*;i‬
‭mport‬
‭java.io.*;classJay‬

‭{‬

‭public static void main(String Args[])throwsClassNotFoundException‬

‭{‬

‭try‬

‭{‬

‭Class.forName("com.mysql.jdbc.Driver");‬

‭Connection‬
‭Con=DriverManager.getConnection("mysql:jdbc://localhost:3306/stud","root","siem ");‬

‭Statement St=con.createStatement();‬
‭ResultSetrs=st.executeQuery("select‬ ‭*‬ ‭from‬
‭student");while(rs.next())‬

‭{‬
‭System.out.println(rs.getInt(1)+""+rs.getString(2)+""+rs.getString(3));‬

‭}‬
‭con.close();‬

‭}‬

‭catch(Exceptione)‬

‭{‬
‭System.out.println("Error:-"+e);‬

‭}‬

‭}‬
‭}‬

‭o/p‬

‭ID‬ ‭NAME‬ ‭City‬

‭1.‬ ‭Jayraj‬ ‭Nashik‬


‭2.‬ ‭Avinash‬ ‭Pune‬
‭3.‬ ‭Ashwini‬ ‭Mumbai‬

‭Conclusion:‬
‭We Understand The Java Mysql Connectivity.‬
‭ExperimentNo:04‬

‭ProblemStatement::‬

‭Transform the system from command line system to GUI based application using applet‬

‭Objectives::‬

‭1)‬‭TounderstandGUIconcept.‬

‭2)‬‭TounderstandApplet andEventhandlingusingapplet‬

‭SoftwareRequirements:-‬

‭-Ubuntu 14.04,Geditor,JDK‬

‭HardwareRequirements:-‬

‭–‬ ‭AnyProcessorabovePentium4‬

‭Theory Concept::‬

‭JavaApplet‬

‭ ppletisaspecialtypeofprogramthatisembeddedinthewebpagetogeneratethedynamic‬
A
‭content.Itrunsinsidethebrowserandworksatclient side.‬

‭AdvantageofApplet‬

‭There Are Many Advantages of Applets. They Are As Follows:‬


‭•‬ ‭It works at client side soles response time.‬

‭•‬ ‭Secured‬

‭•‬ ‭Itcanbeexecutedbybrowsersrunningundermany‬
‭Platforms,includingLinux,Windows,MacOsetc.‬

‭DrawbackofApplet‬

‭•‬ ‭Pluginisrequiredatclientbrowserto executeapplet.‬


‭HierarchyofApplet‬

‭As displayed in the above diagram,Applet class extends Panel .Panel class extends Container which‬
‭is the subclass Component.‬
‭LifecycleofJavaApplet‬

‭1.‬ ‭Applet Initialized.‬


‭2.‬ ‭Applet Is Started.‬
‭3.‬ ‭Appletispainted.‬
‭4.‬ ‭Appletisstopped.‬
‭5.‬ ‭Appletisdestroyed.‬
‭LifecyclemethodsforApplet:‬
‭The Java.applet.Applet Class 4 life cycle methods and Java.awt.Component Class Provides 1 lifecycle‬
‭methods for an applet.‬

‭java.applet.Appletclass‬

‭For creating any applet Java.applet.Applet Class Must Be‬


‭Inherited.Itprovides4lifecyclemethodsofapplet.‬
‭1)‬‭public void init():issued initialize theApplet.Itisinvoked only once.‬

‭2)‬ ‭public void start():is invoked after the‬


‭init()methodorbrowserismaximized.ItisusedtostarttheApplet.‬
‭3)‬ ‭public void stop():isusedtostoptheApplet.ItisinvokedwhenAppletisstoporbrowser isminimized.‬

‭4)‬‭public void destroy():is used to destroytheApplet.Itisinvokedonlyonce.‬

‭java.awt.Componentclass‬

‭TheComponentclassprovides1lifecyclemethodofapplet.‬

‭1.‬‭public void paint(Graphics):isusedtopainttheApplet.ItprovidesGraphicsclassobjectthatcanbeused‬


‭for drawingoval,rectangle,arcetc.‬
‭E.g.‬

‭What is anEvent?‬

‭Change‬ ‭in‬ ‭the‬ ‭state‬ ‭o f‬ ‭an‬ ‭o bject‬ ‭is‬ ‭known‬ ‭as‬ ‭event‬ ‭i.e.‬ ‭event‬ ‭describes‬ ‭the‬ ‭change‬ ‭in‬ ‭state‬ ‭o f‬
‭source.‬ ‭Events‬ ‭are‬ ‭generated‬ ‭as‬ ‭result‬ ‭o f‬ ‭user‬ ‭interaction‬ ‭with‬ ‭the‬
‭graphicaluserinterfacecomponents.Forexample,clickingonabutton,movingthemouse,entering‬‭a‬‭character‬
‭through‬ ‭keyboard,selecting‬ ‭an‬ ‭item‬ ‭from‬ ‭list,‬ ‭scrolling‬ ‭the‬ ‭page‬ ‭aretheactivitiesthatcausesan‬ ‭event‬ ‭to‬
‭happen‬

‭ ypesofEvent‬
T
‭The Event Scan Be Broadly Classified Into Two Categories:‬

‭•‬ ‭ForegroundEvents‬‭-Thoseeventswhichrequirethedirectinteractionofuser.Theyaregenerate‬
‭dasconsequencesofapersoninteractingwiththegraphicalcomponents‬ ‭in‬ ‭Graphical‬ ‭User‬ ‭Interface.‬
‭For‬ ‭example,‬ ‭clicking‬ ‭o n‬ ‭a‬ ‭button,‬ ‭moving‬ ‭the‬ ‭mouse,‬ ‭entering‬ ‭a‬ ‭character‬ ‭through‬
‭keyboard,selecting anitem fromlist,scrolling thepageetc.‬
‭•‬ ‭Background‬ ‭Events‬ ‭-‬ ‭Those‬ ‭events‬ ‭that‬ ‭require‬ ‭the‬ ‭interaction‬ ‭o f‬ ‭end‬ ‭user‬
‭areknownasbackgroundevents.Operatingsysteminterrupts,hardwareorsoftwarefailure,timerexpir‬
‭es,anoperationcompletionaretheexampleofbackgroundevents.‬

‭add(t3);‬
‭add(b);b.addActionListener(this);‬

‭}‬
‭publicvoidactionPerformed(ActionEvent)‬
‭{‬
‭if(e.getSource()==b)‬
‭{‬
‭intn1=Integer.parseInt(t1.getText());intn2=Integer.parse‬
‭Int(t2.getText());t3.setText(""+(n1+n2));‬

‭}‬
‭}‬

‭}‬

‭/*‬
‭<html><body><appletcode="Q2.class"height=500width=500>‬
‭</applet></body></html>*/‬

‭ UTPUT:‬
O
‭Conclusion:‬‭WelearntheAppletdesigningandEventhandlingforsystemdesigning‬
‭ExperimentNo:05‬

‭Download Install and Configure Android Studioon Linux/windows platform.‬

‭P roblemDefinition‬
‭Install and Configure Android Studio on Linux.‬

‭1.1‬‭Prerequisite:‬
‭●‬ ‭Basic concepts of Installation and Configuration of Android Studio on Linux.‬
‭●‬ ‭Concepts of Android Platform Architecture and component of Android.‬

‭1.2‬‭SoftwareRequirements:‬
‭AndroidStudio‬
‭1.3‬‭Tools/Framework/LanguageUsed:‬
‭AndroidStudio‬
‭1.4‬‭HardwareRequirement:‬
‭PIV,4GB RAM,500GB HDD, LenovoA13-4089Model‬
‭1.5‬‭LearningObjectives:‬
‭InstallandConfigureAndroidStudioonLinux.‬
‭1.6‬‭Outcomes:‬
‭After‬ ‭completion‬ ‭o f‬ ‭this‬ ‭assignment,‬ ‭students‬ ‭are‬ ‭able‬ ‭toUnderstand‬ ‭Howto‬ ‭Install‬
‭andConfigureAndroidStudioonLinuxandAndroidPlatformArchitecture.‬
‭1.7‬‭TheoryConcepts:‬
‭Android‬ ‭is‬ ‭a‬ ‭complete‬ ‭set‬ ‭o f‬ ‭software‬ ‭for‬ ‭mobile‬ ‭devices‬ ‭such‬ ‭as‬ ‭tablet‬
‭computers,notebooks,‬ ‭smartphones,‬ ‭electronic‬ ‭book‬ ‭readers,‬ ‭set-top‬ ‭boxes‬ ‭etc.‬ ‭It‬ ‭contains‬ ‭a‬
‭Linux-basedOperating‬‭System‬‭,‬‭middleware‬‭and‬‭key‬‭mobile‬‭applications‬‭.‬‭It‬‭can‬‭be‬‭thought‬
‭o f‬ ‭as‬ ‭a‬ ‭mobile‬ ‭o perating‬
‭system.Butitisnotlimitedtomobileonly.Itiscurrentlyusedinvariousdevicessuchasmobiles,tablets,te‬
‭levisions etc.‬

‭HistoryofAndroid‬

‭The‬ ‭History‬ ‭And‬ ‭versions‬ ‭of‬ ‭android‬ ‭are‬ ‭interesting‬ ‭to‬ ‭know.The‬ ‭Codenames‬ ‭Android‬
‭Ranges‬ ‭from‬ ‭A‬ ‭to‬ ‭J‬ ‭currently,‬ ‭s uch‬ ‭as‬ ‭Aestro‬‭,‬ ‭Blender‬‭,‬ ‭Cupcake‬‭,‬ ‭Donut‬‭,‬
‭Eclair‬‭,‬‭Froyo‬‭,‭G
‬ ingerbread‬‭,‬‭Honeycomb‬‭,‬‭Ice‬ ‭Cream‬ ‭Sandwich‬‭,‬‭JellyBean‬‭,‬‭KitKat‬ ‭and‬ ‭Lollipop.Let's‬
‭Understand‬‭the androidhistoryina sequence.‬
‭1)‬ ‭Initially,‬‭AndyRubinfoundedAndroid Incorporation Palo Alto‬‭,California,United States October,2003.‬

‭2)‬ ‭On‬ ‭17th‬ ‭August‬ ‭2005,‬ ‭Google‬ ‭acquired‬ ‭Android‬ ‭Incorporation.‬ ‭Since‬ ‭then,‬ ‭it‬ ‭is‬ ‭a‬ ‭subsidiary‬
‭o fGoogleIncorporation.‬
‭3)‬ ‭ThekeyemployeesofAndroidIncorporationare‬‭Andy Rubin‬‭,‬‭Rich Miner‬‭,‬‭Chris White‬‭and‬
‭NickSears‬‭.‬
‭4)‬ ‭Originally‬ ‭intended‬ ‭for‬ ‭cameras‬ ‭but‬ ‭shifted‬ ‭to‬ ‭smart‬ ‭phones‬ ‭later‬
‭becauseoflowmarketforcameraonly.‬
‭5)‬ ‭AndroidisthenicknameofAndyRubin givenbycoworkersbecauseofhislovetorobots.‬
‭6)‬ ‭In2007,GoogleannouncesthedevelopmentofandroidOS.‬
‭7)‬ ‭In2008,HTClaunchedthefirstandroidmobile.‬

‭AndroidArchitecture‬
‭androidarchitecture‬‭or‬‭Androidsoftwarestack‬‭iscategorizedintofiveparts:‬

‭a.‬ ‭Linux Kernel‬


‭b.‬ ‭native libraries(middleware),‬
‭c.‬ ‭AndroidRuntime‬
‭d.‬ ‭ApplicationFramework‬
‭e.‬ ‭Applications‬
‭Let's See The Android architecture first.‬
‭1)‬‭Linux Kernel‬
‭It‬ ‭is‬‭the‬‭heart‬‭o f‬‭android‬‭architecture‬‭that‬‭exists‬‭at‬‭the‬‭root‬‭o f‬‭android‬‭architecture.‬
‭Linuxkernel‬‭isresponsiblefordevicedrivers,power‬ ‭management,memory‬
‭management,devicemanagementand resource access.‬

‭2)‬‭NativeLibraries‬
‭On the top of linux kernel, there are‬‭Native libraries‬‭such as WebKit, OpenGL,‬
‭FreeType,SQLite,Media,Cruntimelibrary(libc)etc.TheWebKitlibraryisresponsibleforbrowsersup‬
‭port,SQLiteisfordatabase,FreeTypeforfontsupport,Mediaforplayingandrecordingaudioandvideo‬
‭formats.‬

‭3)‬‭AndroidRuntime‬
‭In‬‭android‬‭runtime,‬‭there‬‭are‬‭core‬‭libraries‬‭and‬‭DVM‬‭(Dalvik‬‭Virtual‬‭Machine)‬‭which‬
‭is‬ ‭responsible‬ ‭for‬ ‭running‬ ‭android‬ ‭applications.‬ ‭DVM‬ ‭is‬ ‭like‬ ‭JVM‬ ‭but‬ ‭it‬ ‭is‬ ‭o ptimized‬ ‭for‬
‭mobile devices. It Consumes Less Memory And Provides Fast Performance.‬

‭4)‬‭AndroidFramework‬
‭On‬ ‭the‬ ‭top‬ ‭o f‬ ‭Native‬ ‭libraries‬ ‭and‬ ‭android‬‭runtime,‬‭there‬‭is‬‭an‬‭android‬‭framework.‬
‭Android‬ ‭Framework‬ ‭includes‬ ‭Android‬ ‭APIs‬ ‭such‬ ‭as‬ ‭UI‬ ‭(User‬ ‭Interface),‬ ‭telephony,‬
‭resources,‬ ‭locations,Content‬ ‭Providers‬ ‭(data)‬ ‭and‬ ‭package‬ ‭managers.‬ ‭It‬ ‭provides‬ ‭a‬ ‭lot‬ ‭o f‬
‭classes and interfaces for android application development.‬

‭5)‬‭Applications‬
‭On‬ ‭the‬ ‭top‬ ‭o f‬ ‭android‬ ‭framework,‬ ‭there‬ ‭are‬ ‭applications.‬ ‭All‬ ‭applications‬ ‭such‬ ‭as‬
‭home,contact,‬ ‭settings,‬ ‭games,‬ ‭browsers‬ ‭are‬ ‭using‬ ‭android‬ ‭framework‬ ‭that‬ ‭uses‬ ‭android‬
‭runtime and libraries.Androidruntime And nativelibrariesareusingLinuxkernel.‬
‭An‬ ‭Android‬ ‭component‬ ‭is‬ ‭simply‬ ‭a‬ ‭piece‬ ‭o f‬ ‭code‬ ‭that‬ ‭has‬ ‭a‬ ‭well-defined‬ ‭life‬ ‭cycle‬ ‭e.g.‬
‭Activity,Receiver,Serviceetc.‬
‭The‬‭core building blocks or fundamental components of‬‭android are activities, views, intents,‬

‭s ervices,content providers,fragmentsandAndroidManifest.xml.‬

‭Activity‬
‭Anactivityisaclassthatrepresentsasinglescreen.ItislikeaFrameinAWT.‬
‭View‬
‭Aview istheUIelementsuch as button,label,textfield etc.Anythingthatyou seeisaview.‬
‭Intent‬
‭Intentisusedto invokecomponents.Itismainlyusedto:‬
o‬
‭ ‭Starttheservice‬
o‬
‭ ‭Launcheractivity‬
o‬
‭ ‭Display Webpage‬
o‬
‭ ‭Displayalistof contacts‬
o‬
‭ ‭Broadcast Message‬

o‬
‭ ‭Dialaphone Calletc.‬
‭For Example,you may write the following codetoview the webpage.‬
‭1.‬ ‭Intent Intent=‬‭new‬‭Intent(Intent.ACTION_VIEW);‬
‭2.‬ ‭intent.setData(Uri.parse("‬‭http://www.javatpoint.com‬‭"));‬
‭3.‬ ‭startActivity(intent);‬

‭Service‬
S‭ ervice‬‭is‬‭a‬‭background‬‭process‬‭that‬‭can‬‭run‬‭for‬‭a‬‭long‬‭time.There‬‭are‬‭two‬‭types‬‭o f‬‭services‬‭local‬‭and‬
‭remote.‬ ‭Local‬ ‭service‬ ‭is‬ ‭accessed‬ ‭from‬ ‭within‬ ‭the‬ ‭application‬ ‭whereas‬ ‭remote‬ ‭service‬ ‭is‬ ‭accessed‬
‭remotely from other applications running on the same device.‬

‭ContentProvider‬
‭ContentProvidersareusedto share data between the applications.‬

‭Fragment‬
‭Fragmentsarelikepartsofactivity.Anactivitycandisplayoneormorefragmentsonthescreenatthesametime.‬

‭AndroidManifest.xml‬
‭Itcontainsinformationabout Activities,content providers,permissions etc.Itisliketheweb.xml‬
‭file in Java EE.‬
‭AndroidVirtualDevice(AVD)‬

I‭ t‬‭is‬‭used‬‭to‬‭test‬‭the‬‭android‬‭application‬‭without‬‭the‬‭need‬‭for‬‭mobile‬‭o r‬‭tablet‬‭etc.‬‭It‬ ‭can‬‭be‬‭created‬‭in‬


‭different types of real devices.‬

‭AndroidEmulator‬‭isusedtorun,debugandtestthe android application.If Don'thavethereal‬


‭device,itcanbethebestwaytorun,debug andtestthe application.‬
‭Itusesanopensourceprocessoremulatortechnologycalled‬‭QEMU‬‭.‬
‭Theemulatortoolenablesyoutostarttheemulatorfromthecommandline.Youneedtowrite:emul‬
‭ator-avd<AVD NAME>‬
‭IncaseofEclipseIDE,you cancreateAVDby‬‭W indowmenu>AVDManager> New‬‭.‬

‭Inthegivenimage,youcanseethe androidemulator,itdisplaystheoutputofthehello androidexample.‬

‭DalvikVirtualMachine|DVM‬
‭As we know the modern JVM is high performance and provides excellent‬
‭memorymanagement.Butitneedsto‬
‭beoptimizedforlow-poweredhandhelddevicesaswell.‬

‭The‬‭Dalvik Virtual Machine(DVM)‬‭is an android virtual machine optimized for mobile devices.It‬
‭optimizes the virtual machine for memory,‬‭battery life and performance‬‭.‬
‭DalvikisanameofatowninIceland.TheDalvikVMwaswrittenbyDanBornstein.‬
‭TheDexcompilerconvertstheclassfilesintothe.dexfilethatrunontheDalvikVM.Multipleclassfilesareconve‬
‭rted intoonedexfile.‬
‭Let's See The Compiling And Packaging process from the source file:‬

‭The‬‭javactool‬‭compilesthejavasourcefileintotheclassfile.‬
‭The‬‭dxtool‬‭takesalltheclassfilesofyourapplicationandgeneratesasingle.dexfile.Itisaplatform-‬
‭specifictool.‬
‭The‬‭AndroidAssetsPackagingTool(aapt)‬‭handle‬ ‭the‬ ‭packaging‬ ‭process.Internal‬
‭Details For working helloandroid example.‬
‭AndroidStudioisthepremiertoolproducedbyGooglefor‬‭creatingAndroidapps‬‭anditmorethanmatchesthat‬
‭o ther IDEusedbyMicrosoftdevelopersfor‬‭creating Windowsphoneapps‬‭.‬

‭Step-1‬
‭DownloadandInstallAndroidStudio‬
‭ThefirsttoolyouneedtodownloadisofcourseAndroidStudio.YoucandownloadAndroidStudio‬
‭AndroidVirtualDevice(AVD)‬

‭Itisusedtotesttheandroidapplicationwithouttheneedformobileortabletetc.Itcanbecreatedindifferentcon‬
‭figurationstoemulatedifferenttypesofreal devices.‬
‭AndroidEmulator‬‭isusedtorun,debugandtestthe android application.If Don'thavethereal‬
‭device,itcanbethebestwaytorun,debug andtestthe application.‬
‭Itusesanopensourceprocessoremulatortechnologycalled‬‭QEMU‬‭.‬
‭Theemulatortoolenablesyoutostarttheemulatorfromthecommandline.Youneedtowrite:emul‬
‭ator-avd<AVD NAME>‬
‭IncaseofEclipseIDE,you cancreateAVDby‬‭W indowmenu>AVDManager> New‬‭.‬

‭Inthegivenimage,youcanseethe androidemulator,itdisplaystheoutputofthehello androidexample.‬


‭DalvikVirtualMachine|DVM‬
‭As we know the modern JVM is high performance and provides excellent‬
‭memorymanagement.Butitneedsto‬
‭beoptimizedforlow-poweredhandhelddevicesaswell.‬

‭The‬‭DalvikVirtualMachine(DVM)‬‭isanandroidvirtualmachineoptimizedformobiledevices.It‬
‭optimizes the virtual machine for memory,‬‭battery life and performance‬‭.‬
‭DalvikisanameofatowninIceland.TheDalvikVMwaswrittenbyDanBornstein.‬
‭TheDexcompilerconvertstheclassfilesintothe.dexfilethatrunontheDalvikVM.Multipleclassfilesareconve‬
‭rted intoonedexfile.‬
‭Let's See The Compiling And Packaging process from the source file:‬
‭The‬‭javactool‬‭compilesthejavasourcefileintotheclassfile.‬
‭The‬‭dxtool‬‭takesalltheclassfilesofyourapplicationandgeneratesasingle.dexfile.Itisaplatform-‬
‭specifictool.‬
‭The‬‭AndroidAssetsPackagingTool(aapt)‬‭handles‬ ‭the‬ ‭packaging‬ ‭process.Internal‬
‭Details For working helloandroid example.‬
‭Step-1‬
‭DownloadandInstallAndroidStudio‬
‭ThefirsttoolyouneedtodownloadisofcourseAndroidStudio.YoucandownloadAndroidStudio‬

‭this:‬

‭android-studio-‬

‭ide-143.2915827-linux.zip‬‭Extractthezipfilebyrunni‬
‭ngthefollowingcommand:‬
‭sudounzipandroid-studio-ide-143.2915827-linux.zip-d/opt‬‭R‬
‭eplacetheandroidfilenamewiththeonelistedbythelscommand.‬
‭Step-2‬
‭RunAndroidStudio‬
‭TorunAndroidStudio,navigatetothe/opt/android-studio/binfolderusing‬‭thecdcommand‬‭:‬
‭cd/opt/android-studio/bin‬
‭Thenrunthefollowing command:‬
‭shstudio.sh‬

‭✔‬ ‭A‬ ‭screen‬ ‭will‬ ‭appear‬ ‭asking‬ ‭whether‬ ‭you‬ ‭want‬ ‭to‬ ‭import‬ ‭settings.‬ ‭Choose‬ ‭the‬‭second‬

‭o ption‬ ‭which‬ ‭reads‬ ‭as‬ ‭"I‬‭do‬‭not‬‭have‬‭a‬‭previous‬‭version‬‭o f‬‭Studio‬‭o r‬‭I‬‭do‬‭not‬‭want‬‭to‬


‭import mysettings".‬

‭✔‬ ‭ThiswillbefollowedbyaWelcomescreen.‬

‭✔‬ ‭Click"Next"to continue‬

‭Step-4‬
‭ChooseanInstallationType‬

‭✔‬ ‭Screenwillappearwithoptionsforchoosingstandardsettingsorcustomsettings.‬

‭✔‬ ‭Choose The Standard Settings Option And Click"Next".‬


‭Thenextscreenshowsalistofcomponentswhichwillbedownloaded.‬

‭✔‬ ‭The Downloadsizeisquitelargeandisover 600 Megabytes.‬

‭✔‬ ‭Click"Next"to continue.‬

‭✔‬ ‭Now,click"Finish".‬

‭Step-5‬
‭CreatingYourFirstProject‬
‭Ascreenwillappearwithoptionsforcreatinganewprojectandopeningexisting‬
‭projects.Choosethestartanew projectlink.‬
‭Ascreenwillappearwiththefollowingfi‬
‭elds:‬
‭Applicationname‬

‭Company‬

‭For This example, change the application name to"HelloWorld"and leave the‬
‭restasthedefaults.Click"Next"‬

‭Step-6‬
‭Choose Which Android Devices Target‬
‭Ucannow Choose Which Type of Android device you‬
‭wish to target.‬
‭ he Options Are As Follows:‬
T
‭Phone/Tablet‬
‭Wear‬
‭TV‬
‭Android‬
‭Auto Glass‬

‭✔‬ ‭Foreach Option,youcanchoosetheversionofAndroidtotarget.‬


‭✔‬ ‭If‬ ‭you‬ ‭choose‬ ‭"Phone‬‭and‬‭Tablet"‬‭and‬‭then‬‭look‬‭at‬‭the‬‭minimum‬‭SDK‬‭o ptions‬‭you‬‭will‬‭see‬

‭that‬ ‭for‬ ‭each‬ ‭o ption‬ ‭you‬ ‭choose‬ ‭it‬ ‭will‬ ‭show‬ ‭you‬ ‭how‬ ‭many‬ ‭devices‬ ‭will‬ ‭be‬ ‭able‬ ‭to‬ ‭run‬
‭yourapp.‬

‭✔‬ ‭Ichose4.1Jellybeanasitcoversover90%ofthemarketbutisn't toofab behind.‬

‭✔‬

‭✔‬

‭✔‬

‭✔‬

‭✔‬ ‭Click"Next"‬

‭Step-7‬
‭Choose anActivity‬

‭✔‬‭Ascreenwillappearaskingforyoutochooseanactivity.‬

‭✔‬‭Anactivityinitssimplestformisascreenandtheoneyouchooseherewillactasyourmainacti‬

‭vity.‬

‭✔‬‭Choose"BasicActivity"and click"Next".‬

‭✔‬‭You Can now give the activity anameandatitle.‬

‭✔‬‭For example, leave them as they are and click"Finish".‬


‭Step-8‬

‭AndroidStudiowillnowloadandyoucanrunthe‬
‭defaultprojectthathasbeensetupbypressingshiftandF10.‬

‭✔‬‭You Will Be Asked To Select A Deployment Target.‬

‭✔‬‭The first time RunAndroidStudiotherewon'tbeatarget.‬


‭Clickthe"CreateNewEmulator"button.‬
‭Step-9‬
‭ChooseADevicetoEmulate‬

‭✔‬‭Alistofdeviceswillappearand youcanchooseoneto useasatestdevice.‬

‭✔‬‭Don'tworryyoudon'tneedtheactualdeviceasthephoneortabletwillbeemulatedbyyour‬

‭computer.‬

‭✔‬‭When You have chosen a device click"Next".‬

‭✔‬‭A‬ ‭screen‬‭will‬‭appear‬‭with‬‭recommended‬‭download‬‭o ptions.‬‭Click‬‭the‬‭download‬‭link‬

‭next‬‭to‬‭o ne‬‭o f‬‭the‬‭o ptions‬‭for‬‭a‬‭version‬‭o f‬‭Android‬‭at‬‭the‬‭same‬‭SDK‬‭as‬‭your‬‭project‬


‭target or higher.‬

‭✔‬ ‭This Causes Anew download to occur.‬

‭✔‬ ‭Click"Next".‬

‭✔‬‭You will now be back at the choose a deployment target screen. Select the phone or‬

‭tablet you downloaded andclickOK.‬


‭1.8‬‭AssignmentQuestion?‬
‭1.‬‭ExplainAndroidActivityLifecycle?‬
‭2.‬‭ExplainAndroidFragment?‬
‭3.‬‭ExplainAndroidApplicationArchitecture?‬
‭4.‬‭Whatarethecodenamesofandroid?‬
‭5.‬‭ExplainAndroidWidget?‬

‭1.9‬‭OralQuestion?‬
‭1.‬‭What Is the Current Version ofAndroid?‬
‭2.‬‭What Is the Difference Between Android andiOS?‬
‭3.‬‭Whoisfounderof Android?‬
‭4.‬‭Does Android Support Other Languages Than Java?‬
‭WhatisActivity?‬
‭EXPERIMENT-6‬

‭Title:‬
‭Design Mobile App For media player.‬
‭ProblemDefinition:‬
‭ImplementingmediaplayerforAudioandVideo.‬
‭1.1‬‭Prerequisite:‬
‭●‬ ‭ConceptsofMediaPlayerClass.‬
‭●‬ ‭BasicconceptsofMediaPlayerAudio andVideo.‬

‭1.2‬ ‭SoftwareRequirements:‬
‭AndroidStudio‬
‭1.3‬‭Tools/Framework/LanguageUsed:‬
‭AndroidStudio‬
‭1.4‬ ‭HardwareRequirement:‬
‭PIV,4GB RAM,500GB HDD, LenovoA13-4089Model‬
‭1.5‬‭LearningObjectives:‬
‭Implementing Arrayadapter And Mediaplayer Class.‬
‭1.6‬ ‭Outcomes:‬
‭AftercompletionofthisassignmentstudentareabletoImplementMediaplayer.‬
‭1.7‬ ‭TheoryConcepts:‬
‭AndroidMediaPlayerExample‬

‭✔‬ ‭Wecanplayandcontroltheaudiofilesinandroidbythehelpof‬‭MediaPlayerclass.‬

‭✔‬ ‭Simple exampletoplaythe audiofile.In The next page,controlthe‬

‭audioplaybacklikestart,stop,pause etc.‬

‭✔‬ ‭MediaPlayerclass‬

‭✔‬ ‭Theandroid.media.MediaPlayerclass isusedtocontrol theaudio orvideofiles.‬

‭✔‬ ‭MethodsofMedia Playerclass‬

‭TherearemanymethodsofMedia Player class.Some Of Them are as follows:‬


‭Method‬ ‭Description‬

‭publicvoidsetDataSource(Stringpath)‬ ‭Setsthedatasource(filepathorhttpurl)t‬

‭use.‬

‭publicvoidprepare()‬ ‭Prepares‬ ‭the‬ ‭player‬ ‭for‬

‭playback synchronously.‬

‭public void start()‬ ‭Itstartsorresumestheplayback.‬

‭public void stop()‬ ‭Itstopstheplayback.‬

‭public void pause()‬ ‭Itpausesthe playback.‬

‭public boolean disPlaying()‬ ‭Checksifmediaplayerisplaying.‬

‭publicvoidseekTo(intmillis)‬ ‭Seeks To Specified Time in milliseconds.‬


‭public‬ ‭voidsetLooping(boolean looping)‬ ‭Setstheplayerforloopingornon-looping.‬

‭publicbooleanisLooping()‬ ‭Checksiftheplayerisloopingornon-loopi‬

‭ng.‬

‭publicvoidselectTrack(intindex)‬ ‭Itselectsatrackfor The Specified Index.‬

‭publicist getCurrentPosition()‬ ‭Returns The Current Playback Position.‬

‭publicintgetDuration()‬ ‭Returns Duration Of The file.‬

‭public‬ ‭void‬ ‭Setsthevolumeonthisplayer.‬


‭setVolume(floatleftVolume,floatrightVolume)‬

‭AndroidVideoPlayerExample‬

‭✔‬‭With the help of Media‬‭Controller and Video Viewclasses,‬‭wecan playthevideofilesinandroid.‬

‭✔‬‭Media Controller Class‬

‭✔‬ ‭Theandroid.widget.MediaControllerisaviewthatcontainsmediacontrolslikeplay/pause,pre‬

‭vious,next,fast-forward,rewindetc.‬
‭✔‬‭VideoViewclass‬

‭✔‬ ‭Theandroid.widget.VideoViewclassprovidesmethodstoplayandcontrolthevideoplayer.Th‬

‭ecommonlyused methodsofVideoView classareasfollows:‬

‭Method‬ ‭Description‬

‭ ublicvoid‬
P ‭ etsthemediacontrollertothe‬
S
‭setMediaController(MediaControllercontroller‬ ‭Videoview.‬
‭)‬

‭publicvoidsetVideoURI(Uriuri)‬ ‭Set The URIofthe video file.‬

‭public void start()‬ ‭Start The Videoview.‬

‭publicvoidstopPlayback()‬ ‭Stop The Playback.‬

‭public void pause()‬ ‭Pause The Playback.‬

‭publicvoidsuspend()‬ ‭Suspendstheplayback.‬

‭public void resume()‬ ‭Resumestheplayback.‬

‭publicvoidseekTo(intmillis)‬ ‭ eeks To Specified Time in‬


S
‭milliseconds.‬

‭1.8‬‭AssignmentQuestion?‬
‭1.‬‭Explain ArrayAdapter Class?‬
‭2.‬‭ExplainMedia PlayerClass?‬
‭3.‬‭ExplainVideo ViewClass?‬
‭4.‬‭ExplainList ViewClass?‬
‭5.‬‭ExplainMedia RecorderClass?‬
‭EXPERIMENT- 7‬
‭Title:‬

‭Design a mobile app to store data using internal or external storage.‬


‭Problem Definition:‬
‭Implement an app to store data using internal or external storage.‬
‭1.1‬‭Prerequisite:‬
‭●‬‭Basic Concepts Of Internal Or External Storage.‬
‭●‬‭BasicConceptofInternalandExternalMemory.‬

‭1.2‬‭SoftwareRequirements:‬
‭AndroidStudio‬
‭1.3‬‭Tools/Framework/LanguageUsed:‬
‭AndroidStudio‬
‭1.4‬‭HardwareRequirement:‬
‭PIV,4GB RAM,500GB HDD, LenovoA13-4089Model‬
‭1.5‬‭LearningObjectives:‬
‭Implementapptostoredatausinginternalorexternalstorage.‬
‭1.6‬‭Outcomes:‬
‭AftercompletionofthisassignmentstudentareabletoImplementApptostoredatausingint‬
‭ernalor externalstorage.‬
‭1.7‬‭TheoryConcepts:‬
‭AndroidPreferencesExample‬
‭Android‬ ‭shared‬ ‭preference‬ ‭is‬ ‭used‬ ‭to‬ ‭store‬ ‭and‬ ‭retrieve‬ ‭primitive‬
‭information.‬ ‭In‬ ‭android,string,integer,long,number‬ ‭etc.are‬ ‭considered‬
‭asprimitivedatatype.‬
‭Android‬ ‭Shared‬ ‭preferences‬ ‭are‬ ‭used‬ ‭to‬‭store‬‭data‬‭in‬‭key‬‭and‬‭value‬‭pairs‬‭so‬
‭that we can retrieve the value on the basis key.‬
‭Android‬ ‭provides‬ ‭many‬ ‭kinds‬ ‭o f‬ ‭storage‬ ‭for‬ ‭applications‬ ‭to‬ ‭store‬ ‭their‬ ‭data.‬
‭These‬ ‭storage‬ ‭places‬ ‭are‬ ‭shared‬ ‭preferences,‬ ‭internal‬ ‭and‬ ‭external‬ ‭storage,‬
‭SQLite storage, and storage via network connection.‬
‭Itiswidelyusedtogetinformationfromusersuchasinsettings‬
‭AndroidInternalStorageExample‬
‭We‬‭are‬‭able‬‭to‬‭save‬‭o r‬‭read‬‭data‬‭from‬‭the‬‭device‬‭internal‬‭memory.‬
‭FileInputStream‬ ‭andFileOutputStream‬
‭classesareusedtoreadandwritedataintothefile.‬
‭Here,wearegoingtoreadandwritedatatothe internal storage the device.‬
‭In‬ ‭o rder‬ ‭to‬ ‭use‬ ‭internal‬ ‭storage‬ ‭to‬ ‭write‬ ‭some‬ ‭data‬ ‭in‬ ‭the‬ ‭file,‬ ‭call‬ ‭the‬
‭o penFileOutput()‬ ‭method‬ ‭with‬ ‭the‬ ‭name‬ ‭o f‬ ‭the‬ ‭file‬ ‭and‬‭the‬‭mode.‬‭The‬‭mode‬
‭could be private, public etc. Its syntax is given below –‬

‭Reading File‬
‭In order to read from the file you just created, call the‬
‭o penFileInput() method with‬
‭thenameofthefile.ItreturnsaninstanceofFileInputStream.Itssyntaxisgivenbel‬
‭ow −‬
‭ ethodsofwriteandclose,thereareothermethodsprovidedbythe‬‭FileOutputStream‬‭clas‬
M
‭sfor‬
‭better writing files.These Methods Are Listed Below −‬

‭Sr.No‬ ‭Method Description‬

‭FileOutputStream(File File,Booleanappend)‬
‭1‬
‭ThismethodconstructsanewFileOutputStreamthatwritesto file.‬

‭ etChannel()‬
g
‭2‬ ‭Thismethodreturnsawrite-onlyFile‬
‭Channelthatsharesitspositionwiththisstream‬

‭getFD()‬
‭3‬
‭This Method Returns The Underlying File Descriptor‬

‭ rite(byte[]buffer,intbyteOffset,intbyteCount)‬
w
‭4‬ ‭ThismethodWritescountbytesfromthebytearraybufferstartingatposition‬
‭o ffsettothisstream‬
‭Apart from the methods of‬ ‭read and close,‬
‭thereareothermethodsprovided byte File‬‭Input Stream Class‬
‭Forbetterreadingfiles.These Methods Are Listed‬‭below–‬

‭Sr.No‬ ‭Method Description‬

‭ vailable()‬
a
‭1‬ ‭Thismethodreturnsanestimatednumberofbytesthatcanbereador skipped‬
‭withoutblockingfor moreinput‬

‭ etChannel()‬
g
‭2‬ ‭Thismethodreturnsaread-onlyFileChannelthatsharesitspositionwiththisst‬
‭ream‬

‭getFD()‬
‭3‬
‭This Method Returns The Underlying file descriptor‬

r‭ ead(byte[]buffer,intbyteOffset,intbyteCount)‬
‭4‬ ‭Thismethodreadsatmostlengthbytesfromthisstreamandstoresthem in‬
‭thebytearraybstarting atoffset‬

‭AndroidExternalStorageExample‬
‭Like‬ ‭internal‬ ‭storage,‬ ‭we‬ ‭are‬ ‭able‬ ‭to‬ ‭save‬‭o r‬‭read‬‭data‬‭from‬‭the‬‭device's‬
‭external‬ ‭memory‬ ‭such‬ ‭as‬ ‭sd‬ ‭card.‬ ‭The‬ ‭File‬ ‭Input‬ ‭Stream‬ ‭and‬ ‭File‬ ‭Output‬
‭Stream classes are used to read and write data into the file.‬
‭1.8‬‭AssignmentQuestion?‬
‭1.‬‭ExplaingetExternalstorageDirectory()?‬
‭2.‬‭What Is the Difference Between InternalandExternalmemory?‬
‭3.‬‭WhatistheuseofsharedpreferenceinAndroidandwherearetheystored?‬
‭4.‬‭What Do You Mean Contentprovider? ExplaingetPathmethod‬
‭EXPERIMENT-8‬
‭Title:‬
‭DesignamobileappusingGoogleMapandGPStotracethelocation.‬
‭ProblemDefinition:‬
‭ImplementapptousingGoogleMapandGPStotracethelocation.‬
‭1.1‬ ‭Prerequisite:‬
‭●‬ ‭BasicconceptsofGoogleMap.‬
‭●‬ ‭BasicConceptofGPSfortracelocation.‬

‭1.2‬ ‭SoftwareRequirements:‬
‭AndroidStudio‬
‭1.3‬ ‭Tools/Framework/LanguageUsed:‬
‭AndroidStudio‬
‭1.4‬ ‭HardwareRequirement:‬
‭PIV,4GB RAM,500GB HDD, LenovoA13-4089Model‬
‭1.5‬ ‭LearningObjectives:‬
‭ImplementapptousingGoogleMapandGPStotracethelocation.‬
‭1.6‬ ‭Outcomes:‬
‭After‬ ‭completion‬ ‭o f‬ ‭this‬ ‭assignment‬‭student‬‭are‬‭able‬‭to‬‭Implement‬‭App‬‭to‬
‭using Google Map andGPStotracethelocation‬
‭1.7‬ ‭TheoryConcepts‬
‭Android‬‭application‬‭which‬‭will‬‭display‬‭latitude‬‭and‬‭longitude‬‭o f‬‭the‬‭current‬
‭location‬‭in‬‭a‬‭textview‬‭and‬‭corresponding‬‭location‬‭in‬‭the‬‭Google‬‭Map.‬‭The‬‭current‬
‭location will be retrieved using GPSand LocationManagerAPIoftheAndroid.‬

‭Location‬
‭publicclassLocation‬
‭extends‬ ‭Object‬ ‭implements‬ ‭Parcelable Java.lang.Object‬
‭↳‬ ‭android.location.Location‬

‭LocationManager‬

‭public‬ ‭class‬

‭LocationMan‬
‭agerextends‬
‭Objectjava.la‬
‭ng.Object‬

‭↳‬ ‭android.location.LocationManager‬

‭This‬ ‭class‬ ‭provides‬ ‭access‬ ‭to‬‭the‬‭system‬‭location‬‭services.‬‭These‬‭services‬


‭allow‬ ‭applications‬ ‭to‬ ‭o btain‬ ‭periodic‬ ‭updates‬ ‭o f‬ ‭the‬ ‭device's‬ ‭geographical‬
‭location,‬ ‭o r‬ ‭to‬ ‭fire‬ ‭an‬ ‭application-specified‬
‭Intent‬‭whenthedeviceenterstheproximityofagivengeographicallocation.‬

‭Unless Noted,allLocationAPImethodsrequire‬
‭The‬ ‭ACCESS_COARSE_LOCATION‬‭o r‬ ‭ACCESS_FINE_LOCATION‬‭permissions.‬ ‭If‬ ‭your‬
‭application‬‭o nly‬‭has‬‭the‬‭coarse‬‭permission‬‭then‬‭it‬‭will‬‭not‬‭have‬‭access‬‭to‬‭the‬‭GPS‬
‭o r‬‭passive‬‭location‬‭providers.‬‭Other‬‭Providers‬‭will‬‭still‬‭return‬‭location‬‭results,‬‭but‬
‭the‬ ‭update‬ ‭rate‬ ‭will‬ ‭be‬ ‭throttled‬ ‭and‬ ‭the‬ ‭exact‬ ‭location‬ ‭will‬ ‭deobfuscate‬
‭toacoarselevel inaccuracy.‬

‭Instances‬ ‭o f‬ ‭this‬ ‭class‬ ‭must‬ ‭be‬ ‭o btained‬ ‭using‬


‭Context.getSystemService(Class)‬‭with‬ ‭the‬
‭argumentLocationManager.class‬ ‭o r‬
‭Context.getSystemService(String)‬ ‭with‬ ‭the‬ ‭argument‬
‭Context.LOCATION_SERVICE‬‭.‬

‭LocationProvider‬
‭public class LocationProvider‬
‭extendsObjectjava.lang.Object‬
‭android.location.LocationProvider‬

‭An‬‭abstract‬‭superclass‬‭for‬‭location‬‭providers.‬‭A‬‭location‬‭provider‬‭provides‬
‭periodic reports on geographical location of the device.‬
‭Each‬ ‭provider‬ ‭has‬ ‭a‬ ‭set‬ ‭o f‬ ‭criteria‬ ‭under‬ ‭which‬ ‭it‬ ‭may‬ ‭be‬ ‭used;‬ ‭for‬
‭example,‬ ‭some‬ ‭providers‬ ‭require‬ ‭GPS‬ ‭hardware‬ ‭and‬ ‭visibility‬ ‭to‬ ‭a‬ ‭number‬ ‭o f‬
‭satellites;‬ ‭o thers‬ ‭require‬ ‭the‬ ‭use‬ ‭o f‬ ‭the‬ ‭cellular‬ ‭radio,‬ ‭o r‬ ‭access‬ ‭to‬ ‭a‬ ‭specific‬
‭carrier's‬ ‭network,‬ ‭o r‬ ‭to‬ ‭the‬ ‭internet.‬ ‭They‬ ‭may‬ ‭also‬ ‭have‬ ‭different‬ ‭battery‬
‭consumption‬ ‭characteristics‬ ‭o r‬ ‭monetary‬ ‭costs‬ ‭to‬ ‭the‬ ‭user.‬ ‭The‬ ‭Criteria‬‭class‬
‭allows providers to be selected based on user-specified criteria.‬

‭Location ManagerMethods: -‬

‭Public Methods‬

‭boolean‬ ‭addGpsStatusListener‬‭(‬‭GpsStatus.Listener‬‭listener)‬‭This‬ ‭method‬ ‭


2
‭4
‭deprecated‬ ‭in‬ ‭level‬
‭.‬
‭APIuse‬‭registerGnssStatusCallback(GnssStatus.Callback)‬
‭instead.‬

‭boolean‬ ‭addNmeaListener‬‭(‬‭OnNmeaMessageListener‬‭listener,‬‭Handler‬‭handler)‬
‭Addison NMEA listener.‬

‭boolean‬ ‭addNmeaListener‬‭(‬‭OnNmeaMessageListener‬ ‭listener)‬


‭Addison NMEA listener.‬

‭boolean‬ ‭addNmeaListener‬‭(‬‭GpsStatus.NmeaListener‬‭listener)‬‭This‬ ‭level‬

‭method‬ ‭was‬ ‭deprecated‬ ‭in‬ ‭


2
‭4
‭APIuse‬‭addNmeaListener(OnNmeaMessageListener)‬ ‭.‬
‭instead.‬
‭void‬ ‭addProximityAlert‬‭(double latitude,double longitude,float radius,long‬
‭expiration,‬‭PendingIntent‬‭intent)‬
‭Seta Proximity Alert For The location given by the position(latitude,‬
‭longitude)and the given radius.‬

‭void‬ ‭addTestProvider‬‭(‬‭String‬‭name,booleanrequiresNetwork,booleanrequiresSatellite,‬
‭booleanrequiresCell,booleanhasMonetaryCost,booleansupportsAltitude,boolean‬
‭supportsSpeed,booleansupportsBearing,intpowerRequirement,intaccuracy)‬
‭Createsamocklocationproviderandaddsittothesetofactive‬
‭providers.‬

‭void‬ ‭c learTestProviderEnabled‬‭(‬‭String‬‭provider)‬
‭Removesanymockenabledvalueassociatedwiththegivenprovider.‬

‭void‬ ‭c learTestProviderLocation‬‭(‬‭String‬‭provider)‬
‭Removesanymocklocationassociatedwiththegivenprovider.‬

‭void‬ ‭c learTestProviderStatus‬‭(‬‭String‬‭provider)‬
‭Removesanymockstatusvaluesassociatedwiththegivenprovider.‬

‭List‬‭<‬‭String‬‭>‬ ‭getAllProviders‬‭()‬
‭Returnsalistofthenamesofallknownlocationproviders.‬

‭String‬ ‭getBestProvider‬‭(‬‭Criteria Criteria‬‭,booleanenabledOnly)‬


‭Return The name theproviderthatbestmeetsthegive criteria.‬

‭GpsStatus‬ ‭getGpsStatus‬‭(‬‭GpsStatus‬‭status)‬
‭RetrievesinformationaboutthecurrentstatusoftheGPSengine.‬

‭Location‬ ‭ etLastKnownLocation‬‭(‬‭String‬‭provider)‬
g
‭ReturnsaLocationindicatingthedatafromthelastknownlocationfixobtainedfromthe‬
‭givenprovider.‬
‭LocationProvi‬ ‭getProvider‬‭(‬‭String Name‬‭)‬
‭der‬ ‭Returnstheinformationassociatedwiththelocationproviderofthe‬
‭given name, or null if no provider exists by that name.‬

‭List‬‭<‬‭String‬‭>‬ ‭ etProviders‬‭(‬‭Criteria Criteria‬‭,booleanenabledOnly)‬


g
‭ReturnsalistofthenamesofLocationProvidersthatsatisfythegivencriteria, or null if‬
‭none do.‬

‭List‬‭<‬‭String‬‭>‬ ‭getProviders‬‭(booleanenabledOnly)‬
‭Returns A List Of The names of location providers.‬

‭boolean‬ ‭isProviderEnabled‬‭(‬‭String‬‭provider)‬
‭Returns The Current Enabled/disabled status of the given provider.‬
‭boolean‬ ‭registerGnssMeasurementsCallback‬‭(‬‭GnssMeasurementsEvent.Callback‬‭c allback‬‭,‬‭H‬
‭andler‬‭handler)‬
‭Register GPS Measurement callback.‬
‭boolean‬ ‭registerGnssMeasurementsCallback‬‭(‬‭GnssMeasurementsEvent.Callback‬‭c allback)‬
‭Register GPS Measurement callback.‬

‭boolean‬ ‭registerGnssNavigationMessageCallback‬‭(‬‭GnssNavigationMessage.Callback‬‭c allbac‬


‭k‬‭,‬‭Handler‬‭handler)‬
‭Registers GNSS Navigation Message callback.‬
‭boolean‬ ‭registerGnssNavigationMessageCallback‬‭(‬‭GnssNavigationMessage.Callback‬‭c allbac‬
‭k)‬
‭Registers GNSS Navigation Message callback.‬

‭boolean‬ ‭registerGnssStatusCallback‬‭(‬‭GnssStatus.Callback‬ ‭c allback)‬


‭Register siGNS statuscallback.‬
‭boolean‬ ‭registerGnssStatusCallback‬‭(‬‭GnssStatus.Callback‬ ‭c allback,‬ ‭Handler‬
‭Handler‬‭)‬
‭Register siGNS statuscallback.‬
‭void‬ ‭removeGpsStatusListener‬‭(‬‭GpsStatus.Listener‬‭listener)‬
‭This‬ ‭method‬ ‭was‬ ‭deprecated‬ ‭in‬ ‭API‬ ‭level‬ ‭24.‬
‭use‬‭unregisterGnssStatusCallback(GnssStatus.Callback)‬‭instead.‬
‭void‬ ‭removeNmeaListener‬‭(‬‭OnNmeaMessageListener‬ ‭listener)‬
‭Remove an NMEA listener.‬
‭void‬ ‭removeNmeaListener‬‭(‬‭GpsStatus.NmeaListener‬‭listener)‬
‭This‬ ‭method‬ ‭was‬ ‭deprecated‬ ‭in‬ ‭API‬ ‭level‬ ‭24.‬
‭use‬‭removeNmeaListener(OnNmeaMessageListener)‬‭instead.‬
‭void‬ ‭removeProximityAlert‬‭(‬‭PendingIntent‬‭intent)‬
‭RemovestheproximityalertwiththegivenPendingIntent.‬
‭void‬ ‭removeTestProvider‬‭(‬‭String‬‭provider)‬
‭Removes The Mock Location Provider With The Given Name.‬
‭void‬ ‭removeUpdates‬‭(‬‭LocationListener‬‭listener)‬
‭RemovesalllocationupdatesforthespecifiedLocationListener.‬
‭void‬ ‭removeUpdates‬‭(‬‭PendingIntent‬‭intent)‬
‭Removesalllocationupdatesforthespecifiedpendingintent.‬
‭void‬ ‭requestLocationUpdates‬‭(‬‭String‬‭provider,‬ ‭long‬ ‭minTime,‬
‭float‬
‭ inDistance‬‭,‭L
m ‬ ocationListener‬‭listener)‬
‭Registerforlocationupdatesusingthenamedprovider,and pendingintent.‬

‭void‬ ‭requestLocationUpdates‬‭(long‬ ‭ inTime,‬


m
‭floatminDistance,‬‭Criteria‬

‭Criteria‬‭,‬‭LocationListener‬‭listener,‬ ‭Looper‬‭looper)‬ ‭Register‬ ‭for‬ ‭location‬ ‭updates‬

‭using Criteria,and callback the specified looper thread.‬

‭void‬ ‭requestLocationUpdates‬‭(long‬ ‭minTime,‬


‭floatminDistance,‬‭Criteria‬
‭c riteria‬‭,‬‭PendingIntent‬‭intent)‬
‭RegisterforlocationupdatesusingaCriteriaandpendingintent.‬
‭void‬ ‭requestLocationUpdates‬‭(‬‭String‬‭provider,‬ ‭long‬ ‭minTime,‬
‭floatminDistance‬‭,‬‭LocationListener‬‭lis‬
‭tener,‬‭Looper‬‭looper)‬
‭Registerforlocationupdatesusingthenamedprovider,and callback‬
‭onthespecifiedlooperthread.‬

‭void‬ ‭requestLocationUpdates‬‭(‬‭String‬‭provider,‬ ‭long‬ ‭minTime,‬


‭float‬
‭ inDistance‬‭,‭P
m ‬ endingIntent‬‭intent)‬
‭Register For Location updates using the named provider, anda pendingintent.‬

‭void‬ r‭ equestSingleUpdate‬‭(‬‭String‬‭provider,‬‭PendingIntent‬‭intent)‬
‭Registerforasinglelocationupdateusinganamedproviderandpendingintent.‬

‭void‬ ‭requestSingleUpdate‬‭(‬‭String‬‭provider,‬‭LocationListener‬‭listener,‬ ‭‬
L
‭o‬
‭o‬
‭p‬
‭e‬
‭r‬
l‭ ooper)‬
‭Registerforasinglelocationupdateusingthenamedproviderandacallback.‬

‭void‬ ‭requestSingleUpdate‬‭(‬‭Criteria‬ ‭c riteria,‬ ‭LocationListener‬

‭listener,‬‭Looper‬‭looper)‬
‭RegisterforasinglelocationupdateusingaCriteriaandacallback.‬
‭void‬ ‭requestSingleUpdate‬‭(‬‭Criteria‬‭c riteria,‬‭PendingIntent‬‭intent)‬
‭RegisterforasinglelocationupdateusingaCriteriaandpendingintent.‬

‭boolean‬ ‭sendExtraCommand‬‭(‬‭String Provider‬‭,‬‭String Command‬‭,‬‭Bundle Extras‬‭)‬

‭Send Additional Commands To Locationprovider.‬


‭void‬ ‭setTestProviderEnabled‬‭(‬‭String‬ ‭provider,‬ ‭boolean‬
‭enabled)Setsamockenabledvalueforthegiven‬
‭provider.‬

‭void‬ ‭setTestProviderLocation‬‭(‬‭String‬ ‭provider,‬‭Location‬


‭loc)Setsamocklocationforthegivenprovider.‬

‭void‬ ‭setTestProviderStatus‬‭(‬‭String‬‭provider, int‬ ‭status,‬ ‭Bundle‬ ‭extras,‬


‭long updateTime)Setsmock‬

‭statusvaluesforthe given provider.‬

‭void‬ ‭unregisterGnssMeasurementsCallback‬‭(‬‭GnssMeasurementsEvent.Callback‬‭c allback)‬


‭Unregister GPS Measurement callback.‬

‭void‬ ‭unregisterGnssNavigationMessageCallback‬‭(‬‭GnssNavigationMessage.Callb‬‭ack‬‭c allbac‬


‭k)‬
‭UnregistersaGNSSNavigationMessagecallback.‬

‭void‬ ‭unregisterGnssStatusCallback‬‭(‬‭GnssStatus.Callback‬ ‭c allback)‬


‭Remove siGNS statuscallback.‬

‭PermissionRequiredforGPSTracking‬
‭Only‬‭fine‬‭location‬‭will‬‭allow‬‭you‬‭access‬‭to‬‭gps‬‭data,‬‭and‬‭allows‬‭you‬‭access‬
‭toeverythingelsecoarselocationgives.Youcanusethemethodsofthe‬‭LocationManage‬
‭r‬‭to‬ ‭acquire‬ ‭location‬ ‭data‬ ‭from‬ ‭gps‬ ‭and‬ ‭cell‬ ‭tower‬ ‭sources‬ ‭already,you‬
‭donothavetoworkoutthisinformation yourself.‬
‭The main permissions you need‬
‭are‬‭android.permission.ACCESS_COARSE_LOCATIONorandroid.permission.ACCESS_‬
‭FINE_LOCATION.‬
‭This‬ ‭permission‬ ‭should‬ ‭allow‬ ‭your‬ ‭app‬ ‭to‬ ‭use‬ ‭location‬ ‭services‬ ‭through‬ ‭the‬
‭devicesGPS,Wi-Fi,and cell towers.Justplopitinyourmanifest Wherever Put Your‬

‭permissions,anditshoulddothetrick.Youcanfindalltheotherpermissionshere:(‬‭http://‬
‭developer.android.com/reference/android/Manifest.permission.html‬‭)‬
‭Hereisthecity:‬
‭<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>‬

‭LocationListener‬

‭public interface‬

‭LocationListener‬

‭android.location.LocationList‬

‭ener‬

‭Used‬ ‭for‬‭receiving‬‭notifications‬‭from‬‭the‬‭LocationManager‬‭when‬‭the‬‭location‬‭has‬‭changed.‬
‭These‬ ‭methods‬ ‭are‬ ‭called‬ ‭if‬ ‭the‬ ‭LocationListener‬ ‭has‬ ‭been‬ ‭registered‬ ‭with‬ ‭the‬ ‭location‬
‭manager‬ ‭service‬ ‭using‬ ‭therequestLocationUpdates(String,‬ ‭long,float,LocationListener)‬
‭method.‬

‭Public Methods‬

‭abstract void‬ ‭o nLocationChanged‬‭(‬‭Location‬ ‭location)‬


‭Called When The Location Has Changed.‬

‭abstract void‬ ‭o nProviderDisabled‬‭(‬‭String‬‭provider)‬


‭Calledwhentheprovider isdisabledbytheuser.‬

‭abstract void‬ ‭o nProviderEnabled‬‭(‬‭String‬‭provider)‬


‭Calledwhentheprovider isenabledbytheuser.‬

‭abstract void‬ ‭o nStatusChanged‬‭(‬‭String‬


‭pr‬
‭ov‬
‭id‬
‭er,‬
‭in‬
‭status,‬‭Bundle Extras‬‭)‬
‭Called When The Provider Status Changes.‬
‭voidonStatusChanged(Stringprovider,int status,Bundle Extras)‬

‭Called‬ ‭when‬ ‭the‬‭provider‬‭status‬‭changes.‬‭This‬‭method‬‭is‬‭called‬


‭when‬‭a‬‭provider‬‭is‬‭unable‬‭to‬‭fetch‬‭a‬‭location‬‭o r‬‭if‬‭the‬‭provider‬
‭has recently become available after a period of unavailability.‬
‭Parameters‬
‭providerString:thenameofthelocationproviderassociatedwiththisupdate.‬

‭statusint:‬ ‭OUT_OF_SERVICE‬‭if‬ ‭the‬ ‭provider‬ ‭is‬ ‭o ut‬ ‭o f‬ ‭service,‬ ‭and‬


‭this‬ ‭is‬ ‭not‬ ‭expected‬ ‭change‬ ‭in‬ ‭near‬
‭future;‬‭TEMPORARILY_UNAVAILABLE‬‭iftheprovideristemporarily‬
‭unavailable‬ ‭but‬ ‭is‬ ‭expected‬ ‭to‬ ‭be‬ ‭available‬ ‭shortly;‬ ‭and‬
‭AVAILABLE‬‭if theprovider iscurrentlyavailable.‬

‭extrasBundle:anoptionalBundlewhichwillcontainproviderspecificstatusvariables.‬

‭Anumberofcommonkey/valuepairsfortheextrasBundlearelistedb‬
‭elow.Providers‬‭that‬‭use‬‭any‬‭o f‬‭the‬‭keys‬‭o n‬‭this‬‭list‬‭must‬‭provide‬
‭the corresponding value as described below.‬

‭satellites-the number of satellites used to derive the fix‬


‭1.8‬ ‭AssignmentQuestion?‬

‭1.‬ ‭ExplainimportantstepsforTracethelocationusingGoogleMap?‬
‭2.‬ ‭Explain Important Steps For TracethelocationusingGPS?‬
‭3.‬ ‭Whataredifferenttypesofsensorsavailableinmobiledevice?‬
‭4.‬ ‭ExplainonProviderDisabledandonProviderEnabledmethod?‬
‭5.‬ ‭Explainlocation.getLatitude()andlocation.getLongitude()?‬

‭******* END *******‬

You might also like