Tuesday, December 31, 2019

Android Studio

Android Studio

Android Studio is the official IDE for android app development. IDE stands for an integrated development environment. Android studio is a platform base on Intellij IDEA. It provides the interface for developers to create, compile, build, and control their mobile apps. Android Studio provides a smart interface and environment and performance. Several services are integrated with this IDE like VCS, Firebase, and GIT. Android studio is enriched with several advanced features provided like auto-suggestion, presentation mode, instant run, and intelligent color-coded code editor.

The features of Android Studio

  • The powerful, robust, flexible and automated build system
  • Integrated Firebase cloud support
  • Highly optimized for all android devices
  • Layout editor with drag and drop enabled with different screen size previews
  • APK and DEX Analyser
  • Inbuilt C++ and NDK support
  • Regular update support for all platform components
  • Support for both Kotlin and Java programming languages
  • Fast and customizable emulator support
  • Flexible Gradle-based build system.
  • Build variants and multiple APK generation.
  • Expanded template support for Google Services and various device types.
  • Rich layout editor with support for theme editing.
  • Lint tools to catch performance, usability, version compatibility, and other problems.
  • ProGuard and app-signing capabilities.
  • Built-in support for Google Cloud Platform, making it easy to integrate Google Cloud Messaging and App Engine.

Download link for Android Studio

This is the official download link for downloading latest version of Android Studio.

Android Background

Android Background

Android is an open-source and Linux-based Operating System for mobile devices such as smartphones, tablet computers, Wearable devices, Auto and Televisions. Android is the world's most popular mobile platform. It was designed as "smart mobile devices that are more aware of its owner's location and preferences", However, the initial design of Android was to Develop an Operating System for Digital Cameras. Android is the brainchild of Andy Rubin, Rick Miner, Nick Sears, and Chris White. Soon, the creators of Android realized that the market space of Digital camera operating systems was not enough.

At earlier stages, Android had two competitors Symbian and Microsoft Windows mobile.

Google acquired Android Inc. in 2005. On November 5, 2007, google unveiled Android. It was the first product of the Open Handset Alliance and was the start of Google movement towards Smartphone business. On 23 Sept 2018, the First installment of the Android Operating System in a device was launched. Soon, Apple IOS and Android became the biggest competitors in the Smartphone business. Thereafter various versions of Android are launched, generally named after sweet dishes.

Android is mostly written in C, C++, and Java programming languages.

Android Now

The latest version of Android is Android 10.0, released on September 3, 2019, on Google's Pixel devices.

Android is designed for a wide range of devices, from small handheld mobile devices with a small screen to large-sized Television having large screen sizes. There are basically four form factors available for Android OS named Mobile Phone/Tablets, Wearable devices, Auto (for cars and Automobiles) and Televisions. Most of the devices are based on touch screen interaction between the user and the device. Now voice commands and gesture recognition are also playing their roles. Hardware buttons are getting diminished with time. The devices are getting lean, powerful and cheaper with the passage of time.

Devices are getting smarter and smarter with the newer versions of Android. Several new cutting edge technologies are also getting incorporated with the latest versions.


What is Android?


Android is an open-source operating system and was developed for portable mobile devices having a limited battery. Power Management is the core issue to develop operating systems for such devices. Android uses a modified version of the Linux kernel and other open-source software.

Defining Android

Definition of Android can be summarized with the following three points
  • An open-source operating system
  • A software stack having libraries, classes and other resources to develop applications (APPs), capable of running on devices installed with Android OS.
  • Devices, installed with the Android operating system.

Recently, Android became the leading operating system worldwide, as Android becomes the world's most popular operating system for getting online. Android is installed on more than 40% of computing devices all over the world now.

Android OS is composed of different layers(Android Software Stack). Each layer has several programs, APIs, Libraries and classes. Each Layer is responsible to provide some services and interfaces to the layer just above it.

