Based on the lectures, please write a 4-5 page speech paper and prepare a ppt presentation summarizing your findings for the study in java programming topics. The presentation will consist of your...

1 answer below »






Based on the lectures, please write a 4-5 page speech paper and prepare a ppt presentation summarizing your findings for the study in java programming topics. The presentation will consist of your major findings, analysis, and recommendations in a presentation of 4-5 slides. Your ppt should include visual support. Please write the speech according to slides and DO NOT copy and paste directly from lectures pdf. Each slide takes about 1-2 speechpage to present and read so please make plans for that accordingly. Thank you very much.





Web application development Week4 AGENDA • Inheritance and Interfaces • ArrayLists • Java Collections Framework Inheritance – What is Inheritance is an important pillar of OOP(Object-Oriented Programming). It is the mechanism in java by which one class is allowed to inherit the features(fields and methods) of another class. In Java, inheritance means creating new classes based on existing ones. A class that inherits from another class can reuse the methods and fields of that class. In addition, you can add new fields and methods to your current class as well. Inheritance – Why use • Code Reusability: The code written in the Superclass is common to all subclasses. Child classes can directly use the parent class code. • Method Overriding: Method Overriding is achievable only through Inheritance. It is one of the ways by which java achieves Run Time Polymorphism. • Abstraction: The concept of abstract where we do not have to provide all details is achieved through inheritance. Abstraction only shows the functionality to the user. https://www.geeksforgeeks.org/abstraction-in-java-2/ Inheritance – Terminologies • Class: Class is a set of objects which shares common characteristics/ behavior and common properties/ attributes. Class is not a real-world entity. It is just a template or blueprint or prototype from which objects are created. • Super Class/Parent Class: The class whose features are inherited is known as a superclass(or a base class or a parent class). • Sub Class/Child Class: The class that inherits the other class is known as a subclass(or a derived class, extended class, or child class). The subclass can add its own fields and methods in addition to the superclass fields and methods. • Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to create a new class and there is already a class that includes some of the code that we want, we can derive our new class from the existing class. By doing this, we are reusing the fields and methods of the existing class. Inheritance – How to use The extends keyword is used for inheritance in java. Using the extends keyword indicates you are derived from an existing class. In other words, “extends” refers to increased functionality. Syntax: class derived-class extends base-class { //methods and fields } Inheritance – Demo • We’ll practice a demo on inheritance. • In this example, Bicycle here is a base class. • Continue next slide…. Inheritance – Demo • MountainBike here is a derived class that extends the Bicycle class. • Continue next slide…. Inheritance – Demo • And finally, Inheritance is a driver class to run the program. Interface – What is • An interface in Java is a blueprint of a class. It has static constants and abstract methods. • The interface in Java is a mechanism to achieve abstraction. There can be only abstract methods in the Java interface, not method body. It is used to achieve abstraction and multiple inheritance in Java. • In other words, you can say that interfaces can have abstract methods and variables. It cannot have a method body. • Java Interface also represents the IS-A relationship. Interface – Why use There are mainly three reasons to use interface: Interface – How to declare • An interface is declared by using the interface keyword. It provides total abstraction; means all the methods in an interface are declared with the empty body, and all the fields are public, static and final by default. A class that implements an interface must implement all the methods declared in the interface. • Syntax: interface interface_name { // declare constant fields // declare methods that abstract // by default. } Interface – Relationship with classes A class extends another class, an interface extends another interface, but a class implements an interface. Interface – Demo • In this first example, the Interface class implements the interface printable. Output: Hello Interface – Demo In this example, we will demonstrate a real-world example of Interface implemented by a class. Continue next slide… Interface – Demo In this example, we will demonstrate a real-world example of Interface implemented by a class. Continue next slide… Interface – Demo In this example, we will demonstrate a real-world example of Interface implemented by a class. Output: Interface – Demo In this similar example, we will demonstrate a second real-world example of Interface implemented by a class. Continue next slide… Interface – Demo In this example, we will demonstrate a real-world example of Interface implemented by a class. Continue next slide… Interface – Demo In this example, we will demonstrate a real-world example of Interface implemented by a class. Output: ArrayLists – What is • In Java, we need to declare the size of an array before we can use it. Once the size of an array is declared, it's hard to change it. • To handle this issue, we can use the ArrayList class. It allows us to create resizable arrays. • Unlike arrays, arraylists can automatically adjust their capacity when we add or remove elements from them. Hence, arraylists are also known as dynamic arrays. ArrayLists – How to use • Before using ArrayList, we first need to import the java.util.ArrayList package. Here is how we can create arraylists in Java: ArrayList arrayList= new ArrayList<>(); In the above, Type indicates the type of an arraylist. For example: // create Integer type arraylist ArrayList arrayList = new ArrayList<>(); // create String type arraylist ArrayList arrayList = new ArrayList<>(); • In the above program, we used Integer not int. It is because we cannot use primitive types while creating an arraylist. Instead, we have to use the corresponding wrapper classes. Here, Integer is the corresponding wrapper class of int. ArrayLists – Methods ArrayLists – Example ArrayLists – Demo 1 ArrayLists – Demo 2 ArrayLists – Demo 3 Collections Framework • Java Collections Framework is one of the core parts of the Java programming language. Collections are used in almost every programming language. Most of the programming languages support various type of collections such as List, Set, Queue, Stack, etc. Collections Framework – What is • Collections are like containers that group multiple items in a single unit. For example, a jar of chocolates, a list of names, etc. • Collections are used in every programming language and when Java arrived, it also came with few Collection classes – Vector, Stack, Hashtable, Array. • Java 1.2 provided Collections Framework that is the architecture to represent and manipulate Collections in java in a standard way. • Java Collections Framework consists of the following parts: (next slide) Framework – Interfaces • Java Collections Framework interfaces provides the abstract data type to represent collection. • java.util.Collection is the root interface of Collections Framework. It is on the top of the Collections framework hierarchy. It contains some important methods such as size(), iterator(), add(), remove(), clear() that every Collection class must implement. • Some other important interfaces are java.util.List, java.util.Set, java.util.Queue and java.util.Map. The Map is the only interface that doesn’t inherit from the Collection interface but it’s part of the Collections framework. All the collections framework interfaces are present in java.util package. Framework – Implementation classes • Java Collections framework provides implementation classes for core collection interfaces. We can use them to create different types of collections in the Java program. • Some important collection classes are ArrayList, LinkedList, HashMap, TreeMap, HashSet, and TreeSet. These classes solve most of our programming needs but if we need some special collection class, we can extend them to create our custom collection class. • Java 1.5 came up with thread-safe collection classes that allowed us to modify Collections while iterating over them. Some of them are CopyOnWriteArrayList, ConcurrentHashMap, CopyOnWriteArraySet. These classes are in java.util.concurrent package. • All the collection classes are present in java.util and java.util.concurrent package. Framework – Algorithms • Algorithms are useful methods to provide some common functionalities such as searching, sorting and shuffling. Framework – Class diagram • Below class diagram shows Collections Framework hierarchy. For simplicity, I have included only commonly used interfaces and classes. Collections Framework – Benefits Java Collections framework have following benefits: • Reduced Development Effort – It comes with almost all common types of collections and useful methods to iterate and manipulate the data. So we can concentrate more on business logic rather than designing our collection APIs. • Better Quality – Using core collection classes that are well-tested increases our program quality rather than using any home-developed data structure. • Reusability and Interoperability • Reduce effort to maintain because everybody knows Collection API classes. Collections Framework – API Interfaces • Java collection interfaces are the foundation of the Java Collections Framework. Note that all the core collection interfaces are generic; for example public interface Collection. The syntax is for Generics and when we declare Collection, we should use it to specify the type of Object it can contain. It helps in reducing run-time errors by type-checking the Objects at compile-time. • To keep the number of core collection interfaces manageable, the Java platform doesn’t provide separate interfaces for each variant of each collection type. If an unsupported operation is invoked, a collection implementation throws an UnsupportedOperationException. https://www.digitalocean.com/community/tutorials/java-generics-example-method-class-interface Framework – Collection Interface • This is the root of the collection hierarchy. A collection represents a group of objects known as its elements. The Java platform doesn’t provide any direct implementations of this interface. • The interface has methods to tell you how many elements are in the collection (size, isEmpty), to check whether a given object is in the collection (contains), to add and remove an element from the collection (add, remove), and to provide an iterator over the collection (iterator). • Collection interface also provides bulk operations methods that work on the entire collection – containsAll, addAll, removeAll, retainAll, clear. • The toArray methods are provided as a bridge between collections and older APIs that expect arrays on input. Framework – Iterator Interface Iterator interface provides methods to iterate over the elements of the Collection. We can get the instance of iterator using iterator() method. Iterator takes the place of Enumeration in the Java Collections Framework. Iterators allow the caller to remove elements from the underlying collection during the iteration. Iterators in collection classes implement Iterator Design Pattern. Framework – Set Interface • Set is a collection that cannot contain duplicate elements. This interface models the mathematical set abstraction and is used to represent sets, such as the deck of cards. • The Java platform contains three general-purpose Set implementations: HashSet, TreeSet, and LinkedHashSet. Set interface doesn’t allow random-access to an element in the Collection. You can use iterator or foreach loop to traverse the elements of a Set. Framework – List Interface • List is an ordered collection and can contain duplicate elements. You can access any element from its index. List is more like array with dynamic length. List is one of the most used Collection type. ArrayList and LinkedList are implementation classes of List interface. • List interface provides useful methods to add an element at a specific index, remove/replace element based on the index and to get a sub-list using the index. • Collections class provide some useful algorithm for List – sort, shuffle, reverse, binarySearch etc. List strList = new ArrayList<>(); //add at last strList.add(0, "0"); //add at specified index strList.add(1, "1"); //replace strList.set(1, "2"); //remove strList.remove("1"); Framework – Queue Interface • Queue is a collection used to hold multiple elements prior to processing. Besides basic Collection operations, a Queue provides additional insertion, extraction, and inspection operations. • Queues typically, but do not necessarily, order elements in a FIFO (first-in-first-out) manner. Among the exceptions are priority queues, which order elements according to a supplied comparator or the elements’ natural ordering. Whatever the ordering used, the head of the queue is the element that would be removed by a call to remove or poll. In a FIFO queue, all new elements are inserted at the tail of the queue. Framework – Dequeue Interface • A linear collection that supports element insertion and removal at both ends. The name deque is short for “double-ended queue” and is usually pronounced “deck”. Most Deque implementations place no fixed limits on the number of elements they may contain, but this interface supports capacity-restricted deques as well as those with no fixed size limit. • This interface defines methods to access the elements at both ends of the deque. Methods are provided to insert, remove, and examine the element. Framework – Map Interface • Java Map
Answered 3 days AfterDec 09, 2023

