Java – IO @ Blocking vs. Non-blocking

Various streams are blocking in Java IO’s. Usually, when a thread invokes a read() or write() operation, that thread is blocked until there is some data to read, or the data is fully written. This results that respective thread cannot do anything in the meantime.

Java NIO’s non-blocking mode enables a thread to request reading data from a channel, and only get what is currently available, or nothing at all, if no data is currently available. Instead of remaining blocked until data becomes available for reading, the thread can go further with something else. This is true for non-blocking writing wherein a thread can request that some data be written to a channel, but not wait for it to be fully written.

What threads spend their idle time on when not blocked in IO calls, is usually performing IO on other channels in the meantime. That is, a single thread can now manage multiple channels of input and output.

!! Happy Revision/Learning !!

Git – A Quick Reference

# Starting a git repository
git init

# Creating a working copy of a repository (Check-Out)
git clone /path/to/repository

# Creating a working copy from a particular branch of a repository (Check-Out)
git clone -b feature/branchName /path/to/repository

# Switching to another branch of a repository
git switch feature/branchName

# Get current branch status
git status

# Adding a file to Index (Check-In)
git add path/fileName.extension

# Adding all the files to Index (Check-In)
git add –all

# To commit the changes
git commit -m “Commit Message”

# Pushing changes from the HEAD of your local working copy to remote repository
git push

# If a file was added to the stage by mistake then undo a stage
git reset path/fileName.extension

# Another way to undo the staging changes
git restore –staged path/fileName.extension

# Reseting code by deleting all changes. HEAD is the latest local commit
git reset –hard HEAD

# Same as above but N commits back.
git reset –hard HEAD~N

# Reset code but keep changes locally. (Useful for uncommiting a not pushed mistake)
git reset –soft HEAD~1 [Tip: Use HEAD~2 if a merge occured]

# Save local uncommitted changes temporarily
git stash

# Bring back the saved changes
git stash apply

# Getting repository history
git log

# To see the fileName of committed changes
git show –pretty=”” –name-only

# To see the contents of committed changes
git show

# Downloads new changeSet from a remote repository but don’t integrate to working files
git fetch

# Downloads new changeSet from a remote repository
git pull

# Getting the list of all branchs at local with their respective origins
git branch -lvv

# Getting the difference between two files
git diff HEAD: path/fileName.extension path/fileName.extension

# Setting the proxy
git config –global http.proxy http://website.proxy.com:9090
git config –global https.proxy http://website.proxy.com:9090

# Getting help for Git commands
git –help

How to resolve the Merge conflict during Pull request in Git

We have to resolve the conflicts manually by merging the develop into feature branch. After the conflicts are resolved we could be able to merge the Pull request.

  • Step 1: Checkout the feature branch and merge the respective changes from the target branch. Resolve conflicts.
    • git checkout feature/branchName
    • git pull origin develop
  • Step 2: After the merge conflicts are resolved, stage >> commit >> push the changes accordingly.
    • git commit
    • git push origin HEAD
  • Step 3: Merge the updated pull request.

How to check Environment Variables through Command Prompt

There are couple of ways which we could opt to check the environment variables through command prompt and details for the same is given below:-
(1) In Windows >> Command-Prompt, the command is :- echo %PATH%
(2) To get a list of all environment variables enter the command :- set
(3) To send those variables to a text file enter the command :- set > myFilename.txt

Windows-10 @ Useful KeyBoard Shortcuts

Windows Key + Shift Key + Arrow Key
Press the Windows Key then add and hold the SHIFT key. While keeping those two pressed hit the left or right arrow key to move the current active window left or right. It’s very useful feature when you are working with two monitors.

Windows Key + 1, 2, 3, etc.
A nice new feature in Windows 10 is the ability to run a program that is on your taskbar by simply pressing the Windows key + a number.

Windows Key + Q/S
You can use either of these two keys to open up Cortana and the Windows search box

Windows Key + Comma (,)
If you’re working and have several windows open on the screen, but want to quickly see what’s on the desktop without having to switch to the desktop, then press Windows Key + Comma (,).

