Spring Dependency Injection using Constructor Injection and XML Configuration

I have used Spring way back in my career, but I have been lately using again at work. In this blog post, I am going to explain how to use dependency injection in spring using constructor injection and XML configuration. This blog post assumes you already have Java and Maven installed.

Step 1: Create a Java Project using Maven


mvn archetype:generate \
  -DgroupId=com.mycompany.productstore \
  -DartifactId=product_store_xml_constructor_injection \
  -DarchetypeArtifactId=maven-archetype-quickstart \
  -DinteractiveMode=false

Step 2: Let’s create some placeholder folders


cd product_store_xml_constructor_injection/src/main

mkdir resources

cd java/com/mycompany/productstore

mkdir model service repository

Continue reading “Spring Dependency Injection using Constructor Injection and XML Configuration”

Javascript Object Property Attributes: configurable, enumerable, value, writable

In JavaScript, an object can have two types of properties: data(standard) properties and accessor properties. Every property in an object has some attributes, this blog post we are going to take a look at the attributes of data properties.

The data properties have the following four attributes:

  • [[Configurable]] – Determines whether we can change the property
  • [[Enumerable]] – Determines whether we can iterate over the property
  • [[Value]] – It holds the value of the property
  • [[Writable]] – Determines whether we can change the value to the property

By default [[Enumerable]], [[Configurable]], [[Writable]] are true for any property we create in an object.


var product = {
  price: 100
};

In the above product object, we can loop through, change, write into the property price.

Using Object.getOwnPropertyDescriptor(object, property) method we can get the attributes of a property in an object.


var product = {
  price: 100
};

var descriptor = Object.getOwnPropertyDescriptor(product, 'price');
console.log(descriptor);

// {value: 100, writable: true, enumerable: true, configurable: true}

Continue reading “Javascript Object Property Attributes: configurable, enumerable, value, writable”

Spring Dependency Injection using Setter Injection and XML Configuration

I have used Spring way back in my career, but I have been lately using again at work. In this blog post, I am going to explain how to use dependency injection in spring using setter injection and XML configuration. This blog post assumes you already have Java and Maven installed.

Step 1: Create a Java Project using Maven


mvn archetype:generate \
  -DgroupId=com.mycompany.productstore \
  -DartifactId=product_store_xml_setter_injection \
  -DarchetypeArtifactId=maven-archetype-quickstart \
  -DinteractiveMode=false

Step 2: Let’s create some placeholder folders


cd product_store_xml_setter_injection/src/main

mkdir resources

cd java/com/mycompany/productstore

mkdir model service repository

Continue reading “Spring Dependency Injection using Setter Injection and XML Configuration”

How to change the default shell in Mac or Linux

Below I have some useful commands to view/modify the shell in Mac or Linux.

View all available shells


$ cat /etc/shells

View the current shell


$ echo $SHELL

Change the current shell to zsh


$ chsh -s /bin/zsh

We should restart the terminal after executing the above command for the new shell to take effect. In the chsh -s we can pass any one of the available shells in the machine.

Restart the shell


$ exec -l $SHELL

How to loop through or enumerate the properties of a JavaScript object?

There are multiple ways to iterate/loop through all the properties in a JavaScript object.

Method 1: for-in loop


var person = {
  name: 'Shravan Kasagoni',
  age: 20,
  isActive: true
};

person.constructor.prototype.printName = function() {
  console.log(this.name);
};

person.constructor.prototype.encKey = 'somevalue';

person.constructor.prototype.printName = function() {
  console.log(this.name);
};

The for-in loop iterates over all enumerable properties of an object.


for (var propertyName in person) {
  console.log(propertyName, person[propertyName]);
}

Result:


name Shravan Kasagoni
age 20
isActive true
printName ƒ () {
  console.log(this.name);
}
encKey somevalue

Continue reading “How to loop through or enumerate the properties of a JavaScript object?”