Android Studio Shortcuts

1.Jump on words from left to right and right to left using ctrl+left arrow and ctrl+right arrow

2.To make entire text selection we can use ctrl+left arrow or ctrl+right arrow so it moves the cursor to particular text and by pressing ctrl+ shift+left arrow we can make the entire text selection.

3.To switch between tabs use Alt+left or Alt+Right arrow ie you have opened ten files on the screen want to move from one file to another you can use it.

4.ctrl+y to remove a single line from the code we can also use ctrl+x for cutting the line without selecting the text and ctrl+c for copying.

5.For moving statement we can use ctrl+shift+up or ctrl+shift+down arrow it will move statement above or below expression.

6.we can see all the shortcuts under File →setting →keymap →Editor Action

How to create a Singleton class in Kotlin

we can create a singleton class in kotlin by using keyword object.Below program illustrate how to create a singleton class

fun main()
singleton.printname() = "Hi i am main class"

object singleton
println("Singleton class invoked")
var name:String = "I am from singletonclass"
fun printname()
Singleton class invoked
I am from singletonclass
Hi i am main class

apply vs with

we use apply when we need to perform some operation on a object and return it.

We use with when we need to perform some operation on a object and return some other object.

Difference between apply vs with

apply function will take instance as an receiver while with function we need to pass instance as an argument.But in both case the instance will be refered with this inside the block

Example of apply

fun getDeveloper(): Developer {
return Developer().apply {
developerName = "Pandiyan"
developerAge = 22

Example of with

fun getPersonFromDeveloper(developer: Developer): Person {
return with(developer) {
Person(developerName, developerAge)

Collections in Kotlin

Collections is a framework that provides you an architecture to store and manipulate a group of object.

By using collection we can perform insertion,deletion,manipulation,searching and sorting.

Collection provide us an interface like list,map and set.

Collection are classified in to two types:

immutable → it provide only with read only option we cannt add or remove element on this type.

mutable → we can modify the object we can perform read,write and delete data from the coollection.

lets see the collections under two types first we see with immutable types

listOf ()→it comes under immutable type, list…

Intent Service

If you need to perform any operation asynchronus or queue and that process will be automatically killed after it has done.Since intent service works on worker thread so launching multiple intent will be done one by one and will be killed after it has done with it.Since its run on single thread it will be time consuming.

starting an intent service

public void startService(View view){ Intent intent=new Intent(this,MyService.class); startService(intent); }


public void stopService(View view){ Intent intent=new Intent(this,MyService.class); stopService(intent); }

override method when we extend intent service

@Override protected void onHandleIntent(Intent intent){ synchronize (this){ try{ wait(20000); }catch(IntarruptedException e){ e.printStackTrace(); } } }

Pending Intent

Pending Intent is basically an object that wrap around another intent object.

It allows other application or service like notification manager,alarm manager etc to let them handle which time it need to be executed.

This intent are executed by thrid parties like android os at some scheduled time.

we use pending intent mainly when we want to execute some operation at later point.

Association, Composition and Aggregation in Java

Association is relationship between two classes that establish through object in association there are two types

Association its weakly coupled that an object can stay even the other object get destroyed eg an bank can stay without employess and vice versa. Aggregation helps in reusing the code.

Composition its strongly coupled one object cannt stay if other object get destroyed eg library cannt stay if books are destroyed

Print pyramid pattern

public class Employee
public static void main(String[] args)
public static void drawPyramidPattern()
for(int i=0;i<6;i++)
for(int j=0;j<6-i;j++)
System.out.print(" ");
for(int k=0;k<=i;k++)
System.out.print("* ");

hashcode() and equals() method

hashcode() and equals() methods both are provided by the object class.Object class is the base class of java object.So all the object by default override this two method.

equals() method compare weather two object are equal

public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Employee employee = (Employee) o;
return id ==;

hascode() method based on hashing return a int hascode value to store on hash table.It …

public class MyClass
public static void main(String args[])

int row=10;
for(int i=1;i<=row;i++)
for(int j=1;j<=i;j++)
System.out.print("* ");
System.out.println(" ");


* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *

Half Pyramid using numbers

public class MyClass
public static void main(String args[])

Pandiyan Mani

Knowledge is everything

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store