Devices can be Mobile phones/Tablets, Wearable devices (Wristwatches), Auto (Automobile navigation and infotainment systems), and smart televisions.

Saturday, December 28, 2019

Understanding the variables in java

Understanding the variables in java


A variable is something in a program that is liable to change. A variable is a mere holder or container to hold some value and is identified by some identifier(symbolic representation).

for example

int speed=60;

We have declared a variable identified by speed, data type int, and the value assigned by "="(assignment operator), which is 60. The value assigned to a variable can be changed later in the program. The variable's identifier must be preceded by its data type. A variable must be declared before it is used in a program.

java variables

The Java programming language defines the following kinds of variables:
  • Instance Variables (Non-Static Fields) 
  • Class Variables (Static Fields)
  • Local Variables
  • Parameters

Instance Variables

Each instance of the class has its own copy of this variable. Any non-static field or attribute of a class is an instance variable. We need to create an object of the class to use the instance variable.

Class Variables

Any static variable of the class is known as the class variable. We do not need to create the objects of the class to access these variables. Read this Java tutorial for more details on the static keyword in Java. These variables belong to the class, not to the individual objects.

Local Variables

Local variables are declared and within the body of any block, method, or constructor. Their scope is limited to that particular block, method, or constructor.


The parameters are passed between the parenthesis of the method declaration.  

Video Tutorial:-

Classes and Objects in java

Classes and Objects in java


Class is a set of objects. Class is used to classify, things having common attributes and behaviors. For example, the Student is a class in which all people studying can be kept. The class provides the structure for the Object. The class can be considered as a Blueprint, Template, or Factory to create identically structured and behavioral objects.

Class Dog with multiple objects
Class Dog with multiple objects


The object is an abstract data type. The object has attributes, behavior, identity, or the state. An object is an instance of the class. A programming language is said to object-oriented programming language if it is object-based and has the power of polymorphism and inheritance. For example class Dog with the attribute, color can have many dog objects with different colors

The relation between Class and Object 

  • Class is a logical construct
  • An object is a physical reality
  • An object is an instance of a class

Classes and Objects in Java
Classes and Objects in Java

A Java class can contain the declarations of variables and methods.

java class variables and methods
Java class

The class can have three kinds of members in Java.

  • Fields
  • Methods
  • Nested Classes and Interfaces
We can also nest other classes and interfaces in a class.

Example of Class members

