How to remember Username and Password when pull or push Project with Git


Remember username and password when pull or push project 

In this tutorial I will share how to remember username and password when pull or push by working with git , also I will share how to avoid conflict lines  when developers are working at the same file in project.

To git remember username and password when pull or push

1) Go to your project folder
2) Right click in your project
3) Select Git Bash
4) Type: git config credential.helper store
5) Enter : your username and password

Then when pull or push git next time it will remember your username and password automatically.

Sometime developers are working at the same file ,one developer committed his/her task first ,and next developer do the same lines and the same file when pull it will conflict lines that required developer merge or resolved  that file or revert the previous file. To avoid conflict lines at the same file , here is step by step to avoid conflict line at the same file.

1) Commit your task (do not click button Push , just only commit )
2) Right click your project folder or your repository project
3) Stash Save
4) pull
5) stash pop
6) push

when push your project git will merge your code and line automatically.


Android Sample Project Part -1

Android Sample Project Part -1 


to create new sample android project and run it should have eclipse , genymotion for run and test it at local. And this is sample project demo.
Demo tax on Salary (android sample project)
1) step 1




2) step 2 - input currency (riels) to text box ,then show result pay tax.


Next tutorial we will create project step by step.

Android Sample Project Part -2

In this section we will create sample project step by step.

1) Create your project name in eclipse.
2)  In activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/lbltitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="32dp"
   
        android:gravity="center_horizontal"
        android:text="@string/SalaryTax"
        android:textColor="#0101DF"
        android:textSize="35sp" />

    <TextView
        android:id="@+id/lblsalary"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/lbltitle"
        android:layout_marginTop="37dp"
        android:text="@string/Salary"
        android:textColor="#0101DF"
        android:textSize="25sp" />

    <EditText
        android:id="@+id/txtsalary"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/lblsalary"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/lblsalary"
        android:ems="10"
        android:textSize="15sp"
        android:inputType="number"
       android:width="200dp" >
        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/btncal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/CalculateTax"
        android:textColor="#0101DF"
        android:width="110dp" />

    <TextView
        android:id="@+id/lblnet"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignLeft="@+id/lblsalary"
        android:layout_below="@+id/btncal"
        android:layout_marginTop="37dp"
        android:text="@string/NetSalary"
       android:textSize="20sp" />

    <TextView
        android:id="@+id/lbltax"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/lblnet"
        android:layout_below="@+id/lblnet"
        android:layout_marginTop="48dp"
        android:text="@string/Tax"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/txtsalary"
        android:layout_alignLeft="@+id/txtsalary"
        android:text="@string/introductionTaz" />

</RelativeLayout>







Android Sample Project Part - 3

Android Sample Project Part - 3


In  this section you will know more android sample project , and this part we will learn more about xml file.
In this part we will store variable name and values in String.xml file in android sample project .
To store variable and values in string.xml to ,go to android project 



<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">salary</string>
    <string name="action_settings">Settings</string>
     <string name="SalaryTax">Tax payment</string>
      <string name="Salary">Salary</string>
      <string name="CalculateTax">Calcualte</string>
     <string name="NetSalary">balance</string>
      <string name="Tax">Tax</string>
      <string name="introductionTaz">1$ = 4000 Riels</string>
    

</resources>

You saw some variable and values stores in string.xml file and ti was used activity_main.xml 
Example:1
android:text="@string/SalaryTax" ,also you can call to use it in MainActivity.java like this 
Example:2
Toast.makeText(MainActivity.this, getString(R.string.SalaryTax, comp, guesses), 
            Toast.LENGTH_LONG).show();

Android Sample Project Part - 4

Android Sample Project Part - 4

In this section you will know more about MainActivity.java and Concept in android sample project 
In this app you will know how to declare variable and some conditions in Salary Tax.

There are  some conditions that we will to do it in MainActivity.java


