lab file€¦ · 2. what is difference between arraylist and linkedlist? 3. what is difference...

46
Department : Computer Engineering Class :TE COMPUTER Semester : I Pune Vidyarthi Griha’s College of Engineering, Nashik-4 LAB FILE Subject :SDL Faculty : Prof.Prasad A. Lahare

Upload: others

Post on 24-Jun-2020

16 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Department : Computer Engineering

Class :TE COMPUTER Semester : I

Pune Vidyarthi Griha’s

College of Engineering, Nashik-4

LAB FILE

Subject :SDL

Faculty : Prof.Prasad A. Lahare

Page 2: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Sr. No. Aim of Experiment

1Design a system with the help of advance data structures in Java and enhance the system

using collections and generics.

2Enhance the above system with the help of socket programming use client server

architecture.

3Enhance above system by using JDBC, Multithreading, concurrency, synchronous and

asynchronous callbacks, ThreadPools using ExecutorService.

4 Transform the above system from command line system to GUI based application

5 Download Install and Configure Android Studio on Linux/windows platform

6 Design a mobile app for 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.

9 Mini Project on Advanced JAVA and Mobile Application Development

Academic Year :2019-20 Semester : I

Subject Teacher HOD

Pune Vidyarthi Griha’s

College Of Engineering, Nashik-4

LIST OF EXPERIMENTS

Department :Computer Engineering

Name of lab :PL-II

Subject :SDL

Page 3: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

SD Module-1 Advanced JAVA

Assignment No. 1

Title:

Design a system with the help of advance data structures in Java and enhance the system using collections and generics.

Problem Definition: Write a Java program for perform the various operation on Student database like Add Student, Delete, Search, Failed Student List etc.

1.1 Prerequisite:

Basic concepts of Advance Data Structure Java.

Concepts of Collection and Generics.

1.2 Software Requirements:

Eclipse SDK

1.3 Tools/Framework/Language Used:

Concepts of Collection and Generics.

1.4 Hardware Requirement:

PIV, 2GB RAM, 500 GB HDD, Lenovo A13-4089 Model.

1.5 Learning Objectives: Understand the implementation of the various legacy Advance Data Structure and new

Collection framework.

1.6 Outcomes: After completion of this assignment students can evaluate and analyze the problem and solve by Advance data structures and Collection framework concept.

1.7 Theory Concepts:

The data structures provided by the Java utility package are very powerful and perform a wide range of functions. These data structures consist of the following interface and classes −

Enumeration

BitSet

Vector

Stack

Dictionary

Hashtable

Properties

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4 1

Page 4: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

All these classes are now legacy and Java-2 has introduced a new framework called Collections Framework, which is discussed in the next chapter. −

The Enumeration

The Enumeration interface isn't itself a data structure, but it is very important within the context of other data structures. The Enumeration interface defines a means to retrieve successive elements from a data structure. For example, Enumeration defines a method called nextElement that is used to get the next element in a data structure that contains multiple elements.

The BitSet

The BitSet class implements a group of bits or flags that can be set and cleared individually. This class is very useful in cases where you need to keep up with a set of Boolean values; you just assign a bit to each value and set or clear it as appropriate.

The Vector The Vector class is similar to a traditional Java array, except that it can grow as necessary to accommodate new elements.

Like an array, elements of a Vector object can be accessed via an index into the vector. The nice thing about using the Vector class is that you don't have to worry about setting it to a specific size upon creation; it shrinks and grows automatically when necessary.

The Stack

The Stack class implements a last-in-first-out (LIFO) stack of elements. You can think of a stack literally as a vertical stack of objects; when you add a new element, it gets stacked on top of the others. When you pull an element off the stack, it comes off the top. In other words, the last element you added to the stack is the first one to come back off.

. The Dictionary The Dictionary class is an abstract class that defines a data structure for mapping keys to values. This is useful in cases where you want to be able to access data via a particular key rather than an integer index. Since the Dictionary class is abstract, it provides only the framework for a key-mapped data structure rather than a specific implementation.

The Hashtable

The Hashtable class provides a means of organizing data based on some user-defined key structure. For example, in an address list hash table you could store and sort data based on a key such as ZIP code rather than on a person's name. The specific meaning of keys with regard to hash tables is totally dependent on the usage of the hash table and the data it contains.

The Properties Properties is a subclass of Hashtable. It is used to maintain lists of values in which the key is a String and the value is also a String. The Properties class is used by many other Java classes. For example, it is the type of object returned by System.getProperties( ) when obtaining environmental values.

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4 2

Page 5: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

Prior to Java 2, Java provided ad hoc classes such as Dictionary, Vector, Stack, and Properties to store and manipulate groups of objects. Although these classes were quite useful, they lacked a central, unifying theme. Thus, the way that you used Vector was different from the way that you used Properties.

The collections framework was designed to meet several goals, such as –

The framework had to be high-performance. The implementations for the fundamental collections (dynamic arrays, linked lists, trees, and hashtables) were to be highly efficient. The framework had to allow different types of collections to work in a similar manner and with a high degree of interoperability. The framework had to extend and/or adapt a collection easily. Towards this end, the entire collections framework is designed around a set of standard interfaces. Several standard implementations such as LinkedList, HashSet, and TreeSet, of these interfaces are provided that

you may use as-is and you may also implement your own collection, if you choose.

A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain the following –

Interfaces − These are abstract data types that represent collections. Interfaces allow collections to be

manipulated independently of the details of their representation. In object-oriented languages, interfaces generally form a hierarchy. Implementations, i.e., Classes − These are the concrete implementations of the collection interfaces. In

essence, they are reusable data structures. Algorithms − These are the methods that perform useful computations, such as searching and sorting, on

objects that implement collection interfaces. The algorithms are said to be polymorphic: that is, the same

