Date Archives July 19, 2016

Git Basic

Git

  • Git is a version control system that is used for software development and other version control tasks.
  • A repository to backup files and to update the files. So, you can use it later for restore or update.
  • You probably had a experience that you updated some shared filed and replace it, but actually you erased all the parts which others made updates. This is a common situation during working on a software development as a team.
  • If you use Git, it will ask you whether you really want to replace the file when there is an updated file by others.

Screen Shot 2016-07-19 at 4.27.12 PM

Repository

  • Remote repository: files are managed by remote repository server, and this is for sharing with others.
  • Local repository: personal repository that file is saved on my PC .

Screen Shot 2016-07-19 at 4.26.35 PM

Creating Repository

  • You can either create a brand new repository from scratch or by cloning an existing remote repository onto your local machine.

Screen Shot 2016-07-19 at 4.28.48 PM

Commit

Screen Shot 2016-07-19 at 4.37.15 PM

  • The “commit” operation enables you to record changes that were made to a file or directory in the Git history.
  • By commiting every change made, you will be able to view all changes chronologically in the respective file or directory.

Screen Shot 2016-07-19 at 4.38.02 PM

Working Tree and Index

Screen Shot 2016-07-19 at 4.41.29 PM

  • A “working tree” consist of files that you are currently working on.
  • An “index” is a staging area where new commits are prepared. It acts as the interface between a repository and a working tree.

  • Changes made on the working tree will not be commited directly to the repository. They need to be staged on the index first

Git Hub vs. Git Lab

GitHub

  • suitable for OpenSource project
  • extra fee is needed for private repository, not suitable for personal project.

Screen Shot 2016-07-19 at 4.46.30 PM

GitLab

  • free for using private repository.
  • If you pay extra, you can get technical support as well.

Screen Shot 2016-07-19 at 4.48.39 PM

Citation

Images and most of words are from the website below

  • https://backlogtool.com/git-guide/en/

 

What is enum and When to use

enum

  • Enum is a predefined list of values which do not represent some kind of numeric or textual data.
  • You can use enums when a variable can only take one out of a small set of possible values. Examples will be like type days(“Mon”,”Tue”,”Wed”,”Thu”,”Fri”,”Sat”,”Sun”).

enum days{

MON, TUE, WED, THU, FRI, SAT, SUN

}

Example

public class EnumExample {
   public enum Day {
      MON, TUE, WED, THU, FRI, SAT, SUN
   }
   Day dName;

   public EnumExample(Day dName) {
      this.dName = dName;
   }

   public void dayFeelings () {
      switch (dName) {
         case MON:
            System.out.println("Week starts :(");
            break;

         case SAT: case SUN:
            System.out.println("Weekend Yay!");
            break;

         default:
            System.out.println("Waiting for weekend…");
            break;
      }
   }

   public static void main(String[] args) {
      EnumExample mon = new EnumExample(Day.MON);
      mon.dayFeelings();
      EnumExample tue = new EnumExample(Day.TUE);
      tue.dayFeelings();
      EnumExample sat = new EnumExample(Day.SAT);
      sat.dayFeelings();
      EnumExample thu = new EnumExample(Day.THU);
      thu.dayFeelings();
   }
}

Output….

Week starts 🙁
Waiting for weekend…
Weekend Yay!
Waiting for weekend…

 

Important points

You can not assign any value other than specified in Enum Constants.

enum Color{
   YELLOW, GREEN, RED
}

Color c = Color.RED;
c = 1;           // Compilation Error

MyEnum.values() returns an array of MyEnum’s values

public class EnumExample{
   public enum Color{
      YELLOW(10), GREEN(20), RED(30);
      private int value;
      private Color(int value){
         this.value=value; 
      }
   }

   public static void main(String[] args){
      for(Color c: Color.values()){
         System.out.println("Color value: "+c.value+" Color name: "+c);
      }
   }

output…

Color value: 10 Color name: YELLOW
Color value: 20 Color name: GREEN
Color value: 30 Color name: RED