Monthly salary (Riels)Rate
0 - 800,0000%
800,001 - 1,250,0005%
1,250,001 - 8,500,00010%
8,500,001 - 12,500,00015%
12,500,001 - upwards20%
public class MainActivity extends Activity {
public Button CalculateTax;
public EditText Salary;
public TextView NetSalary;
public TextView Tax;

public double salarys, netsalary,tax = 0;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
                //call method 
addOnclickListener();
}
private void addOnclickListener() {
// TODO Auto-generated method stub
CalculateTax = (Button)findViewById(R.id.btncal);
Salary = (EditText)findViewById(R.id.txtsalary);
NetSalary = (TextView)findViewById(R.id.lblnet);
Tax = (TextView)findViewById(R.id.lbltax);

CalculateTax.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if(Salary.getText().toString().equals("")){
Toast.makeText(getApplicationContext(), "Please Fill in the salary", Toast.LENGTH_LONG).show();
}
else
{
salarys = Double.valueOf(Salary.getText().toString());
if(salarys>=0 && salarys<=800000){
netsalary salarys ;
tax = 0;
}else if(salarys >= 800001 && salarys <= 1250000){
tax = (salarys *0.05)-40000;
netsalary salarys -((salarys *0.05) - 40000);
}else if(salarys >=1250001 && salarys <= 8500000){
tax = (salarys *0.1)-102500;
netsalary  salarys  - ((salarys  *0.1 ) - 102500);
}else if(salarys >= 8500001 && salarys <= 12500000){
tax = (salarys *0.15)-527500;
netsalary  salarys - ((salarys *0.15)-527500);
}else {
tax = (salarys *0.2)-1152500;
DecimalFormat df = new DecimalFormat("00.00");
                   String myre = df.format(tax);
netsalary  salarys - ((salarys *0.2)-1152500);
DecimalFormat dfo = new DecimalFormat("00.00");
                   String myreo = dfo.format(netsalary  );
}
}
String finaltax = String.valueOf(tax);
Tax.setText(" Pay tax = "+finaltax);
NetSalary.setText("Your Balance = "+ String.valueOf(netsalary  ));
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}

Android Concept Sample Project

Android Concept Sampe Project 

In this tutorial you will know android project concept and this project name is tax on salary..
Some Countries get from citizen who is working in company or NGO and tax will automatically to government monthly . so this this tutorial we will create new android sample project it s name tax on Salary


Example: Cambodia (Tax on Salary)

Monthly salary (Riels)Rate
0 - 800,0000%
800,001 - 1,250,0005%
1,250,001 - 8,500,00010%
8,500,001 - 12,500,00015%
12,500,001 - upwards20%


Next tutorial we will create this sample android project.

Comparator Date - Java

In this tutorial you will know how to compare Date  in java .
In this section we will do step by step
1. Comparator Date in Java
2. Comparator by using method after(), before() and equal()

public boolean after(Date date);
public boolean  before(Date date)
public boolean equal(Object o);

See Example1;

import java.util.Date;