method can be used on many different implementations of the appropriate collection interface.In addition to collections, the framework defines several map interfaces and classes. Maps store key/value pairs. Although maps are not collections in the proper use of the term, but they are fully integrated with collections.

The Collection Interfaces

The collections framework defines several interfaces. This section provides an overview of each interface −

Sr.No. Interface & Description

1

2

3

4

5

6

7

8

The Collection Interface This enables you to work with groups of objects; it is at the top of the collections hierarchy.

The List Interface

This extends Collection and an instance of List stores an ordered collection of elements.

The Set This extends Collection to handle sets, which must contain unique elements.

The SortedSet

This extends Set to handle sorted sets.

The Map This maps unique keys to values.

The Map.Entry

This describes an element (a key/value pair) in a map. This is an inner class of Map.

The SortedMap This extends Map so that the keys are maintained in an ascending order.

The Enumeration

This is legacy interface defines the methods by which you can enumerate (obtain one at a time) the

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4 3

Page 6: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

elements in a collection of objects. This legacy interface has been superceded by Iterator.

The Collection Classes Java provides a set of standard collection classes that implement Collection interfaces. Some of the classes provide full implementations that can be used as-is and others are abstract class, providing skeletal implementations that are used as starting points for creating concrete collections. The standard collection classes are summarized in the following table −

Sr.No. Class & Description

1 AbstractCollection Implements most of the Collection interface.

2

3

4

5

AbstractList Extends AbstractCollection and implements most of the List interface.

AbstractSequentialList Extends AbstractList for use by a collection that uses sequential rather than random access of its elements.

LinkedList Implements a linked list by extending AbstractSequentialList.

ArrayList

Implements a dynamic array by extending AbstractList.

6

7

8

9

AbstractSet Extends AbstractCollection and implements most of the Set interface.

HashSet

Extends AbstractSet for use with a hash table.

LinkedHashSet Extends HashSet to allow insertion-order iterations.

TreeSet

Implements a set stored in a tree. Extends AbstractSet.

10 AbstractMap Implements most of the Map interface.

11 HashMap Extends AbstractMap to use a hash table.

12 TreeMap Extends AbstractMap to use a tree.

13 WeakHashMap Extends AbstractMap to use a hash table with weak keys.

14 LinkedHashMap Extends HashMap to allow insertion-order iterations.

15 IdentityHashMap Extends AbstractMap and uses reference equality when comparing documents.

The AbstractCollection, AbstractSet, AbstractList, AbstractSequentialList and AbstractMap classes provide skeletal implementations of the core collection interfaces, to minimize the effort required to implement them.

The following legacy classes defined by java.util have been discussed in the previous chapter −

Sr.No. Class & Description 1 Vector

This implements a dynamic array. It is similar to ArrayList, but with some differences. 2 Stack PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4 4

Page 7: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

3

4

5

6

Stack is a subclass of Vector that implements a standard last-in, first-out stack.

Dictionary Dictionary is an abstract class that represents a key/value storage repository and operates much like Map.

Hashtable

Hashtable was part of the original java.util and is a concrete implementation of a Dictionary.

Properties Properties is a subclass of Hashtable. It is used to maintain lists of values in which the key is a String and the value is also a String.

BitSet A BitSet class creates a special type of array that holds bit values. This array can increase in size as needed.

1.8. Design and Program Flow: 1. Declaration of Class Student Read and Display Student details like Student roll no, name and marks. 2. Declaration of Class Teacher then write menu driven program and perform the various opeartion like Add Student details, delete Student record using roll no, search student details using roll no, find out failed student list based on input marks set for pass and fails.etc. 3. using ArrayList and Operation class use the Scanner or DataInputStream classes for same.

1.8.1 Conclusion:

In this way advance data structures collection framework is useful for abstract class,

providing skeletal implementations that are used as starting points for creating concrete collections.

1.9 Assignment Questions: [ Write at least 5point in comparison ]

1. What is the difference between Array and Vector? 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap?

4. What is difference between List and Set? 5. What is difference between Abstract Class and Interface?

1. 9.1 Oral Questions: [Write short answer ]

1. What is Collection ? What is a Collections Framework ? What are the benefits of Java Collections Framework ? 2. Name the core Collection interfaces ?

3. What is the difference between Map and Set ? 4. What are the classes implementing List and Set interface ?

5. What is the difference between Iterator and Enumeration ?

1.9.2 References:

1. http://javahungry.blogspot.com/2015/05/50-java-collections-interview-questions-and-answers.html

2. https://www.tutorialspoint.com

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4 5

Page 8: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

SD Module-1 Advanced JAVA

Assignment No. 2

Title : Enhance the above system with the help of socket programming use client server architecture.

Problem Definition:

Write a Java Program with the help of Socket Programming using Cilent Server Architecture Perform Various

Operation on Student database like Add Student, Search Student, Deleted Student and Failed Student List etc. 1.1 Prerequisite:

Basic concepts of JDBC and Socket Programming.

Concepts of Client Server Architecture and there Database Connectivity.

1.2 Software Requirements:

Eclipse SDK

1.3 Tools/Framework/Language Used:

JDBC Driver Manager, MySQL.

1.4 Hardware Requirement:

PIV, 2GB RAM, 500 GB HDD, Lenovo A13-4089 Model.

1.5 Learning Objectives:

Understand the implementation of Client Server Architecture Using Socket Programming Concept.

1.6 Outcomes: After completion of this assignment Students able to design and implement Client Server Architecture with help of Socket Programming.

1.7 Theory Concepts:

Java Socket programming is used for communication between the applications running on different JRE.

Java Socket programming can be connection-oriented or connection-less.

Socket and ServerSocket classes are used for connection-oriented socket programming and DatagramSocket and DatagramPacket classes are used for connection-less socket programming.

The client in socket programming must know two information:

