Tutorials

Thursday, September 15, 2016

Wi-Fi Hotspot in Windows 10


This blog will be explained, how create a Wi-Fi hotspot in windows 10 using cmd.

Step 1
Switch on Wi-Fi in your computer. 

Step 2
Launch the command prompt.

Step 3
Then type below command to create the hotspot.

NETSH WLAN set hostednetwork mode=allow ssid=My_Hotspot key=19920218

Here,

ssid - Name of the Wi-Fi hotspot.
key - Password of the Wi-Fi hotspot (at least 8 characters).

Step 4
Using below command, created Wi-Fi hotspot can be started.

NETSH WLAN start hostednetwork

Step 5
To stop the started Wi-Fi hotspot, type below command.

NETSH WLAN stop hostednetwork





Wednesday, August 3, 2016

Factory Design Pattern

Hi, today I'm going to give you an explanation about the Factory Design Pattern. 

Design Patterns

Design patterns provide solutions for general problems that software developers face during their software developments. These solutions were obtained by the experienced object-oriented software developers as best practices to solve their problems. Design Patterns can be categorized for three main categories. They are,


  • Behavioral - Describe the interactions and focus on how communicate between the objects.
  • Creational - Create objects for a suitable class.
  • Structural - Construct larger structures from single parts (classes and objects).

Factory Pattern

Factory Design Pattern is one of the most popular design pattern in usage and it can be categorized under creational pattern. Using this design pattern , developers can create objects without exposing the creational method to the clients. As well as the developer can refer the newly created object using a common interface.

Understand Factory Pattern


We are going to discuss a simple example to understand the Factory Design Pattern. Here we are going to create Colors interface and  Red, Green and Blue concrete classes implementing the Colors interface. ColorsFactory class creates the Colors objects. DemonstrateFactoryPattern class is used ColorsFactory class to get the Colors objects. Below class diagram describes the Example that we are going to discuss.


If I explain simply about above class diagram, DemonstrateFactoryPattern class provide information about the object that needs ("Red/Green/Blue"). Then ColorsFactory class generates the object according to provided information.

Now let's see how implements the above example using Java.


  • Creates Colors interface


Colors.java

public interface Colors {
    public void generate();
}

  • Create concrete classes implementing the Colors interface
Red.java

public class Red implements Colors {
    @Override    public void generate() {
        System.out.println("This is Red Color");    }
}

Green.java

public class Green implements Colors {
    @Override    public void generate() {
        System.out.println("This is Green Color");    }
}

Blue.java

public class Blue implements Colors {
    @Override    public void generate() {
        System.out.println("This is Blue Color");    }
}


  • Create a Factory to generate objects according to provided information.


public class ColorsFactory {

//create getColor method to generate objects according to provided information
    public Colors getColor(String colorName) {

                if(colorName.equals("Red")){
              return new Red();          
  } else if(colorName.equals("Green")) {
              return new Green();        
  } else if(colorName.equals("Blue")) {
              return new Green();        
  } else return null;
    }
}

  • Create a class to pass information and get the object


DemonstrateFactoryPattern.java

public class DemonstrateFactoryPattern {

    public static void main(String[] args) {

        //create object of ColorsFactory        
 ColorsFactory colorsFactory = new ColorsFactory();

        //get an object of Red and call it's generate method.        
 Colors red = colorsFactory.getColor("Red");        
 red.generate();

        //get an object of Green and call it's generate method.        
 Colors green = colorsFactory.getColor("Green");        
 green.generate();

        //get an object of Blue and call it's generate method.        
 Colors blue = colorsFactory.getColor("Blue");        
 blue.generate();    }
}

  • Outputs

The outputs should be as below.

This is Red Color
This is Green Color
This is Green Color



Thursday, July 28, 2016

Save Sinhala Unicode Characters in MySQL

Here I am going to explain how to save Sinhala Unicode Characters in a MySQL table. It is not a very hard thing to do. Only thing that need to do is, set “COLLATE” type as “utf8_unicode_ci”. Below I have explained step by step, how to do that using phpmyadmin in WAMP Server.


Step 1 : Start WAMP and then open phpmyadmin.

Step 2 : Create a new database as below. Set the database name and Collate type as                                           “utf8_unicode_ci”.



Step 3: Now create a table describes as below. Set “Collation” to “utf8_unicode_ci” in every table column.

After successfully creating the table, you can insert Sinhala Unicode characters to the table.