JAVA CONCEPTS
&
BASICS OF ANDROID
INHERITANCE IN JAVA
Inheritance can be defined as the mechanism where one class acquires the
properties of another class. The class that inherits is called the child class or the
subclass whereas the class which is inherited is called the parent class or the
superclass.
The idea behind inheritance in Java is that you can create new class that are built
upon existing classes. When you inherit from an existing class, you can reuse
methods and fields of the parent class. Moreover, you can add new methods and
fields in your current class also.
“extends” is the keyword that is used to perform inheritance between classes.
Terminologies
o Class: A class is a group of objects which have common properties. It is a
template or blueprint from which objects are created.
o Sub Class/Child Class: Subclass is a class which inherits the other class. It is
also called a derived class, extended class, or child class.
o Super Class/Parent Class: Superclass is the class from where a subclass inherits
the features. It is also called a base class or a parent class.
o Reusability: As the name specifies, reusability is a mechanism which facilitates
you to reuse the fields and methods of the existing class when you create a new
class. You can use the same fields and methods already defined in the previous
class.
ACCESS MODIFIERS IN JAVA
Default Access Modifiers in Java
In the default stage, all the methods and classes, including the data members, are package-level.
Default Access Modifier in Java means the methods and classes are accessible only in one
particular or same package, which is a collection of related classes.
Private Access Modifiers in Java
Private Access Modifier in Java is a private keyword that is mainly used for a private class,
constructor, or method.
The methods of private modifiers can not be accessed by other users other than their native class.
The data members of private modifiers are only available in their defined class.
Protected Access Modifiers in Java
The methods and the members of Protected Access Modifiers in Java are only accessible and visible
to their classes and their inherited classes.
Protected Access Modifiers use the keyword "protected" to do the declaration.
This concept follows the Inheritance methods of object-oriented programming.
Public Access Modifiers in Java
Public Access Modifier in Java is used for making a method or data member accessible for everyone
and every platform.
This access modifier uses the "public" keyword to make the data public in Java.
Overriding In Java : It is when a child class has its method implementation for the method already
present in the parent class. Technically, overriding is a function that requires a subclass or child class to
provide a variety of method implementations, that are already provided by one of its super classes or
parent classes, in any object-oriented programming language.
OVERRIDING IN JAVA
Introduction to Android Studio
• Android studio is an IDE(Integrated Development Environment)
developed and managed by google, which is being used to develop
android application.
• Android studio provides auto generated code editor which means that
to write your XML java or kotlin code you need not to write it
completely it generates it for you.
• It's gradle feature helps you in compiling and building the application,
in short android studio is best IDE for Android app development. You
can download smart phone in android studio for simulation process.
ACTIVITY IN ANDROID
• An activity in Android is a specific combination of XML files and JAVA files. It
is basically a container that contains the design as well as coding stuff. XML
files provide the design of the screen and JAVA files deal with all coding.
• An activity is one screen of an app. In that way the activity is very similar to a
window in the Windows operating system. The most specific block of the user
interface is the activity. An Android app contains activities, meaning one or more
screens.
• Examples: Login screen, sign up screen, and home screen.
• An activity class is per definition a class in Android. Every application which has
UI must inherit it to create a window.
ACTIVITY LIFECYCLE
An activity goes through a number of states. Activity lifecycle in Android manages
the different states of activity, such as when the activity starts or stops, etc. All of
these states are managed by callback methods.
There are seven callback methods:-
• onCreate():- This callback method must be created by you, this is fired when
your activity is created by the system. For example, when you open the app it will
call onCreate(), onStart(), and onResume() methods. These three methods are
initiated when you open an app.
• onStart():- There should always be an onStart() callback after onCreate() finishes.
In the started state users will be able to see the activity but they are not ready for
user interaction.
• onResume():- In this, activities will be in the foreground and ready for user
interaction. You can understand the use of this callback from this example: “when the
user presses the phone’s answer button it will give onPause() after you end up calling
it will again give onResume()”.
• onPause():- This callback occurs when there is a case of another activity starting in
front of the current activity. It is the opposite of onResume(). An example for this
callback can be “when you open the app, that is another app from the notification bar,
or open settings then it will call onPause() and onStop()”.
• onStop():- It is the opposite of onStart(). In this case, activity will no longer be
visible to the users.
• onRestart():- This occurs when the activity is stopped and before the activity starts
again. It is a less common callback.
• onDestroy():- It is opposite of onCreate(). This starts when the system needs to free
memory or when finish() is called. It is used for cleanup which is a very common
activity.
setContentView In Android Studio
findViewById IN ANDROID STUDIO
It connects your backend code with the user interface elements, layouts, buttons
etc. Every component in the user interface has an ID associated with it, which
allows you to control its actions from the backend. Just pass the Id in the
findViewById function and store what it returns in another variable in your code.
View is whatever you can see on the mobile screen. So for instance, text view,
image view all these are view. So every view are given specific id so that we can
use it when we require. So id help in identifying the specific view. So whenever
an id is given to a view, an entry is made inside R.java class automatically and
findViewById(R.id.something) is the method that help you to find that specific
view from that class.
OnClickListener IN ANDROID STUDIO
• OnClickListener is a function in Java/Kotlin that handles Android I/O
Interface.
• OnClickListener tells the Application on what to do when you
press/hit a button.
• For example, when you hit the Buy Now button in Amazon App/Any
other App it takes you to Checkout/Billing Page, here OnClickListener
acts as a bridge between the Buy Now Button and Billing Page.
ANDROID PROJECT FOLDER STRUCTURE
Manifests Folder
Manifests folder contains AndroidManifest.xml for creating our android
application. This file contains information about our application such as the Android
version, metadata, states package for Kotlin file, and other application components.
It acts as an intermediator between android OS and our application.
Java folder
The Java folder contains all the java and Kotlin source code (.java) files
that we create during the app development, including other Test files.
Resource (res) folder
The resource folder is the most important folder because it contains all the non-code
sources like images, XML layouts, and UI strings for our android application.
res/drawable folder
It contains the different types of images used for the development of the application.
We need to add all the images in a drawable folder for the application development .
res/layout folder
The layout folder contains all XML layout files which we used to define the user
interface of our application. It contains the activity_main.xml file.
res/mipmap folder
This folder contains launcher.xml files to define icons that are used to show on the
home screen.
res/values folder
Values folder contains a number of XML files like strings, dimensions, colors, and
style definitions. One of the most important files is the strings.xml file which
contains the resources.