1. IP Address of Server, and 2. Port number.

. Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASHIK-4 1

Page 9: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

Socket class A socket is simply an endpoint for communications between the machines. The Socket class can be used to create a socket.

Important methods

Method Description

1) public InputStream getInputStream() returns the InputStream attached with this socket.

2) public OutputStream getOutputStream() returns the OutputStream attached with this socket.

3) public synchronized void close() closes this socket

ServerSocket class The ServerSocket class can be used to create a server socket. This object is used to establish communication with the clients.

Important methods

Method Description

1) public Socket accept() returns the socket and establish a connection between server and client.

2) public synchronized void close() closes the server socket.

Sample Code for Server

ServerSocket ss=new ServerSocket(6666);

Socket s=ss.accept();//establishes connection DataInputStream dis=new DataInputStream(s.getInputStream());

String str=(String)dis.readUTF();

System.out.println("message= "+str); ss.close();

Sample Code for Client

Socket s=new Socket("localhost",6666); DataOutputStream dout=new DataOutputStream(s.getOutputStream());

dout.writeUTF("Hello Server");

dout.flush();

dout.close(); s.close();

Java DatagramSocket class

Java DatagramSocket class represents a connection-less socket for sending and receiving datagram packets. A datagram is basically an information but there is no guarantee of its content, arrival or arrival time.

Commonly used Constructors of DatagramSocket class

DatagramSocket() throws SocketEeption: it creates a datagram socket and binds it with the available Port Number on the localhost machine.

DatagramSocket(int port) throws SocketEeption: it creates a datagram socket and binds it with the given Port Number.

DatagramSocket(int port, InetAddress address) throws SocketEeption: it creates a datagram socket and binds it with the specified port number and host address.

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASHIK-4 2

Page 10: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

Java DatagramPacket class

Java DatagramPacket is a message that can be sent or received. If you send multiple packet, it may arrive in

any order. Additionally, packet delivery is not guaranteed.

Commonly used Constructors of DatagramPacket class DatagramPacket(byte[] barr, int length): it creates a datagram packet. This constructor is used to

receive the packets. DatagramPacket(byte[] barr, int length, InetAddress address, int port): it creates a datagram

packet. This constructor is used to send the packets.

Java InetAddress class represents an IP address. The java.net.InetAddress class provides methods to get the

IP of any host name

InetAddress ip=InetAddress.getByName("www.snjb.org”);

System.out.println("Host Name: "+ip.getHostName()); System.out.println("IP Address: "+ip.getHostAddress());

The Java HttpURLConnection class is http specific URLConnection. It works for HTTP protocol only.

By the help of HttpURLConnection class, you can information of any HTTP URL such as header information, status code, response code etc.

The java.net.HttpURLConnection is subclass of URLConnection class.

URL url=new URL("http://www.snjb.org");

HttpURLConnection huc=(HttpURLConnection)url.openConnection();

The Java URLConnection class represents a communication link between the URL and the application. This class can be used to read and write data to the specified resource referred by the URL.

URL url=new URL("http://www.snjb.org"); URLConnection urlcon=url.openConnection();

InputStream stream=urlcon.getInputStream();

1.8.1 Design and Program Flow:

1. Write Student.java program for Display the Student details like Roll no, name and marks. 2. Write Client.java program Perform Various Operation on Student database like Add Student,

Search Student, Deleted Student and Failed Student List etc. 3. Write Operation.java program perform various Operations using ArrayList. 4. Write ServerDemo.java program for Connection establishment with Client.

1.8.2 Conclusion:

In this assignment student are able to understand and implement Client Server Architecture using Socket Program concept.

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASHIK-4 3

Page 11: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

1.9 Assignment Questions: 1. What is Socket? 2. What is DataInputStream Class?

3. What is DataOutputStream Class? 4. What is Port number, IP Address and Local Host name?

5. What is Datagram Socket?

1. 9.1 Oral Questions:

1. Define Network Programming? 2. What is a Socket? 3. Advantages of Java Sockets and Disadvantages of Java Sockets?

4. Which class is used by server applications to obtain a port and listen for client requests? 5.Which class represents the socket that both the client and server use to communicate with each other?

1.9.2 References :

1. https://www.tutorialspoint.com/java/java_interview_questions.htm

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASHIK-4 4

Page 12: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

SD Module-1 Advanced JAVA

ASSIGNMENT NO – 03

Title :-

Enhance above system by using JDBC, Multithreading, concurrency, synchronous and asynchronous callbacks, Thread Pools using Executor Service.

Problem Definition:

Write a Java program with the help of JDBC and Multithreading Perform Various Operation on Student database like Add Student, Search Student, Deleted Student and Failed Student List etc.

1.1 Prerequisite:

Basic concepts of JDBC

Concepts of Multithreading, Concurrency, Synchronous and Asynchronous callbacks.

1.2 Software Requirements:

Eclipse SDK

1.3 Tools/Framework/Language Used:

JDBC Connectivity Driver and MySQL.

1.4 Hardware Requirement:

PIV, 2GB RAM, 500 GB HDD, Lenovo A13-4089 Model.

1.5 Learning Objectives:

Understand the implementation of JDBC and Multithreading Concept.

1.6 Outcomes: After completion of assignment student are able to implement the concept of JDBC and Multithreading Concept in easy ways.

1.7 Theory Concepts: Java JDBC is a java API to connect and execute query with the database. JDBC API uses jdbc drivers to connect with the database.

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASHIK-4 1

Page 13: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

Before JDBC, ODBC API was the database API to connect and execute query with the database. But, ODBC API uses ODBC driver which is written in C language (i.e. platform dependent and unsecured). That is why Java has defined its own API (JDBC API) that uses JDBC drivers (written in Java language).

JDBC Driver

JDBC Driver is a software component that enables java application to interact with the database.There are 4 types of JDBC drivers:

1. JDBC-ODBC bridge driver 2. Native-API driver (partially java driver) 3. Network Protocol driver (fully java driver)

4. Thin driver (fully java driver) 1) JDBC-ODBC bridge driver