Windows Key + Period (.)
If you do Windows key + ., you get a small dialog with a bunch of emojis! If you click on the emoji, it will insert it into currently active program.

Windows Key + PrtScn
Windows Key + PrtScn (PrintScreen) will take a snapshot of whatever is on your screen and put it into the Photos app automatically.

Ctrl + Alt + PrtScn
Place your cursor on the screen from which you want a screenshot. Make sure there is a program window on that screen, otherwise you will get a shot of both screens anyway. Now, press Ctrl + Alt + PrtScn on your keyboard and hit Ctrl + V to paste the screenshot.

Windows Key + P
Just press Windows Key + P and all your options pop up on the right hand side! You can duplicate the display, extend it or mirror it!

Double vs Triple equals in JavaScript

Using the triple equals, the values must be equal in type as well. Therefore, it’s always suggested to use === since that is a more thorough check and helps in avoiding bugs at a later stage. Happy Learning & Coding 🙂

Sample Code Snippet:-

1 == “1” // true
1 === “1” // false

1 != "1" // false
1 !== "1" // true

0 == false // true
0 === false // false

null == undefined // true
null === undefined // false

@Size vs @Length vs @Column

@Size and @Length are similar which are used to validate the size of a field. The first is a Java-standard annotation and the second is specific to Hibernate. Whereas @Column, is a JPA annotation that we use to control DDL statements.

Example for @Size
This annotation makes the bean independent of JPA and its vendors such as Hibernate

public class Customer {
    ...
    @Size(min = 5, max = 15)
    private String fullName;
    ...
}

Example for @Length
It is Hibernate-specific version of @Size

@Entity
public class Customer {
    …
    @Length(min = 5, max = 15)
    private String fullName;
    …
}

Example for @Column
It is used to indicate specific characteristics of the physical database column.

@Entity
public class Customer {
    …
    @Column(length = 15)
    private String fullName;
    …
}

How to resolve Connection Reset for SOAP/REST calls in SOAP-UI

If we are getting “Connection Reset” (ERROR:java.net.SocketException: Connection Reset) at endpoint URL which is TLS 1.2 enabled then we could follow given below steps for necessary tuning:-

(1) Navigate to C:\Program Files\SmartBear\SoapUI-5.2.1\bin folder.

(2) Edit SoapUI-5.2.1.vmoptions file with any text editor.

(3) Add following entry and save the file and restart SOAP-UI.

-Dsoapui.https.protocols=SSLv3,TLSv1.2

AWS DevOps

DevOps is a popular and efficient implementation of the software development lifecycle, making AWS DevOps a highly popular amalgamation. Given below are few key-points which could be referenced for the same:-

  • AWS CloudFormation:- It enables DevOps teams to create and release cloud instances and services more frequently than traditional development teams. Templates of AWS resources like EC2 (Elastic Compute Cloud) instances, ECS (Elastic Container Service) containers, and S3 (Simple Storage Service) storage buckets let you set up the entire stack without you having to bring everything together yourself.
  • AWS EC2:- You can run containers inside EC2 instances, so you can leverage the AWS Security and management features.
  • AWS CloudWatch:- This monitoring tool lets you track every resource that AWS has to offer. Plus it makes it very easy to use third-party tools for monitoring.
  • AWS CodePipeline:- It is one of the popular feature from AWS which simplifies the way you manage your CI/CD toolset. It lets you integrate with tools like GitHub, Jenkins, and CodeDeploy, enabling you to visually control the flow of app updates from build to production.

How to configure H2 Database in Spring Boot

Usually, we configure the H2 database in the web.xml file as a Servlet, but Spring Boot is using an embedded instance of Tomcat, so we don’t have access to the web.xml file. Spring Boot does provide us a mechanism to use for declaring servlets via a Spring Boot ServletRegistrationBean.

The following Spring Configuration declares the Servlet wrapper for the H2 database console and maps it to the path of /h2Console.

@Configuration
public class WebConfiguration {
	@Bean
	ServletRegistrationBean h2servletRegistration() {
		ServletRegistrationBean registrationBean = new ServletRegistrationBean(new WebServlet());
		registrationBean.addUrlMappings("/h2Console/*");
		return registrationBean;
	}
}