public class Details {
       public static void main(String[] args) {
Date today = new Date();
Date myDate = new Date(today.getYear(),today.getMonth()-1,today.getDay());
getCompareDate(today, myDate);
}
public static void getCompareDate(Date today, Date myDate){
System.out.println("method Comparator > My Date is : "+myDate);  
    System.out.println("method Comparator Today Date is : "+today);
    if (today.compareTo(myDate)<0){
        System.out.println(" method Comparator Today Date is Lesser than my Date");
    }
    else if (today.compareTo(myDate)>0){
        System.out.println(" method Comparator Today Date is Greater than my date");
    }  
    else{
        System.out.println("Both Dates are equal");
    }

}

//result:
method Comparator > My Date is : Mon Feb 01 00:00:00 ICT 2016
method Comparator Today Date is : Mon Mar 14 23:52:02 ICT 2016
 method Comparator Today Date is Greater than my date


Example2: method after(), before(), equal();

import java.util.Date;

public class Details {
public static void main(String[] args) {
Date today = new Date();
Date myDate = new Date(today.getYear(),today.getMonth()-1,today.getDay());
getDateComapreBeforeAndAfter(today, myDate);
}

private static void getDateComapreBeforeAndAfter(Date today, Date myDate){
//After() or before() or equal() method want to know today > myDate ? and it return boolean true or false
System.out.println("Date method compare Before : "+today.before(myDate));
System.out.println("Date method compare After : "+today.after(myDate));
System.out.println("Date method compare equal : "+today.equals(myDate));
}
}

result :

Date method compare Before : false
Date method compare After : true
Date method compare equal : false





Vector to Array - Java

In this tutorial we will convert vector to Array in java  and to convert vector to array we used method
Vector.toArray();


Syntax:  public Object [] toArray();

See Example:


import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Example {

public static void main(String args[]) {
//console method 
vectorToArray();

}
//declare method to get Vector 
public static void vectorToArray(){
//Declare String[] 
String elements[] = { "Book1", "Book2", "Book3", "Book4", "Book5" };
// convert String[] to List
Set set  =  new HashSet(Arrays.asList(elements));
String[] strObj = new String[set.size()];
strObj = (String[]) set.toArray(strObj);
for (int i = 0; i < strObj.length; i++) {
        System.out.println(strObj[i]);
     }
     System.out.println(set);
}

}

//result :

Book5
Book3
Book4
Book1
Book2
[Book5, Book3, Book4, Book1, Book2]



Vector Remove Object - Java

In this we will remove Object from Vecctor by using method remove()

Syntax : public boolean remove(Object o);

See Example:

import java.util.Vector;

public class Example {

public static void main(String args[]) {
Vector vector = new Vector(3);
vector.add(3);
vector.add(1);
vector.add(2);
System.out.println("Vector before remove element: "+vector);
System.out.println("Removed element from vector: "+vector.remove((Integer)1));
System.out.println("Vector after remove element: "+vector);
 
}

}

//result :

Vector before remove element: [3, 1, 2]
Removed element from vector: true
Vector after remove element: [3, 2]

Vector Remove Element - Java

To remove element from Vector we will use method


See Example:

import java.util.Iterator;
import java.util.Vector;

public class Example {

public static void main(String args[]) {
   
     Vector<String> vec = addVector();
 
}
//declare method to get Vector 
public static Vector<String> addVector(){
/* Vector of initial */
 Vector<String> vectors = new Vector<String>();
 /* Adding elements to a vector*/
 vectors.addElement("Item1");
 vectors.addElement("Item2");
 vectors.addElement("Item3");
 vectors.addElement("Item4");
 vectors.addElement("Item5");
 System.out.println("Vector elements : "+vectors);
 System.out.println("Vector Size Before Remove : "+vectors.size());
 //remove first element "Item1" of index zero
 System.out.println("Removed element: "+vectors.remove(0));
 System.out.println("Vector Size after Remove : "+vectors.size());

 return vectors;

}

}

//result :

Vector elements : [Item1, Item2, Item3, Item4, Item5]
Vector Size Before Remove : 5
Removed element: Item1
Vector Size after Remove : 4

Vector Iterator - java

In this tutorial we will loop or Iterator  vector .





See Example:


import java.util.Iterator;
import java.util.Vector;

public class Example {

public static void main(String args[]) {
   
     Vector<String> vec = addVector();
     System.out.println("Elements Vector : "+vec);
     Iterator iterator = vec.iterator();
     while(iterator.hasNext()){
         System.out.println("Vector Iterator  : "+iterator.next());
       }
  }
//declare method to get Vector 
public static Vector<String> addVector(){
/* Vector of initial  */
 Vector<String> vectors = new Vector<String>();
 /* Adding elements to a vector*/
 vectors.addElement("Item1");
 vectors.addElement("Item2");
 vectors.addElement("Item3");
 vectors.addElement("Item4");
 vectors.addElement("Item5");
 return vectors;

}

}

// result :

Elements Vector : [Item1, Item2, Item3, Item4, Item5]
Vector Iterator  : Item1
Vector Iterator  : Item2
Vector Iterator  : Item3
Vector Iterator  : Item4
Vector Iterator  : Item5

Vector in Java

In this tutorial we learn Add Vector in Java . by using method add()

public boolean add(E e);

See Example :

import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;

public class Example1 {
public static void main(String args[]) {
 
     Vector<String> vec = addVector();
   
     System.out.println("Elements Vector : "+vec);
     System.out.println("Vector size : "+vec.size());
  }
public static Vector<String> addVector(){
/* Vector of initial*/
 Vector<String> vectors = new Vector<String>();
 /* Adding elements to a vector*/
 vectors.addElement("Item1");
 vectors.addElement("Item2");
 vectors.addElement("Item3");
 vectors.addElement("Item4");
 vectors.addElement("Item5");
 return vectors;

}

}

//result :
Elements Vector : [Item1, Item2, Item3, Item4, Item5]
Vector size : 5

Remove Mapping From HashMap

In this section we will learn how to remove element from HashMap in Java .


See Example: 

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class Example2 {

public static void main(String[] args) {
HashMap<Integer, String> hMap = getHashMapKeyAndValue();
}
//Declare method 
public static  HashMap<Integer, String> getHashMapKeyAndValue(){
HashMap<Integer, String> hashMap = new HashMap<Integer, String>();
hashMap.put(1, "Orange");
hashMap.put(5, "Apple");
hashMap.put(3, "Mango");
hashMap.put(4, "Coconut");
hashMap.put(2, "Red Apple");
for(Map.Entry  map : hashMap.entrySet()){
System.out.println("Key :"+ map.getKey() + " & Value : " +map.getValue());
}
//remove  key&value pairs for key 2
Object removeObj = hashMap.remove(2);
System.out.println("HashMap Elements remove key = " + removeObj);
 
System.out.println("After remove element " );
for(Map.Entry  map : hashMap.entrySet()){
System.out.println("Key :"+ map.getKey() + " & Value : " +map.getValue());
}
return hashMap;
}
}
//result:

Key :1 & Value : Orange
Key :2 & Value : Red Apple
Key :3 & Value : Mango
Key :4 & Value : Coconut
Key :5 & Value : Apple
HashMap Elements remove key = Red Apple
After remove element 
Key :1 & Value : Orange
Key :3 & Value : Mango
Key :4 & Value : Coconut
Key :5 & Value : Apple

Get Size or Length of HashMap in Java

In the last tutorial we learnt Sort key and value of HashSet as well as remove all from HashSet .
Now we well learn how to get size from HashMap by use method size() in java to know size or length of collections.

See Example:

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class Example2 {


public static void main(String[] args) {

HashMap<Integer, String> hMap = getHashMapKeyAndValue();
System.out.println("Before Remove HashMap:");
        Set set = hMap.entrySet();
        Iterator iterator = set.iterator();
        while(iterator.hasNext()) {
              Map.Entry me = (Map.Entry)iterator.next();
              System.out.print(me.getKey() + ": ");
              System.out.println(me.getValue());
        }
        System.out.println("Hashmap Size :"+set.size());
        set.clear();
        System.out.println("After Remove Hashmap size : "+set.size());
}
//Declare method 
public static  HashMap<Integer, String> getHashMapKeyAndValue(){
HashMap<Integer, String> hashMap = new HashMap<Integer, String>();
hashMap.put(1, "Orange");
hashMap.put(5, "Apple");
hashMap.put(3, "Mango");
hashMap.put(4, "Coconut");
hashMap.put(2, "Red Apple");
return hashMap;

}
}

//result :

Before Remove HashMap:
1: Orange
2: Red Apple
3: Mango
4: Coconut
5: Apple
Hashmap Size :5
After Remove Hashmap size : 0

Remove All from HashMap In java

In the tutorial we will learn HashMap and how to remove All from Hashmap, so to remove all from HashMap we use method clear(); to remove Key and values from HashMap.

See Example:

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class Example2 {

public static void main(String[] args) {
HashMap<Integer, String> hMap = getHashMapKeyAndValue();
System.out.println("Before Remove HashMap:");
        Set set = hMap.entrySet();
        Iterator iterator = set.iterator();
        while(iterator.hasNext()) {
              Map.Entry me = (Map.Entry)iterator.next();
              System.out.print(me.getKey() + ": ");
              System.out.println(me.getValue());
        }
   
        set.clear();
        System.out.println("After Remove Hashmap :"+set);
}
//Declare method
public static  HashMap<Integer, String> getHashMapKeyAndValue(){
HashMap<Integer, String> hashMap = new HashMap<Integer, String>();
hashMap.put(1, "Orange");
hashMap.put(5, "Apple");
hashMap.put(3, "Mango");
hashMap.put(4, "Coconut");
hashMap.put(2, "Red Apple");
return hashMap;

}
}

//result :

Before Remove HashMap:
1: Orange
2: Red Apple
3: Mango
4: Coconut
5: Apple
After Remove Hashmap :[]

How to loop HashMap in java

In this tutorial we learn how to loop HashMap in java ,by For Loop and Iterator HashMap .

See Example:

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Example {

public static void main(String[] args) {
HashMap<Integer, String>  hashMap = getHashMapKeyAndValue();
//For Loop hashMap
 System.out.println("For Loop:");
for(Map.Entry  map : hashMap.entrySet()){
System.out.println("Key :"+ map.getKey() + " & Value : " +map.getValue());
}
//WHILE LOOP & ITERATOR
        System.out.println("While Loop:");
     
        Iterator iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry map2 = (Map.Entry) iterator.next();
         System.out.println("Key: "+map2.getKey() + " & Value: " + map2.getValue());
       }

}
//Declare method
public static  HashMap<Integer, String> getHashMapKeyAndValue(){
HashMap<Integer, String> hashMap = new HashMap<Integer, String>();
hashMap.put(01, "Book1");
hashMap.put(05, "Book5");
hashMap.put(03, "Book3");
hashMap.put(04, "Book4");
hashMap.put(07, "Book7");
hashMap.put(02, "Book2");
hashMap.put(06, "Book6");
return hashMap;

}

}