The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The JDBC-ODBC bridge driver converts JDBC method calls into the ODBC function calls. This is now discouraged because of thin driver.

Advantages:

easy to use. can be easily connected to any database.

Disadvantages:

Performance degraded because JDBC method call is converted into the ODBC function calls. The ODBC driver needs to be installed on the client machine.

There are 5 steps to connect any java application with the database in java using JDBC. They are as follows:

Register the driver class Creating connection

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASHIK-4 2

Page 14: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

Creating statement Executing queries

Closing connection

Multithreading in Java

Multithreading in java is a process of executing multiple threads simultaneously. Thread is basically a lightweight sub-process, a smallest unit of processing. Multiprocessing and

multithreading, both are used to achieve multitasking. But we use multithreading than multiprocessing because threads share a common memory area. They

don't allocate separate memory area so saves memory, and context-switching between the threads takes less time than process.

Java Multithreading is mostly used in games, animation etc.

Advantages of Java Multithreading

1) It doesn't block the user because threads are independent and you can perform multiple operations at same time.

2) You can perform many operations together so it saves time.

3) Threads are independent so it doesn't affect other threads if exception occur in a single thread.

Multitasking

Multitasking is a process of executing multiple tasks simultaneously. We use multitasking to utilize the CPU.

Multitasking can be achieved by two ways:

Process-based Multitasking(Multiprocessing)

Thread-based Multitasking(Multithreading)

1) Process-based Multitasking (Multiprocessing)

Each process have its own address in memory i.e. each process allocates separate memory area.

Process is heavyweight. Cost of communication between the process is high. Switching from one process to another require some time for saving and loading registers,

memory maps, updating lists etc.

2) Thread-based Multitasking (Multithreading)

Threads share the same address space. Thread is lightweight.

Cost of communication between the thread is low.

What is Thread in java

A thread is a lightweight sub process, a smallest unit of processing. It is a separate path of execution.

Threads are independent, if there occurs exception in one thread, it doesn't affect other threads. It shares a common memory area. Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASHIK-4 3

Page 15: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

Life Cycle of Thread

A thread can be in one of the five states. According to sun, there is only 4 states in thread life cycle in java new, runnable, non-runnable and terminated. There is no running state.

But for better understanding the threads, we are explaining it in the 5 states.

The life cycle of the thread in java is controlled by JVM. The java thread states are as follows:

1. New 2. Runnable

3. Running 4. Non-Runnable (Blocked)

5. Terminated

Java Thread pool represents a group of worker threads that are waiting for the job and reuse many times.

In case of thread pool, a group of fixed size threads are created. A thread from the thread pool is pulled out and assigned a job by the service provider. After completion of the job, thread is contained in the thread pool again.

Advantage of Java Thread Pool

Better performance It saves time because there is no need to create new thread.

Real time usage

It is used in Servlet and JSP where container creates a thread pool to process the request.

Synchronous and Asynchronous Thread Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASHIK-4 4

Page 16: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

When you execute something synchronously, you wait for it to finish before moving on to another task. When you execute something asynchronously, you can move on to another task before it finishes.

That being, said, in the context of computers this translates into executing a process or task on another

"thread." A thread is a series of commands--a block of code--that exists as a unit of work. The operating

system can manage multiple threads and assign a thread a piece ("slice") of processor time before switching to another thread to give it a turn to do some work. At its core (pardon the pun), a processor can simply execute

a command--it has no concept of doing two things at one time. The operating system simulates this by allocating slices of time to different threads.

Now, if you introduce multiple cores/processors into the mix, then things CAN actually happen at the same time. The operating system can allocate time to one thread on the first processor, then allocate the same block of time to another thread on a different processor.

All of this is about allowing the operating system to manage the completion of your task while you can go on in your code and do other things. Asynchronous programming is a complicated topic because of the semantics of how things tie together when you can do them at the same time.

Thread Pool Executor:-

Java thread pool manages the pool of worker threads, it contains a queue that keeps tasks waiting to get executed. We can use ThreadPoolExecutor to create thread pool in java.

1.8.1 Design and Program Flow: 1. Write Student.java program for Display the Student details like Roll no, name and marks. 2. Write Client.java program Perform Various Operation on Student database like Add Student,

Search Student, Deleted Student and Failed Student List etc. 3. Write Operation.java program perform various Operations using ArrayList.

4. Write ServerDemo.java program for Connection establishment with Client. 5. Write Db.java program for Open and Close Connection using MySql.

1.8.2 Conclusion:

In this way Student able to implement the JDBC and Multithreading Concept in java successfully in this assignment.

1.9 Assignment Questions:

1. What is Multithreading? 2. What is the difference between preemptive scheduling and time slicing? 3. What is difference between wait() and sleep() method?

4. What is synchronization? 5. What are the JDBC API components?

1. 9.1 Oral Questions: 1. What are the JDBC statements? 2. What is the role of JDBC DriverManager class?

3. What is batch processing and how to perform batch processing in JDBC? 4. What does the JDBC ResultSet interface?

5. What is Thread Pool?

1.9.2 References : https://www.javatpoint.com/jdbc-interview-questions Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASHIK-4 5

Page 17: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

SD Module-1 Advanced JAVA

Assignment No. 4

Title :- Transform the above system from command line system to GUI based application

Problem Definition:

Write a Java program with the help of GUI based Application Perform Various Operation on Student database like Add Student, Search Student, Deleted Student and Failed Student List etc.

1.1 Prerequisite:

Basic concepts of AWT and Event in Java.