public class Employee { //class declaration

int emp_id;            //Attributes/fields(static or non static)
String emp_name;
int basic_sal;

public void displaySalary() //method(static or non static)

class Address                 //nested class
      String city;
      String state;
      String pin;

Class modifiers

Java also has four class modifiers


"public" means the class is accessible its own package and other than this package. Any class with no modifier is only accessible in its own package. 


"abstract" modifier means that the class is Abstract Class, having one or more abstract methods. The abstract methods are incomplete methods or methods without implementation.


A "final" declared class can not be inherited by the subclasses. The "final " keyword with a class is used to restrict the inheritance(read Inheritance in Java).


"strictfp" means that the strict floating-point evaluation will be used with this class for arithmetic evaluations.

Creating a class in Java

In the example given below, the class Employee has attributes and methods.

Objects can be declared using object reference like

Employee employee; 
Student student;

An object is created by using the "new" keyword followed by the constructor of the class.

Employee emp=new Employee(); 
Student std=new Student();

The "new " keyword 

The "new" keyword,
  • Dynamically allocates memory for the object on heap space.
  • Creates object reference on the heap stack.
  • Returns a reference to it.
  • Reference is stored in a variable.
Object references are used to store objects. The reference to the object can be created for any type of class(Abstract or concrete class) or interface(see Interfaces in Java).

Video Tutorial

Classes and Objects(Creating new objects in java)

Classes and Objects

Creating objects in Java

This program is an example to create classes and objects in Java. We have the following hands-on to understand how can we create classes and objects in Java.

Problem statement:

Create a class Employee with fields emp_id, emp_name, basic_sal, HRA, and income_tax. Create 5 objects of class Employee also print the salary of each employee.

To calculate salary use formula,

salary=basic_sal + HRA - income_tax


First, create a class with the name Employee.

public class Employee {
int emp_id;
String emp_name;
int basic_sal;
int HRA;
int income_tax;

public Employee(int emp_id, String emp_name, int basic_sal, int hRA, int income_tax) 
this.emp_id = emp_id;
this.emp_name = emp_name;
this.basic_sal = basic_sal;
HRA = hRA;
this.income_tax = income_tax;
public void displaySalary()
System.out.println(emp_name+" salary is "+(basic_sal+HRA-income_tax));

Create another class with any name(we have named it Demo) but it must have the main() method inside it

public class Demo {

public static void main(String[] args) {
//the main() method
//Create the objects
Employee emp1=new Employee(12, "Alex", 56500, 3650, 2525);
Employee emp2=new Employee(35, "John", 78450, 5550, 3525);
Employee emp3=new Employee(7, "Steve", 55570, 3645, 2525);
Employee emp4=new Employee(78, "Felix", 63400, 4500, 2525);
Employee emp5=new Employee(54, "Lewis", 537400, 3550, 2525);

//calculate salary of each employee


The following results will be obtained

Alex salary is 57625 
John salary is 80475 
Steve salary is 56690 
Felix salary is 65375 
Lewis salary is 538425 

Java Architecture

Java Architecture

Java is a feature-rich, portable, and object-oriented programming language.

How a Java Program is compiled and executed? 

Java architecture defines that program is compiled by the Java compiler in Java compile-time environment and executed by the JVM (Java Virtual Machine), which is the part of Java Run-time environment

First of all Java code is compiled by the javac compiler and it is converted into bytecodes. Bytecodes are Java's magic. Due to bytecodes, platform in-dependency is achieved by the Java applications. We can move byte codes through the internet or through any other network or we can execute these byte codes on our own local machine using Java Run time environment. It is very important to understand the architecture of Java in this tutorial, we are going to see how a Java program is compiled and executed.

Java Architecture

Step 1:

Create a Java source file with .java extension.

Step 2:

Compile the Java source code using Java compiler(javac) which will create bytecode with .class extension.

Step 3:

ClassLoader reads both the user-defined and library classes into the memory for the execution.

Step 4:

Bytecode verifier validates all the bytecode which are valid and do not violate Java security regulations.

Step 5:

JVM(Java Virtual Machine) reads the byte code and translates into machine code for the execution.
During the execution of the program, the code will interact to operating system and hardware.

What JVM does?

  • JVM first loading the bytecodes from the class files
  • Bytecode verifier verifies the loaded bytecodes for security constraints
  • JVM links the application with the required libraries
  • JVM also performs memory management and Garbage Collection
  • JVM provides the mechanism for managing calls between the application and the host environment.

Java Virtual Machine

  • JVM is an interpreter that converts the bytecode to machine-specific instructions and executes.
  • JVM is platform-specific
  • Most of the modern programming languages are designed to be compiled.
  • The compilation is a one-time exercise and executes faster.
  • It is very difficult to execute compiled code over the internet.
  • Interpreting Java bytecode facilitates its execution over a wide variety of platforms. Only JVM needs to be implemented for each platform.
  • If a machine comprises JVM any java program can be executed on it. JVM differs from platform to platform and is platform-specific.

Video Tutorial

Features of Java

Features of Java

Features of Java programming language

Java is high industrial-strength programming language.Java programs are compiled into byte-codes and they are executed in Java Virtual Machine. Java provides write once run anywhere(WORA). Once you have compiled your program into the byte-codes you do not need to recompile this program will stop you just need Java Run-time Environment to execute this code. Java has the following features.


Java in simple because most of the syntax in java is coming from C and C++ shows the programmers of C and C++ can easily move or migrate from these languages to Java. The removal of complex features of C++ and the induction of new features like automatic garbage collection make Java easier to learn. 

Object-oriented programming language

Java supports all the features of object-oriented programming like inheritance, polymorphism, abstraction, encapsulation, classes, and objects. The object-oriented programming paradigm enables developers to create large applications with ease. 


Java is a robust programming language because it provides features like automatic garbage collection and dynamic memory allocation. Java is also a strictly typed language that makes Java a robust programming language. Robustness of a programming language ensures that there will be no failure during the program execution.


All Java programs are executed inside JVM or Java Virtual Machine, so the Hardware and the Operating system are not exposed. JVM ensures all the security checks and compliances before executing the code. 

Java Secure


Java supports multithreading, which is very useful for creating interactive and high-performance applications. A larger application can be divided into smaller tasks and these smaller tasks can be executed separately for combined results. All these tasks can be executed simultaneously to provide enhanced performance. These tasks are known as Threads. The thread is a small unit of the task assigned that can be dispatched by the Thread schedular. The execution of multiple threads simultaneously is known as multithreading. 

High performance

Java is a high-performance programming language. Java enables on-the-fly execution of the bytecodes with extremely fast Java interpreter, JIT(just in time compiler) and Hotspot Technology. 

Automatic Garbage Collection

Java provides the facility for automatic garbage collection which keeps the developers free from the task of destroying used objects and makes memory locations free from the garbage. 

Architecture Neutral

Java is an architectural neutral programming language so we can run some java code on different machines and Hardware architectures. 

Platform Independent

We can run any Java program on any platform (Operating System/HW). Java is a platform-independent programming language due to bytecode which enables Java to be programming to be a platform-independent programming language. 


Java enables us to create distributed software applications. Java supports technologies like RMI and EJBs etc. Java provides an extensive library of classes and interfaces for dealing with TCP/IP protocols like HTTP, FTP SMTP, etc very easily. This makes programmers create and handle network connections and applications that work in a distributed environment. 


Java Programs are first compiled to byte codes by the Javac Compiler. This byte code can be executed anywhere on any device using Java interpreter which is the part of JVM. It means Java is both compiled as well as an interpreted programming language. Java is also an interpreted programming language that enables Java to be a programming language for the internet. 


Java is a dynamic programming language as objects are loaded at runtime and type resolution is done at the runtime. Dynamic method dispatch and runtime polymorphism are examples of the dynamic nature of Java.

Video Tutorial

Thursday, December 26, 2019

First Java program to print "Hello World"

First Java program

This is our first program in Java. In this program, we will print “hello world” message on the screen and see how the basic Java program is compiled and executed by Java. This has been a tradition to create the first program in any programming language which prints hello world on the screen so we will do the same and make the same program. Java is an object-oriented programming language, which is widely used all over the world by the majority of developers to develop large web and desktop applications. Java is also a pioneering technology in the industry that is used for mobile(Android) app development.

The "Hello World" program

Write the following code in your favorite editor and compile it.

Compile the program using the following command
javac HelloWorld.Java

And execute your program using the command

java HelloWorld

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World");
Hello World

Structure of "Hello World" Program

"Hello World" program in Java
"Hello World" program in Java

Java Keywords

A keyword is a reserved word or literal having some special meaning to perform or represent something in a programming language. The keywords can't be used as identifiers or variable names in a Java Program.
Following is the list of the Java keywords.

Java Keywords

abstract continue for new switch
assert*** default goto* package synchronized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum**** instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp** volatile
const* float native super while

not used
** added in 1.2
*** added in 1.4
**** added in 5.0

Running a Java Program with command-line arguments

1. write a program and compile with the command
javac HelloWorld.Java

2. Execute your program using the command
java HelloWorld Java Python

/****Running with command-line arguments**********/
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello "+args[0]);
        System.out.println("Hello "+args[1]);


Hello Java
Hello Python

Video Example