Android With Java
Android With Java
XML- Designing
FIREBASE/SQLITE/APIs-
Firebase- Database
Introduction of JAVA
Java was developed by team of sun microsystem whose leader was James Gosling in 1991. Java
is the successor version of C++. Code was written in C and C++ programming languages. Java
supports all the concept of OOP that is Class, object, inheritance, polymorphism, constructor,
encapsulation, abstraction etc. The all concept of java makes the java most easier, portable,
and secure programming language.
Features of JAVA:
Compiled and interpreted : Java source code firstly compiled and converted into
byte code that calls class file(.class) then class files interpreted and displays the
output of program.
Platform independent : Most important feature of java is Platform independent.
Java follows the concept “Write once and run anywhere”. Code written in one
machine can easily run in any other machines.
Secure : Java is the most secured programming language. Many concept of C
programming like goto, pointer is not present in java. Because java does not
provide direct access of memory without authorization.
Object Oriented Programming: Java provides concept of code-reusability,
integrity and many other concept of OOP. That makes codes re-usable and
managed. Code written once can be used in many way.
OOPs : In object oriented programming, you need to put each instruction under
the block of class. One java program may contain multiple classes, out of all one
class must should contain Main function.
The main function is the place from where interpreter starts the execution.
Class: Class is the collection of data member(variable) and member
function(method).
Class is the collection of multiple methods that behaves same.
Naming Convention :
All classes starts with uppercase letter.(Pascal naming conventions).
class MathematicalOperation
All packages is written in lowercase letters. Some pre-defined packages of java
is : util , lang , io , etc.
All methods of java is written in Camel case naming convention.
Void addNumber.
Syntax:
class class_name
{
//data_mambers(variables)
//functions
}
class MyFirstClass
{
//main methods
public static void main(String arg[])
{
System.out.print(“Hello world of Java”);
}
}
User Input in Java : To take a value input from user, we need some pre-defined
functions. These pre-defined functions provide option to initialize a variable at
run time by asking a value from user on console screen.
All user input pre-defined functions are stored in Scanner class. And scanner
class is a part of util package.
To add a pre-defined functions are stored in program import is used:
Import java.util.*;//imports all classes of util package.
Import java.util.Scanner;//imports only Scanner class of util package.
To access any user input functions, firstly you need to create object of Scanner
class.
//how to create object of Scanner class:
Class_name obj_name=new class_name(parameters);
Scanner sc=new Scanner(System.in);
Lang Package
Math Class – min(), max(), pow(), sqrt(), floor(), ceil(), round()
no argument – ()
//create a UDF to add two numbers by using No return type and no arguments
int n1=50,n2=70;
System.out.print(“Addition = ”+(n1+n2));
//statement;
}
Return type and no arguments :
int addNumber()
Polymorphism :
Polymorphism is a concept of OOP to use same name function with different working.
In a class we can not create same name function two times, but polymorphism provides a
concept to use same function multiple times in same class.
Polymorphism is collection of Poly+Morphism. Poly means many and Morphism means form.
To use same functions in many form is the purpose of polymorphism.
Ex:
class CLS1
class CLS1
{
}
Constructor : constructor is a method of any class that has same name as the
class. A single class may have more than one overloaded constructor.
Constructor is always public, if class of constructor will not be public then it will
restrict object creation of the class.
We do not need to call constructor explicitly, it is automatically called by
controller when we create the object of the class.
Constructor do not have any return type not even void.
class ConstructEx
{
public ConstructEx()//constructor
{
}
}
Every class has an implicit constructor. That constructor is used to initialize default value to
the instance variable of class. Implicit constructor runs in the absence of explicit constructor.
class Calculator
{
Calculator() //default constructor
{
}
}
Class Calculator
{
Calculator(int a,int b)//parameterized constructor
{
}
Calculator(double c,double d)//parameterized constructor
{
}
Calculator()//default constructor
{
}
}
Note: Constructor contains some instructions, that is executed each time
when object of class is created.
Constructor is mainly used to initialize instance variables of class.
Class Student
If you are declaring a parameterized constructor in a class then you must have to pass actual
parameters at the time of object creation.
Note : Parameterized constructor is used to take value from the caller and initialize value of it’s
parameters to take the instance variable.
Button : Button
textSize
textColor
textFontStyle
LinearLayout
RelativeLayout
ConstraintLayout
FrameLayout
Message Print :
Logcat : developer
Toast : application
Toast – class
makeText(this,””,duration) – function
syntax :
TextView Print
}
2. Bind onClickListener event to the button
Exception Handling : Exception is the run time error which caused termination of the
app. Exceptions are some unwanted situation of programs that may interrupt the
execution of program.
Exceptions are generated because wrong entries in program.
Firstly try block is executed, if there is no Exception in try block then catch block
does not executed. Catch is executed only in case try throws an exception.
Multiple catch may present with one try block, if you want to handle different
type of Exceptions differently. Catch should be present just after the block of try.
Syntax :
try
//statement
catch(Exception_class_obj)
catch(Exception_class_obj)
catch(Exception_class_obj)
A finally block may present with each try block. This finally block executes in each cases
either try throws an error or not.
Implicit intent is used to transfer control from one activity to another within same application.
Explicit Intent is used to transfer control from one activity to another in different applications.
Ex : open camera on click of button, open flashlight on click of button, open gallery, open
whatsapp.
Types of Intent :
1. Implicit Intent
2. Explicit Intent
Implicit Intent :
To open next activity from current activity in same application, implicit intent is used. Intent
class is used to create object of implicit intent.
To finally start the activity “startActivity()” method is used. Which takes parameter of a intent
class obj :
startActivity(intent_class_obj);
ex : startActivity(intent)
The class that is inheriting the members is known as child class or derived class or sub class and
which members are inherited is known as parent class or base class or super class.
By using inheritance all public and protected members can be accessed in child class but private
members(instance variable, methods)can not be accessed in child class.
Types of inheritance :
1. Single inheritence
2. Multiple inheritence(Interface)
3. Multi-level inheritence
4. Hierarchical inheritance
class Math //parent/base/super class
//variables
//methods
In java a single class can not inherit more than class, because java does not support multiple
inheritence. So in this case, concept of interface is used.
Adapter :
Adapter works as a bridge between a sample view and a layout. It is used to create a view that
can be add in any layouts.
FragmentStateAdapter is a abstract class. Abstract class may have abstract any non-abstract
type methods.
When a class have any one abstract method then it must should be declared as abstract class.
When a class inherits a abstract class, it have to implement each abstract method of parent
class.
Abstract methods are those methods which have only declaration not definition. Abstract
methods are defined within child class. Abstract methods are declared with abstract keyword.
Foreach Loop : Foreach loop is used to access each element of a collection. Foreach can
only be applied on a collection like Array, list, ArrayList, HashMap etc.
Foreach loop access each element from start index to the last.
Syntax :
Ex:
System.out.println(i);
System.out.prntln(“******************************************”);
To create a Adapter for recyclerView, java class is inherited from the Abstract class called
RecyclerView.Adapter.
onCreateView(){
}
onBindViewHolder(){
getItemCount(){
return total_item_of_recyclerView;
return (super.itemView)