Concepts of Swing in java.

1.2 Software Requirements:

Eclipse SDK

1.3 Tools/Framework/Language Used:

Concepts of Swing and AWT.

1.4 Hardware Requirement:

PIV, 2GB RAM, 500 GB HDD, Lenovo A13-4089 Model

1.5 Learning Objectives: Understand the implementation of the GUI based Application using Swing , AWT Concept.

1.6 Outcomes: After completion of this assignment student are able to implement the concept of Swing and AWT in GUI based Application in easy way.

1.7 Theory Concepts:

Java AWT (Abstract Window Toolkit) is an API to develop GUI or window-based applications in java.

Java AWT components are platform-dependent i.e. components are displayed according to the view of operating system. AWT is heavyweight i.e. its components are using the resources of OS.

The java.awt package provides classes for AWT api such as TextField, Label, TextArea, RadioButton, CheckBox, Choice, List etc.

Java AWT Hierarchy The hierarchy of Java AWT classes are given below.

Container

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASHIK – 4. 1

Page 18: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

The Container is a component in AWT that can contain another components like buttons, textfields, labels etc. The classes that extends Container class are known as container such as Frame, Dialog and Panel.

Window

The window is the container that have no borders and menu bars. You must use frame, dialog or another window for creating a window.

Panel

The Panel is the container that doesn't contain title bar and menu bars. It can have other components like button, textfield etc.

Frame

The Frame is the container that contain title bar and can have menu bars. It can have other components like button, textfield etc.

Useful Methods of Component class

Method Description

public void add(Component c) inserts a component on this component.

public void setSize(int width,int height) sets the size (width and height) of the component.

public void setLayout(LayoutManager m) defines the layout manager for the component.

public void setVisible(boolean status) changes the visibility of the component, by default false.

To create simple awt example, you need a frame. There are two ways to create a frame in AWT.

By extending Frame class (inheritance) By creating the object of Frame class (association)

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASHIK – 4. 2

Page 19: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

Swing

Java Swing tutorial is a part of Java Foundation Classes (JFC) that is used to create window-based

applications. It is built on the top of AWT (Abstract Windowing Toolkit) API and entirely written in java.

Unlike AWT, Java Swing provides platform-independent and lightweight components.

The javax.swing package provides classes for java swing API such as JButton, JTextField, JTextArea, JRadioButton, JCheckbox, JMenu, JColorChooser etc.

Difference between AWT and Swing

There are many differences between java awt and swing that are given below.

No. Java AWT

1) AWT components are platform-dependent. 2) AWT components are heavyweight. 3) AWT doesn't support pluggable look and feel.

4) AWT provides less components than Swing.

AWT doesn't follows MVC(Model View Controller) where 5) model represents data, view represents presentation and

controller acts as an interface between model and view.

The hierarchy of java swing API is given below.

Java Swing Java swing components are platform-

independent.

Swing components are lightweight.

Swing supports pluggable look and feel.

Swing provides more powerful components such as tables, lists, scrollpanes, colorchooser, tabbedpane etc.

Swing follows MVC.

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASHIK – 4. 3

Page 20: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

Commonly used Methods of Component class

The methods of Component class are widely used in java swing that are given below.

Method public void add(Component c) public void setSize(int width,int height)

Description add a component on another component.

sets size of the component.

public void setLayout(LayoutManager m) sets the layout manager for the component.

public void setVisible(boolean b) sets the visibility of the component. It is by default false.

Java Swing Examples

There are two ways to create a frame:

By creating the object of Frame class (association)

By extending Frame class (inheritance)

We can write the code of swing inside the main(), constructor or any other method.

Java ActionListener Interface

The Java ActionListener is notified whenever you click on the button or menu item. It is notified against

ActionEvent. The ActionListener interface is found in java.awt.event package. It has only one method: actionPerformed().

The Java MouseListener is notified whenever you change the state of mouse. It is notified against MouseEvent. The MouseListener interface is found in java.awt.event package. It has five methods.

The Java ItemListener is notified whenever you click on the checkbox. It is notified against ItemEvent. The ItemListener interface is found in java.awt.event package. It has only one method: itemStateChanged().

The Java KeyListener is notified whenever you change the state of key. It is notified against KeyEvent. The KeyListener interface is found in java.awt.event package. It has three methods.

The Java WindowListener is notified whenever you change the state of window. It is notified against WindowEvent. The WindowListener interface is found in java.awt.event package. It has three methods.

Java adapter classes provide the default implementation of listener interfaces. If you inherit the adapter class, you

will not be forced to provide the implementation of all the methods of listener interfaces. So it saves code.

The adapter classes are found in java.awt.event, java.awt.dnd and javax.swing.event packages. The Adapter classes with their corresponding listener interfaces are given below.

java.awt.event Adapter classes

Adapter class Listener interface

WindowAdapter WindowListener

KeyAdapter KeyListener

MouseAdapter MouseListener

MouseMotionAdapter MouseMotionListener

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASHIK – 4. 4

Page 21: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

FocusAdapter FocusListener

ComponentAdapter ComponentListener

ContainerAdapter ContainerListener

HierarchyBoundsAdapter HierarchyBoundsListener

1.8.1 Design and Program Flow: 1. Write Student.java program for Display the Student details like Roll no, name and marks. 2. Write Client.java program Perform Various Operation on Student database like Add Student,

Search Student, Deleted Student and Failed Student List etc. 3. Write Operation.java program perform various Operations using ArrayList.

4. Write ServerDemo.java program for Connection establishment with Client. 5. Write Db.java program for Open and Close Connection using MySql.

6. Write ClientUI.java program for design GUI based application to perform all operation.

1.8.2 Conclusion:

In this way now students are able to implement the GUI based application using Swing concept successfully.

