Source Control also known as Version/Revision Control which aid in the management of the software configuration, source code changes and other collections of information.
In Software Development, source control has been employed in the need to keep track of development releases and where there are many developers need to work together to make large complex software systems, therefore the need for Version Control Systems(VCS). The source control mostly is managed according to changes of source code which is related to time.
Before Version Control Systems came into play there was Report Control Systems(RCS) which was a software implementation of revision control that automates the storing, retrieval, logging, identification, and merging of revisions. Revision Control System is also capable of handling binary files, though with reduced efficiency. Examples of VCS would be Apache svn, Git, Mercury, and others.
Wednesday, 20 November 2013
Source Control
Design Patterns
A design pattern is a reusable solution that can be implemented on software problems that commonly occur in development. There are very many design patterns that are employed in software design and they are classified according using concepts such as delegation(representation), aggregation(constituent components), consultation(reference) which are into groups, creational patterns, behavioral patterns, structural patterns and concurrency patterns. There is another architectural design pattern that is also becoming very common Model-View-Controller pattern. Object-oriented design patterns typically show relationships and interactions between classes or objects.
Creation Design Patterns
Based on object creations although could result in design problems or added complexity to the design. The approach is to solve this problem is control of object creation. They are grouped further into Class creational and Object creational patterns. Well-known design patterns;-
- Abstract Factory pattern
- Builder pattern
- Factory method pattern
- Prototype pattern
- Singleton pattern
Behavioral Patterns
In software engineering, behavioral design patterns are design patterns that identify common communication patterns between objects and realize these patterns. By doing so, these patterns increase flexibility in carrying out this communication.
Examples;-
- Observer pattern also known as Publisher/Subscriber pattern;-
Objects register to observe an event that may be raised by another object.The observable object holds reference to many observer objects that are registered(subscribed) to it and can be removed(unsubscribed). The observable gives information(publishes) to the observers(subscribers) that are registered(subscribed) and also updates the observers too.
- Iterator pattern
- Chain of responsibility pattern
- Command pattern
- State pattern
- Strategy pattern
- Template method pattern
- Visitor pattern
- Null object pattern
Structural Patterns
Design patterns that ease the design by identifying a simple way to realize relationships between entities(aggregation).
Examples:
- Facade pattern - create a simplified interface of an existing interface to ease usage for common tasks.
- Adapter pattern
- Aggregate pattern
- Decorator pattern
- Composite pattern
- Proxy pattern
- Pipes and Filters pattern
Concurrency Pattern
Concurrency design patterns are those types of patterns that deal with the multi-threaded programming paradigm. Examples:
- Thread pool pattern - acts in a round-robin fashion.
- Monitor Object pattern
- Balking pattern
- Double-checking locking pattern
- Guarded suspension pattern
- Reactor pattern
- Read-write lock pattern
- Scheduler pattern
- Thread-specific pattern
MVC(Model-View-Controller) pattern
In Software Architecture, it is a design pattern that involves de-coupling of business rules, data, functions, logic from user's interaction with it. The Model consists of business rules, data, logic, functions and View consists of representation of data, such as a diagram. Controller is the mediator of communication between the two, Model and View.
Tuesday, 19 November 2013
PHP 5 Configuration
As a developer so far I have dealt with two web servers using PHP 5 on it that I would give you directives on how to setup the machine for running of your web applications. There are two web servers which I know Apache web server and Information Internet Services(IIS) web server.
Using Apache
You can start decide to start on whatever software to start installing either server or parser and Database Software preferably MySQL then configure afterwards.
- Download right package of the web server and PHP 5 parser, that is, Apache 2(or version above) which may come in form of different packages, i.e., WAMP(Windows Apache MySQL), XAMPP(Cross-platform Apache MySQL PHP Perl) which eases your work to download in single packages. For now, we'll use AMP(Apache MySQL PHP) which you will install each in a single package, i.e., download Apache 2(or above version), PHP 5(or above version) which should be an archive(.zip, or .tar file) and MySQL 5(or above version).
- Install Apache Server into your system and then you are supposed to see your web server at the taskbar up and running but its not yet configured for PHP. Still you can go to 'http://localhost/' on your browser you should see that it will display a default 'index.html' page.Its OK.
- Install PHP 5 package by extracting the package contents into your root directory, that is, C:\ and then copy file 'php-ini-development' or 'php-ini-dist' to a folder named backup on your desktop. You'll need it if anything compromise on your environment happens in future.
- Install MySQL package which should be an executable file package and choose standard configuration where prompted. Enter your new password and I would advise you to save the password somewhere safe if you forget easily because you don't want future distress from failure to connecting to database. Don't change any other options just leave them the way they are. Don't forget to select option of 'Add to your bin directory to your Path'.
- Move to PHP 5 directory and you remember the 'php-ini-dist' file rename it to 'php.ini' file and open it with your text editor to configure. Find 'doc_root = ' in the file and change by adding the directory to "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs" directory which is the default on Apache server or you may search on 'httpd' file on 'conf' directory that resides on web server root directory and search value for 'DocumentRoot ' so after it should be like this, 'doc_root = C:\Program Files\Apache Software Foundation\Apache2.2\htdocs'. Find 'extension_dir = ' and remove ';' if it has one and change it to by adding 'C:\<PHP 5 installation>\ext' at the end of '= ' should be like this, 'extension_dir = C:\PHP5\ext'. Find ';extension=' and uncomment by removing the ';' at the start of it for the following 'php_mysqli.dll', 'php_gd2.dll' only those which will allow you to connect to the database and the graphics library. Also uncomment 'session.save_path = "C:\Windows\Temp"' and change it if it has no or different value directory given.
- Finally before we done with PHP 5 configuration add the PHP 5 directory to your PATH. If you don't know refer to my post on java configuration on this blog.
- Go to Apache web server directory and move to conf directory you will copy the 'httpd' file to backup folder you backed up the 'php-ini-dist' file. You will need it if your web server gets compromised in future. Open 'httpd' file in text editor find '<IfModule dir_module>' and add between the tags after the 'index.html' add 'index.php' which must have a space between them. The 'index.php' file might be any of your wish, e.g., test.php or any other php file which we'll be the default php file. After the changes it should be like this, 'DirectoryIndex index.html index.php'.
- Finally add module to handle PHP applications, that is, add the following lines at the end of the file.
LoadModule php5_module "C:\PHP\php5apache<version>.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:\PHP"
Using IIS
- First you will need PHP 5 and MySQL 5 installed but you do not need it configured.
- Hold Ctrl Key and punch R to get Run dialog window type in 'inetmgr' to get IIS manager window.
- On IIS Manager, and then move to the server level.
- Double-click Handler Mappings.
- In the Actions pane, click Add Module Mapping.
- In the Add Module Mapping dialog box, specify the configuration settings as follows:
- Request path: *.php
- Module: FastCgiModule
- Executable: C:\[Path to your PHP installation]\php-cgi.exe
- Name: PHPviaFastCGI
- Click OK.
- In the dialog box that asks you to confirm that you want to create a FastCGI application for the executable, click Yes.
- To verify that the handler mapping works correctly, create a Phpinfo.php file in the C:\inetpub\wwwroot folder that contains the following:
<?php phpinfo(); ?>
- Open a Web browser, and then navigate to http://localhost/phpinfo.php. If everything was set up correctly, you will see the standard PHP information page.
Kudos!
Friday, 8 November 2013
ACID
In Software Engineering, it is a software methodology consisting of set of properties to ensure there is guarantee during processing(committing) of the database transactions is reliable as planned to maintain integrity and security. A transaction by definition is a single logic unit of operation on data, that is, database which involves one or more SQL queries to be executed. In java, JTA API also involves the employment of ACID philosophy to ensure integrity of transactions for business applications. Deployments that ACID is also employed is in software testing for QA (Quality Assurance) and also software security to make an IDS (Intrusion Detection System).
Acid
Consistency
Isolation
Durability
Atomicity
This supposes that the transaction being committed (sent to the database to be stored) if any part of its SQL queries fails the whole of it is compromised and is considered as a failure or all of its parts successful to be considered complete and successful. The transaction is said to constitutes very small (atomic) indivisible operations, that is, SQL queries that make up a transaction.
Consistency
The operations must be valid according the rules or standards specified which are predefined to be followed which ensures the data committed is consistent as specified.
Isolation
By providing isolation we can have concurrency on the happening of transactions, that is, the database operations happen or occur at the same time without interference from other operations.
Durability
The data being stored in the database is permanently stored and can be recovered in case of any power shortages, or system failures.
Tuesday, 6 August 2013
Google's Hacking Incidence
Google's is one of the most popular and high traffic web search engines that happen to be a victim of hacking last year when some mathematician attempted to hack Google's 256-bit SSL encryption key. The mathematican is said to have no malicious intent who instead contacted Google on its weakly encrypted system. Google is said to have admitted about the incidence but didn't notice it until the hacker notified them.
Java Native Interface
A programming interface where java programming language interacts with native programming languages such as C/C++. As a programmer I found it hard to resolve away to communicate with native languages especially C which java derives much of its syntax. The following sample code worked well with C and C++ on windows platform and may also work well on other platforms like UNIX.
I'll give first C sample code which you must have the compilers configured before doing any of these procedures.
Using C language;
First open your editor and save the code below in a java source file (.java extension), that is, "HelloWorld.java".
class HelloWorld {
private native void print();
public static void main(String[] args) {
new HelloWorld().print();
}
static {
System.loadLibrary("HelloWorld"); // loads HelloWorld.dll library file
}
}
then save the code below in a C source file (.c extension), that is, "HelloWorld.c".
#include <jni.h>
#include <stdio.h>
#include "HelloWorld.h"
JNIEXPORT void JNICALL
Java_HelloWorld_print(JNIEnv *env, jobject obj)
{
printf("Welcome to JNI using C!\n");
return;
}
Lastly you should have a batch script to execute your commands so save the following contents in "build.bat" file.
javac HelloWorld.java
javah HelloWorld
cl /I"C:\Program Files\Java\jdk1.7.0_01\include" /I"C:\Program Files\Java\jdk1.7.0_01\include\win32" /I"C:\Program Files\Microsoft Visual Studio\VC98\Include" /I"C:\Program Files\Microsoft Visual Studio\VC98\Lib" HelloWorld.c /Fe"HelloWorld.dll" /LD
java HelloWorld
You should have a similar output.
Using C++ language;
Open your text editor and save the following contents in a .java file, that is, "JNIPrintWrapper.java".
// File: JNIPrintWrapper.java
// Allows access to native methods
public class JNIPrintWrapper
{
// load library JNIPrintLibrary into JVM
static
{
System.loadLibrary( "JNIPrintWrapper" );
}
// native C++ method
public native void printMessage( String message );
}
save the following in a java source file, that is, "JNIPrintMain.java".
// File: JNIPrintMain.java
// Creates a new instance of the Java wrapper class,
// and calls the native methods.
public class JNIPrintMain{
// uses JNI to print a message
public static void main( String args[] )
{
JNIPrintWrapper wrapper = new JNIPrintWrapper();
// call to native methods through JNIWrapper
wrapper.printMessage( "Welcome to JNI using C++!\n" );
}
}
save the following in a C++ source file, that is, "JNIPrintWrapperImpl.cpp".
// File: JNIPrintWrapperImpl.cpp
// Implements the header created by Java
// to integrate with JNI.
// C++ core header
#include <iostream.h>
// header produced by javah
#include "JNIPrintWrapper.h"
// prints string provided by Java application
JNIEXPORT void JNICALL Java_JNIPrintWrapper_printMessage
( JNIEnv * env, jobject thisObject, jstring message )
{
// boolean to determine if string is copied
jboolean copied;
// call JNI method to convert jstring to cstring
const char* charMessage =
env->GetStringUTFChars( message, &copied );
// print message
cout << charMessage;
// release string to prevent memory leak
env->ReleaseStringUTFChars( message, charMessage );
}
You should have a similar output as shown below.
Java Networking
Java is notably known to have good network capabilities that make the java programming world fun especially when it comes to communication. Here is a sample program code to show Client-Server and Server-Client communications using java networking capabilities.
Here is the Client source code.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.*;
import java.util.Scanner;
/*
* A simple demonstration of setting up a Java network client.
*/
public class Client
{
static Scanner scanner = new Scanner(System.in);
// static ServerSocket server;
static Socket sock;
public static void main(String[] argv) {
String server_name = "localhost";
String client_msg = null;
try {
sock = new Socket(server_name, 14323);
/* Finally, we can read and write on the socket. */
System.out.println(" *** Connecting to " +
sock.getInetAddress().getHostName() + ":" +
sock.getLocalPort() + " ***\n");
while(sock.isConnected())
{
// System.out.println(" *** Connected ***\n");
System.out.print("Enter message:");
client_msg = scanner.nextLine();
//send message to server
sendMessage(client_msg);
// wait for server's message
// display new message from server
receiveMessage();
// handle connections
// handle(sock);
}
/* . do the I/O here .. */
if(!sock.isClosed())
{
sock.close( );
System.out.println("\nSocket closed\n");
}
} catch (java.io.IOException e) {
System.err.println("error connecting to " +
server_name + ": " + e);
return;
}
}
protected static void sendMessage(String msg) throws IOException
{
if(msg == "" || msg == null)
return; // exit method
sock.getOutputStream().write(msg.getBytes());
System.out.println("\nMessage sent.");
}
protected static void receiveMessage() throws IOException
{
String recvmsg = "";
int size = 256;
byte[] buff = new byte[size];
sock.getInputStream().read(buff);
for(int i = 0; i < buff.length; i++)
{
if(buff[i] != buff[255])
recvmsg += (char)buff[i];
}
System.out.println("\nServer: " + recvmsg);
}
}
Here is the Server source code.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
/**
* Listen -- make a ServerSocket and wait for connections.
*/
public class Server {
/** The TCP port for the service. */
public static final short PORT = 14323;
protected static ServerSocket sock;
protected static Socket clientSock;
protected static Scanner scanner;
public static void main(String[] args) throws IOException
{
scanner = new Scanner(System.in);
String servermsg;
try {
sock = new ServerSocket(PORT);
System.out.println("\nListening on port " +
sock.getLocalPort());
// receive first message
clientSock = sock.accept();
while ((clientSock.isConnected()))
{
// System.out.println("Accepting from client " +
// clientSock.getInetAddress().getHostName() +
// ":" + clientSock.getLocalPort() + "\n");
// wait for client's message first
// display new client's message
receiveMessage();
// get server's message from standard input
System.out.print("Enter message: ");
servermsg = scanner.nextLine();
// send server's message
sendMessage(servermsg);
}
}
catch (IOException e)
{
System.err.println(e);
}
finally
{
sock.close();
clientSock.close();
}
}
static void receiveMessage() throws IOException
{
int size = 256;
byte[] recvbuff = new byte[size];
clientSock.getInputStream().read(recvbuff);
System.out.print("Client: ");
for(int i = 0; i < recvbuff.length; i++)
{
if(recvbuff[i] != recvbuff[255])
System.out.print("" + (char)recvbuff[i]);
}
System.out.println();
}
static void sendMessage(String msg) throws IOException
{
if(msg == "" || msg == null)
return; // exit method
int size = msg.getBytes().length;
byte[] sendbuff = new byte[size];
sendbuff = msg.getBytes();
clientSock.getOutputStream().write(sendbuff);
System.out.println("\nMessage sent.\n");
}
}
Here is the impressive output I heard you should have something similar on windows.
Subscribe to:
Posts (Atom)




