Posts

Some Git Terminologies Explained in Brief

In this article, I will try to explain some of the important terminologies associated with Git. Some Git Terms Working Directory Working directory refers to a project folder on the file system. It may or may not be tracked by Git. Staging Area A staging area represents the files that are ready to be added to a repository. Typically, projects include dynamically generated files like class files, test reports, etc. These are not added to a repository, only the source code/configuration files are added to a repository. Thus, whenever you want to add some code to a repository, it first needs to be added to the staging area, from where it can be committed to the repository. The process of adding code to the staging area is known as indexing . Local Repository As explained in my Git v/s Github article, Git maintains a local repository where it keeps track of all the changes made to the project on the local system. Remote Repository The repository on your repository hosting system like Githu...

Git and Github Differences Explained In Short

Often, the terms Git and Github are used interchangeably. Those new to Git and Github often find this confusing. In this post, I will try to clear some confusion. What is Git? In very simple terms, Git is a local version control system. Unlike other version control systems like SVN and CVS, it creates a local repository. It can be used to track changes to files. What is Github? Github is a git repository hosting service. It can be used to share git repositories across teams.  In addition to Github, there are other git repository hosting services like Gitlab, Bitbucket, etc. Git and Github Differences The following table lists the differences between Git and Github: Edit Git Github Version control system that can be used to track changes to files Git repository hosting service that can be used to share git repositories across teams. Is a command line tool Has a Graphical User Interface Needs to be installed locally on the system Does not require any additional software to be ins...

Create a local repository in Git with step by step commands

In this article, I will be listing down a few basic instructions to create a local repository in git. Step 1: Open a command prompt/terminal window. Navigate to the directory where you want to create a git repository. Step 2: Initialize the directory as a local repository using the following command: git init Step 3: Add the files from the current directory to the local repository: git add .   Step 4: Commit files to your local repository: git commit -m "Initial commit" That is all!

How to use TestNG with Maven and Eclipse

Image
Earlier, we had seen how to use JUNIT for unit testing. TestNG is another such unit testing framework. In this article, we will be learning how to use TestNG with Maven and Eclipse. TestNG Overview TestNG is a very powerful unit testing framework. Not only does it allow creating and running tests, but it has many advanced features like generating test reports, parameterizing tests, and much more. Let us now learn how to use TestNG to test a simple Java program. Project Creation and Setup  Step 1 – Create a new Maven Project  (Refer to  this  blog post). This should create a project as shown below: Step 2 – Add the TestNG dependencies (You can refer to this blog post). Alternatively, you can add the following to your pom.xml file: <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.8</version> <scope>test</scope></dependency> Writing and Running Code Step 3 – Write code to be tested...

How to add Days to a Date in Java with code samples

Very often, when programmers perform date manipulation, they are required to add a specified number of days to a given date. In this article, we will learn how to add days to a Date in Java. Using LocalDate The LocalDate class makes it very easy to add days to a Date. Let us take a look at a few examples. Adding days to a LocalDate The following code sample demonstrates adding days to a LocalDate: LocalDate date1 = LocalDate.of(2018, 05, 10);System.out.println("Before adding days:"+date1);LocalDate date2 = date1.plusDays(6);System.out.println("After adding days:"+date2); So in this case, the code above invokes the LocalDate.plusDays method. This adds the specified number of days to the LocalDate object on which it is invoked and returns and updated LocalDate. So, this code prints the following output: Before adding days:2018-05-10After adding days:2018-05-16 Similarly, the LocalDate class has a minusDays method, that subtracts the specified number of days from a ...

How to read a file on the classpath in Java

Image
There are often programming situations when you need to read a file on the classpath via Java. In this article, I will show you how to write code for this. Reading a file on the classpath Let us first take a look at the code that you need to write to read a file on the classpath. public class ReadFileFromClassPathDemo { public static void main(String[] args) throws IOException { // read in the file from the resources directory ClassLoader classLoader = ReadFileFromClassPathDemo.class.getClassLoader(); URL url = classLoader.getResource("input.txt"); String fileName = url.getFile(); File file = new File(fileName); String str = new String(Files.readAllBytes(file.toPath())); System.out.println(str); }} Java has an in-built class called ClassLoader .  It is used to dynamically load classes. It can also be used to load resources from the classpath. The code above first obtains a ClassLoader . It then invokes the getResource method on the classLoader . This l...

How to use Flyway with Spring Boot with code samples

Image
At its core, Flyway is a version control system for databases. It allows applying incremental changes to a database. In this article, we will be learning how to use Flyway with a Spring Boot application. Flyway Overview As explained earlier, Flyway is a version control system for databases. To explain in very simple words, it allows specifying database DDL/DML in an SQL file (also known as a migration). It then applies these changes to the database. In case you need to apply further changes, you need to specify another migration with a higher version number with the incremental changes. Flyway then applies the new changes to the database. Let us now understand how to use Flyway with Spring Boot and a MySQL database. Project Creation and Setup  Step 1 – Create a new Maven Project  (Refer to  this  blog post). This should create a project as shown below: Step 2 – Add the Spring Boot, Flyway, and MySQL dependencies . So, the  pom.xml  file should be similar to the following: <proj...