1.9 Assignment Questions: 1. What is Event-Dispatcher-Thread (EDT) in Swing? 2. What are differences between Swing and AWT?

3. Why Swing components are called lightweight components? 4. What is Action Listener?

5. What is Event?

1. 9.1 Oral Questions:

1. What is JFC? 2. What is Layout Manager? 3. What is Spring Layout?

4. What is Box Layout? 5. What is Gridbag Layout?

1.9.2 References :

1. https://www.javatpoint.com/java-springlayout

Pune Vidyarthi Griha’s COLLEGE OF ENGINEERING, NASHIK – 4. 5

Page 22: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

SD Module-1 Android Dvelopment

Experiment No: 05

1.1 Aim: Download Install and Configure Android Studio on Linux/windows platform.

1.2 Prerequisites:

Microsoft® Windows® 10/8/7/Vista/2003 32 or 64−bit

Java JDK1.7 or later version

Java Runtime Environment JRE6

Android Studio

1.3 Learning Objective:

Understand the Installation and configuration of the Android Studio.

New Concepts:

Android Studio

1.4 Software used / Programming Languages Used:

JDK

Android studio

64bit Ubuntu Os or equivalent

1.5 Theory:

Download the latest version of android studio from Android Studio 2.2 , named as android-

studio-bundle-143.3101438-windows.exe.So just download and run on windows machine

according to android studio wizard guideline.

If you are installing Android Studio on Mac or Linux, You can download the latest version

from Android Studio Mac Download,or Android Studio Linux Download, check the instructions

provided along with the downloaded file for Mac OS and Linux.

Installation:

Once you launched Android Studio, its time to mention JDK7 path or later version in android

studio installer

Page 23: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

.

Below the image initiating JDK to android SDK

Page 24: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

Need to check the components, which are required to create applications, below the image has

selected Android Studio, Android SDK, Android Virtual Machine and performance.

Page 25: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

Need to specify the location of local machine path for Android studio and Android SDK, below

the image has taken default location of windows 8.1 x64 bit architecture.

Page 26: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

Need to specify the RAM space for Android emulator by default it would take 512MB of local

machine RAM.

Page 27: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

At final stage, it would extract SDK packages into our local machine, it would take a while time

to finish the task and would take 2626MB of Hard disk space.

After done all above steps perfectly, you must get finish button and it gonna be open android

studio project with Welcome to android studio message as shown below

Page 28: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

You can start your application development by calling start a new android studio project. in a

new installation frame should ask Application name, package information and location of the

project.

Page 29: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

After entered application name, it going to be called select the form factors your application runs

on, here need to specify Minimum SDK, in our tutorial, I have declared as API23: Android

6.0Marshmallow

The next level of installation should contain selecting the activity to mobile, it specifies the

default layout for Applications

Page 30: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

At the final stage it going to be open development tool to write the application code.

Create Android Virtual Device:

To test your Android applications, you will need a virtual Android device. So before we start

writing our code. Launch Android AVD Manager Clicking AVD_Manager icon as shown below

Page 31: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

After Click on a virtual device icon, it going to be shown by default virtual devices which are

present on your SDK, or else need to create a virtual device by clickingCreate new Virtual

device button

If your AVD is created successfully it means your environment is ready for Android application

development. If you like, you can close this window using top-right cross button. Better you re-

start your machine and once you are done with this last step, you are ready to proceed for your

first Android example but before that we will see few more important concepts related to

Android Application Development.

Page 32: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

Hello Word Example:

Before Writing a Hello word code, you must know about XML tags.To write hello word code,

you should redirect to App>res>layout>Activity_main.xml

To show hello word, we need to call text view with layout ( about text view and layout, you must

take references at Relative Layout and Text View ).

<RelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

android:paddingBottom="@dimen/activity_vertical_margin"

tools:context=".MainActivity">

<TextView android:text="@string/hello_world"

android:layout_width="550dp"

android:layout_height="wrap_content" />

</RelativeLayout>

Need to run the program by clicking Run>Run App or else need to call shift+f10key. Finally,

result should be placed at Virtual devices as shown below

Page 33: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

Signature of staff with Date

Questions:

1. List the features of Android Studio

2. Explain Android Layered Architecture

3. Write Short note on Delvik virtual Machine

Page 34: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

Page 35: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

Experiment No: 06

1.1 Aim: Design a mobile app for media player.

1.2 Prerequisites:

Microsoft® Windows® 10/8/7/Vista/2003 32 or 64−bit

Java JDK1.7 or later version

Java Runtime Environment JRE6

Android Studio

1.3 Learning Objective: To study and implementation of mobile application for media player

1.4 Software used (if applicable) / Programming Languages Used:

Android Studio

Windows 7/8/10 32 bit/64 bit or Ubuntu 64 bit

JDK 1.7 or later

1.5 Theory:

Actually, the first thing you do is create an activity. These are where all the action happens,

because they are the screens that allow the user to interact with your app. In short, activities

are one of the basic building blocks of an Android application.

In this introduction to Android activities tutorial, you’ll dive into how to work with activities.

You’ll work through creating a to-do list app named Forget Me Not and along the way learn:

The process for creating, starting and stopping an activity and handle navigation

between activities.

The various stages in the lifecycle of an activity and how to handle each stage

gracefully.

The way to manage configuration changes and persist data within your activity.

Activity Lifecycle:

Before firing up your fingers, indulge yourself in a bit of theory.

As mentioned earlier, activities are the foundations upon which you build screens for your

app. They encompass multiple components the user can interact with, and it’s likely that

your app will have multiple activities to handle the various screens you create.

Page 36: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

Having all these activities doing different things makes it sound like developing an Android

app is a complicated undertaking.

Fortunately, Android handles this with specific callback methods that initiate code only

when it’s needed. This system is known as the activity lifecycle.

