الجمعة، 29 مارس 2019

Learn Top 20 Points in Git - Introduction, Features, Why all are moving to Git

Git Introduction

In this post, we will learn the following.
  • what is git?
  • why it became famous?
  • why all are moving to Git?
  • Git features?
We will see the top 20 important points of Git today.

git introduction

In 2005, Initially Git has evolved by Linus Torvalds.

Every project must be using the Version Control. We are seeing everyone now migrating to Git.
Before moving into Git, first we will go through what is Version Control.

Problems before SVN:

1.    If we do not have the Version Control then if any file is corrupted or lost then recovering the file is difficult and sometimes not possible.
2.    After reopening or recovering file if we want to move to previous state or compare with previous version, who last modified. These are not possible.
3.    We have many issues like and difficult in maintenance hence introduced Version Control.
Examples: CVS, SVN, GIT, Mercurial, Bazaar, Monotone.

For Step-By-Step explanation, Click on how to unstage a file from git.

الخميس، 28 مارس 2019

Two ways to Unstage a File in Git git rm --cached and git reset Head)

Git Unstage file

Common question on git unstage :

This post covers the following questions with in-depth answers along with step-by-step example.
git reset - Why are there 2 ways to unstage a file in git? - Stack Overflow
version control - How to undo 'git add' before commit? - Stack Overflow
git - How can I unstage my files again after making a local commit.

More article on Git Series


How to Unstage a File in Git in Two ways using git rm --cached and git reset Head (Removing File From Staging)

Program: How to write or store data into temporary file in java?

We will learn how to write the data into a temporary file in java using File class.
Below is the example program.


How to write or store data into temporary file in java

Writing data into Temp File:

package examples.java.w3schools.files;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class CreatingTempFileExample {

 public static void main(String[] args) {
  // Example program using BufferedWriter.
  File tempFile = null;
  BufferedWriter writer = null;
  try {
   // Creating ta temporary file in Temp directory.
   tempFile = File.createTempFile("MyTempFile", ".tmp");
   writer = new BufferedWriter(new FileWriter(tempFile));
   writer.write("Writing data into temp file!!!. This is a temp file.");
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   try {
    if (writer != null)
     writer.close();
   } catch (Exception ex) {
   }
  }
  System.out.println("Stored data in temporary file.");
  System.out.println("Temp file location: " + tempFile.getAbsolutePath());
 }

}

Output:

The above program produces the following output and executed in windows operating system.

Stored data in temporary file.
Temp file location: C:\Users\user\AppData\Local\Temp\1\MyTempFile3113093780191713532.tmp

Temporary file is stored in the users Temp location. You can open the file and see its content.

الأربعاء، 27 مارس 2019

Swing UIManager Keys List - getDefaults method example

javax.swing.UIManager:

UIManager manages the current look and feel, the set of available look and feels, PropertyChangeListeners that are notified when the look and feel changes, look and feel defaults, and convenience methods for obtaining various default values.

Java event handler

Specifying the look and feel:

The look and feel can be specified in two distinct ways: by specifying the fully qualified name of the class for the look and feel, or by creating an instance of LookAndFeel and passing it to setLookAndFeel. The following example illustrates setting the look and feel to the system look and feel.   


  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
   
The following example illustrates setting the look and feel based on class name:


  UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
   

Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '-', = '#', = '.' - Solution

UnknownFormatConversionException in Java. 

In this post, We will learn about UnknownFormatConversionException with some examples and common exception "Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '-', = '#', = '.' - Solution".

Unchecked exception thrown when an unknown conversion is given

Unless otherwise specified, passing a null argument to any method or constructor in this class will cause a NullPointerException to be thrown.

NullPointerException in String contains method.

UnknownFormatConversionException is child class of IllegalFormatException class.


UnknownFormatConversionException


UnknownFormatConversionException Constructor Syntax:

public UnknownFormatConversionException(String s)


Constructs an instance of this class with the unknown conversion. s indicates the unknown conversion type or value.

الجمعة، 22 مارس 2019

String isEmpty method in java with example - Internal Implementation

String isEmpty method in java:

In this post, We will learn more about java.lang.String.isEmpty() method.

Step 1) What this method does or method description