Answer To: Based on the lectures, please write a 4-5 page speech paper and prepare a ppt presentation...

Gyanendra answered on Dec 13 2023
19 Votes
Speech
Inheritance:
1. Inheritance in Java is a mechanism in which one object acquires
all the properties and behaviours of a parent object. It is an
important part of OOPs.
2. In Java, Inheritance is like family traits for code
. Classes inherit
qualities from parent classes, making coding efficient and
organized. It's like passing down family traditions, but in the
world of programming. Let’s understand in simple way:
a. Family Resemblance: Inheritance is like kids inheriting traits
from their parents. In Java, one class (the child) can inherit traits
(methods and properties) from another class (the parent).
b. Reusing the Good Stuff: It's about reusing the code that
works well.
c. Adding Our Flavour: While the child class inherits traits, it can
also add its own unique touches. This is like the new ruler
bringing their personal style to the kingdom.
d. Keeping It Organized: Inheritance helps organize the code.
Similar classes are grouped together, making the code easier to
manage.
e. Easier Maintenance: When we need to change something in
the family's traditions, we update the parent class, and the child
classes get benefit from those updates automatically.

3. Inheritance defines the 'IS-A relationship' between a super class
and its sub class.
4. The main use of inheritance is code reusability. The extends
keyword indicates that you are making a new class that derives
from an existing class. The meaning of "extends" is to increase
the functionality.
5. In the terminology of Java, a class which is inherited is called a
parent or superclass, and the new class is called child or
subclass.
Interface
1. It is used to achieve abstraction and multiple
inheritance in Java.
2. An interface is a blueprint of a class, it tells you what to do
but not how to do it. It only contains the name of the
method and the parameter types of a method. It is
completely abstract. It is not an implementation.
3. Interfaces are used by developers to achieve total
abstraction (privacy) and multiple inheritance in Java. See
example of an interface below:

This interface defines a single abstract method, fly (). Any class
that implements the IFlyable interface must provide a concrete
implementation for this method.

4. Below class implements the IFlyable interface by...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here