Handling the various lifecycle stages of your activities is crucial to creating a robust and

reliable app. The lifecycle of an activity is best illustrated as a step pyramid of different

stages linked by the core callback methods:

Following the diagram above, you can picture the lifecycle in action as it courses through

your code. Take a closer look at each of the callbacks:

onCreate(): When you first create an activity, you also call this method. This also

where you initialize any UI elements or data objects. You also have the

savedInstanceState of the activity that contains its previously saved state, and you

can use it to recreate that state.

onStart(): Just before presenting the user with an activity, this method is called. It’s

always followed by onResume() and very rarely by onStop(). In here, you generally

should start UI animations, audio based content or anything else that requires the

activity’s contents to be on screen.

onResume(): Before bringing an activity back to the foreground, you call this

method. Here you have a good place to restart animations, update UI elements,

Page 37: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

restart camera previews, resume audio/video playback or initialize any components

that you release during onPause().

onPause(): Before sliding into the background, this method is called. Here you

should stop any visuals or audio associated with the activity such as UI animations,

music playback or the camera. This method is followed by onResume() if the

activity returns to the foreground or by onStop() if it becomes hidden.

onStop(): You call this method right after onPause(), but before the activity goes into

the background, and it’s a good place to save data that you want to commit to the

disk. It’s followed by either onRestart(), if this activity is coming back to the

foreground, or onDestroy() if it’s being released from memory.

onRestart(): After stopping an activity, but just before starting it again, you call this

method. It’s always followed by onStart().

onDestroy(): This is the final callback you’ll receive from the system before the

activity is destroyed. A call to finish() is one way to destroy the activity, or it can be

triggered by the system when it needs to recoup memory. If your activity includes

any background threads or other long-running resources, destruction could lead to a

memory leak if they’re not released, so you need to remember stop these processes

here as well.

So many methods to remember! In the next section, you’ll see some of these lifecycle

methods in action, and then it’ll be a lot easier to remember what everything does.

Creating an Activity:

Keeping the activity lifecycle in mind, take a look at an activity in the sample project. Open

MainActivity, you’ll see that onCreate.

Here’s a play-by-play of what’s happening above:

You call onCreate() on the superclass; remember that this is always the first thing

you should do in a callback method.

You tell the WindowManager to make your activity’s window full screen.

You set the content view of your activity with the corresponding layout file resource.

Page 38: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

Here you initialize all the UI and data variables. In this case, you’re using a

TextView to show the current date and time, a button to add tasks to your list, a

ListView to display your list, and an ArrayList to hold your data. You can find the

implementation of all these UI elements in the activity_main.xml file.

Here you initialize and set the Adapter that will handle the data for your ListView.

You set an OnItemClickListener() for the ListView to capture the user’s tap on

individual list entries.

Starting an Activity:

In its current stat, the app is a fairly useless lump of ones and zeros because you can’t add

anything to the to-do list. You have the power to change that, and that’s exactly what you’ll

do next.

In the MainActivity file you have open, add a field to the top of the class:

private final int ADD_TASK_REQUEST = 1;

You’ll use this variable to reference your request to add new tasks later on. You can assign

any int value to ADD_TASK_REQUEST. If it returns the value you entered on the request, you

can assume your request was handled successfully. More on this later. Then add the

following implementation for addTaskClicked:

Intent intent = new Intent(MainActivity.this, TaskDescriptionActivity.class);

startActivityForResult(intent, ADD_TASK_REQUEST);

When the user taps the add a task button, you call addTaskClicked. Here you create an

Intent to launch the TaskDescriptionActivity from MainActivity. It needs to produce

a result from TaskDescriptionActivity, because the app needs to know if there is a new

task to add to your list or not. To accomplish this, you start the activity using

startActivityForResult(...). When the TaskDescriptionActivity

finishes, it returns a result in an intent to the onActivityResult(...) method. Implement

this callback to receive the result by adding the following method to the bottom of

MainActivity: All appears to be well and good, but is it really?

Not quite. Forget Me Not needs to be able to move to another activity and extract task

descriptions from it, so the next thing you’ll do is make one.

Page 39: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

Creating an Activity:

Android Studio makes it very easy to create an activity. All you need do is right-click on the

package where you want to add the activity; in this case, the package is

com.raywenderlich.todolist). Then navigate to New\Activity, and the choose Empty Activity,

which is a basic template for an activity.

On the next screen, you enter the Activity Name and Android Studio will automatically fill

the other fields based on that. Enter the activity name as TaskDescriptionActivity.

Android Studio will automatically generate the corresponding resources needed to create the

activity. These are:

Class: The class file is named TaskDescriptionActivity.java and located in your Java

package. This is where you implement the activity’s behavior. This class must

subclass the Activity class or an existing subclass of it.

Layout: The layout file is located under res/layout and named

activity_task_description.xml. It defines the placement of different UI elements on

the screen when the activity is created.

1.6 Questions:

What is activity lifecycle?

How to create an activity in android studio?

What is emulator?

Page 40: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

Experiment No: 07

1.1 Aim: Design a mobile app to store data using internal or external storage.

1.2 Prerequisites:

Microsoft® Windows® 10/8/7/Vista/2003 32 or 64−bit

Java JDK1.7 or later version

Java Runtime Environment JRE6

Android Studio

Storage media

1.3 Learning Objectives:

To study and implement mobile application to fetch data from sdcard.

1.4 Software used (if applicable) / Programming Languages Used:

64-bit Ubuntu or equivalent OS with 64-bit Intel-i5/i7

Java 1.7.0/Android studio

1.5 Theory:

To show all the images from SD Card and Phone Memory in Grid View. It Just the basic and

beginning of Grid View with images. You can enhance your code by adding some more

Codes and Ideas Like below.

You can filter the Images according to Date.

You can Open the Images in Another Activity and customize it.