// result :

For Loop:
Key :1 & Value : Book1
Key :2 & Value : Book2
Key :3 & Value : Book3
Key :4 & Value : Book4
Key :5 & Value : Book5
Key :6 & Value : Book6
Key :7 & Value : Book7
While Loop:
Key: 1 & Value: Book1
Key: 2 & Value: Book2
Key: 3 & Value: Book3
Key: 4 & Value: Book4
Key: 5 & Value: Book5
Key: 6 & Value: Book6
Key: 7 & Value: Book7

HashMap in java

In this tutorial we will learn HashMap .HashMap is the collection class .It is used to sort key and values pairs  HashMap <K, V> .HashMap implement Map Interface . HashMap not order key and values, also it allow Key null and values null .It is used for maintain Key and Value mapping in Java.

HashMap<K,V> hashmap = new HashMap<K,V>();

It is not an ordered collection which means it does not return the keys and values in the same order in which they have been inserted into the HashMap. It neither does any kind of sorting to the stored keys and Values. You must need to import java.util.HashMap or its super class in order to use the HashMap class and methods.

See Example:

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Example {

public static void main(String[] args) {
HashMap<Integer, String>  hashMap = getHashMapKeyAndValue();
//For Loop hashMap
 System.out.println("For Loop:");
for(Map.Entry  map : hashMap.entrySet()){
System.out.println("Key :"+ map.getKey() + " & Value : " +map.getValue());
}
//WHILE LOOP & ITERATOR
        System.out.println("While Loop:");
     
        Iterator iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry map2 = (Map.Entry) iterator.next();
         System.out.println("Key: "+map2.getKey() + " & Value: " + map2.getValue());
       }

}
//Declare method
public static  HashMap<Integer, String> getHashMapKeyAndValue(){
HashMap<Integer, String> hashMap = new HashMap<Integer, String>();
hashMap.put(01, "Book1");
hashMap.put(05, "Book5");
hashMap.put(03, "Book3");
hashMap.put(04, "Book4");
hashMap.put(07, "Book7");
hashMap.put(02, "Book2");
hashMap.put(06, "Book6");
return hashMap;

}

}

//result :
For Loop:
Key :1 & Value : Book1
Key :2 & Value : Book2
Key :3 & Value : Book3
Key :4 & Value : Book4
Key :5 & Value : Book5
Key :6 & Value : Book6
Key :7 & Value : Book7
While Loop:
Key: 1 & Value: Book1
Key: 2 & Value: Book2
Key: 3 & Value: Book3
Key: 4 & Value: Book4
Key: 5 & Value: Book5
Key: 6 & Value: Book6
Key: 7 & Value: Book7




Kategori

Kategori