Step 2) Syntax, Parameters, Return type
Step 3) Example 1:  program to check String is empty or not
Step 4) Example 2:  program to check if the string is null or "  " empty spaces
Step 5) How isEmpty works internally and implementation code.

Step 1: String isEmpty method description

Java String isEmpty() method checks whether a String is empty or not. This method returns true if the given string is empty, else it returns false. In other words you can say that this method returns true if the length of the string is 0.

This method is present in package java.lang.String and introduced isEmpty in java 1.6.



String isEmpty method in java


Step 2: Syntax

The following is the syntax for isEmpty method.

public boolean isEmpty()

Parameters:

Does not take any parameters.


Return type:

boolean. Returns true if length is 0, otherwise false.

الجمعة، 15 مارس 2019

String endsWith​ Method in Java With Example - Internal Implementation

String endsWith​ method in java:

Java String endsWith​ method is used to check the string is ending with the specified string or not. This method returns true if the string is ending with given string or suffix.
Returns false if not ending with the specified string.


String endsWith​ method in java


Syntax:

public boolean endsWith​(String suffix)


Tests if this string ends with the specified suffix.

Parameters:

suffix - the suffix. This string will be searched in the input string.

الخميس، 14 مارس 2019

Java String copyValueOf​ method example - Internal Implementation

Java String copyValueOf​ method:

copyValueOf​ method is present in the String class which is in package java.lang.String. copyValueOf​ is used to convert character array into String that means it creates a new String with contents of array elements. In this tutorial, We will learn String copyValueOf​ method syntax, String copyValueOf​ method example and String copyValueOf​ method internal implementation.

String has overloaded copyValueOf​ methods and both are static methods which can be accessed by class name instead of creating object for String class.



copyValueOf​ Syntax 1: 

public static String copyValueOf​(char[] data);


Returns the string representation of the char array argument. The contents of the character array are copied; subsequent modification of the character array does not affect the returned string.


String copyValueOf​ method


Parameters:

data - the character array.

Returns:

A String that contains the characters of the character array. 

الأربعاء، 13 مارس 2019

Java OOPS Concept

OOPS Concepts in Java

In this tutorial, We'll explore about oops concepts in java w3schools with examples. If you are new to Java programming, You should know the concepts of Object Oriented Programming(OOP) before you start writing coding. This tutorial let you know Classes, Object, Packages, Encapsulation, Inheritance, Polymorphism, Abstraction.


In Java, Please consider behavior means a method how it works or behave called as "behavior".




String equals() method in java with example - Internal Implementation

String equals() method in java with example:

This method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.


Java String equals()


Syntax:

public boolean equals​(Object anObject)

الجمعة، 8 مارس 2019

Java | Difference between String.equals() and String.contentEquals() method?

What is the difference between String.equals() and String.contentEquals() method?

In this post, We will learn What is the difference between String.equals() and String.contentEquals() method in java? Simply contentequals vs equals  for these string methods.

Both these methods are present in the String class in java.

Read the article on Examples on String contentEquals method.

Syntax:

boolean equals​(Object anObject)
public boolean contentEquals​(CharSequence cs)

Difference between String.equals() and String.contentEquals() method?

الأربعاء، 6 مارس 2019

String contentEquals​() method in java with example - Internal Implementation

String contentEquals​() method in java with example:

contentEquals​ method is overloaded method in String class and these two are non static methods.

Read about Static in Java.

Syntax:

public boolean contentEquals​(StringBuffer sb)
public boolean contentEquals​(CharSequence cs)

Return type:

boolean in both cases. Returns true if content is matches, otherwise false.


String contentEquals​() method


الاثنين، 4 مارس 2019

String Contains() method in java with example - Internal Implementation

String contains() method in java with example:


The contains() method is Java method to check if String contains another substring or not. It returns boolean value so it can use directly inside if statements. This method returns true only if this string contains "s" else false. NullPointerException − if the value of s is null. This method is introduced in java 1.5 version.



String Contains() method


Syntax:

public boolean contains​(CharSequence s)

Parameters:

s - the sequence to search for


Return Value:

This method returns true only if and only this string contains "s" else false. 

Exception:

NullPointerException − if the s value of s is null.