You can add Tick Marks or can Show icon near corner in Grid View for Making the

Image Favourite.

Requirements :

1. Classes-

MainActivity - Coding of Finding Images from SD Card and

2. GridView Adapter - Adapter Sets the Images in the Grid Form whatever it Get the

Data. Different Adapter will set the Same Data in Different Layout in Different Forms.

3. ViewHolder Pattern Class - View Holder is a Pattern we User for Recycling the

Page 41: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

Resources. It only Create the Resources (FindViewById()) we are seeing. And Keep on

Replacing the Inner Data like images,text and any other Resources. So their is no need to

create more findViewById() objects and It better to Re-Paint the House then Building a

New House and Paint Another Colour which also Require Space.

FileOutnputStream methods are listed below −

Sr.No Method & description

1 FileOutputStream(File file, boolean append)

This method constructs a new FileOutputStream that writes to file.

2

getChannel()

This method returns a write-only FileChannel that shares its position with

this stream

3

getFD()

This method returns the underlying file descriptor

4

write(byte[] buffer, int byteOffset, int byteCount)

This method Writes count bytes from the byte array buffer starting at

position offset to this stream

FileInputStream methods are listed below −

Sr.No Method & description

1 available()

This method returns an estimated number of bytes that can be read or

Page 42: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

skipped without blocking for more input

2

getChannel()

This method returns a read-only FileChannel that shares its position with

this stream

3

getFD()

This method returns the underlying file descriptor

4

read(byte[] buffer, int byteOffset, int byteCount)

This method reads at most length bytes from this stream and stores

them in the byte array b starting at offset

1.6 Questions:

What is android studio?

How one can run the android application ?

Page 43: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

Experiment No: 08

1.1 Aim: Mobile Application Development for tracing the location

1.2 Prerequisites:

Microsoft® Windows® 10/8/7/Vista/2003 32 or 64−bit

Java JDK1.7 or later version

Java Runtime Environment JRE6

Android Studio

GPS(Global Positioning System)

1.3 Learning Objectives: Develop an application for tracing the location through GPS

1.4 Software used (if applicable) / Programming Languages Used:

• 64-bit Ubuntu or equivalent OS with 64-bit Intel-i5/i7

• Java 1.7/Android studio

1.5 Theory:

GPS Technology:

Global Positioning System (GPS) technology has been around for many years, providing

geographic data that are fed off of satellites to many different industries that require such

information (Hoffman-Wellenhof, 2001). It has widened the capabilities of military, civil and

commercial industry in acting as an enabling factor in new services. In the context of mobile

technology, most of the current and upcoming smart phones are equipped with GPS receiver that

allow the technology to be manipulated to invent new applications to meet the different needs of

users. Google Maps:

The technology behind the maps that we see on most websites and mobile phones are of the

mapping service offered by Google. In 2005, Google Maps API was launched that allow

developers to incorporate map functionality into their websites without any charge. In addition to

displaying a map, Google also offers other relevant API service that allows users to retrieve

certain information such as images to generating driving directions and geographic data.

Page 44: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

Location and Google Play Services:

Android has two basic ways to determine a user’s location. The first is to use the built-in location

APIs that have been available since Android was first introduced. These still work, but not as

well as the newer location APIs bundled as part of the beast known as Google Play Services

Google Play Services is a bundle of services and APIs from Google that we can use for lots of

features in Android apps. They are installed on a majority of devices and run on Android 2.3 and

up. There are a lot of different parts of Google Play Services, but we will see how to include

them in a project and use them for detecting location in a quick and effective way.

Getting the Current Location:

Using maps in an app no longer require extra permissions, but accessing the location of the

device still does. The required permissions should already be in your AndroidManifest.xml file

from the template, but check to make sure these two are there:

<!--

The ACCESS_COARSE/FINE_LOCATION permissions are not required to use

Google Maps Android API v2, but are recommended.

-->

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Page 45: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

Logging the Current Location:

When our client finally connects to the location services, the onConnected() method will be

called. We just added an empty shell for that method using the Quick Fix, but now we can get

the last known location and log it.

Add the following line in the onConnected() method

Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);

Requesting Location Updates:

Now that we’ve done the bare minimum about getting a location, let’s go one step further and

learn how to request location updates. This is especially important when, as mentioned earlier,

the last known location is not available from the fused location provider we are using. It also

becomes particularly important in an app that tracks the user’s location, like a run-tracking or

navigation app.

We need to implement one more interface: LocationListener. Add this to the list of interfaces

implemented in the class declaration, but when you do, make sure you import the Google Play

Services version of LocationListener, not the regular Android version! Check this screenshot to

see the difference based on the different packages:

This is what our class declaration should now look like:

public class MapsActivity extends FragmentActivity implements

GoogleApiClient.ConnectionCallbacks,

GoogleApiClient.OnConnectionFailedListener,

LocationListener {

Showing a Location on a Map:

Let’s finish this simple app with a quick lesson on how to add a marker on a map for a given

location. We will show the user’s current location and then center the map on it. The generated

code from this project template makes this very easy to do!

Page 46: LAB FILE€¦ · 2. What is difference between ArrayList and LinkedList? 3. What is difference between HashTable and HashMap? 4. What is difference between List and Set? 5. What is

Skill Development Laboratory Third Year Computer Engineering

PUNE VIDYARTHI GRIHA’S COLLEGE OF ENGINNERING, NASHIK-4

Take a look at the setUpMap() method that is already in our class. When running this app we

have already seen how a default map marker is added at latitude/longitude of 0, 0. This is the line

of code that adds that marker:

private void setUpMap() {

mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));

}

All we need to do is write this same line with the new latitude and longitude values available in

our Location variable.

Conclusion:

We have developed an application using android for tracing location using GPS technology

Questions:

Q1. Explain methods of Google Map class.