Pages

Tuesday 29 September 2015

Generating a Random Number (Integer) In Java

Hi all,


Today at work I just wanted to generate a Random Integer number. It was pretty easy but sometimes it may get little bit tricky. For this you need to import  to your class.

Suppose you want to generate Random numbers between a MAX and a MIN value. 

If you want to generate a number between 1 and 10, It would be like below;

Read More

Monday 28 September 2015

How to create WAR (.war) file in Eclipse of Dynamic Web Project

Hi all, today I am going to build a war(.war) file from your dynamic web project using Eclipse. You can follow these easy steps as mentioned below,

  • First open your project in Eclipse
  • Then right click on your project, from it choose export then WAR file.
Q

  • From the opened "Export" dialogue bog, Select your web project then the destination where you need to save the WAR file.
  • If you have any preferences, Select "Target Runtime" and "Export source files".


  • Then click finish. Your WAR file will be created on the folder you have given earlier.
Read More

Thursday 26 February 2015

How to Download Image using an URL (C#)


Hi All, Today I am going discuss how to get a Image from a remote location using an URL. This is very easily can be done using two .Net Classes called HttpWebRequest and HttpWebResponse

 

You need to have following References to make above code work;


Here a HTTP web request is generated using your URL and response is assigned to a System.IO.Stream object. Then your familiar System.Drawing.Image class has a method to convert that stream Object to an Image Object. That's all now you have the image in the remote location downloaded to your program.


Read More

Tuesday 7 October 2014

SQL ALTER TABLE Statement



Today I am going to talk about how to ALTER table in DBMS (Database Management System). It doesn't matter what is  your DBMS I'll do some SQL queries which will match to your requirement.

Simply, statement can be used to do alterations to an existing database table. We can identify those alterations as below;

  • Add new column.
  • Modify existing column. (Column data type)
  • Drop existing column.
  • Add Constraints.
  • Drop Constraints.
For all demonstrations below please assume that there are two tables, Employee(EmpID, EmpName) and Department(DepID, DepName). Every employee is belong to one of department.

Add New Column

Sometimes we may need to add columns to existing data tables. To do this we have to alter the existing data table. Using SQL queries we can do it in a simple way.
Using above query you can add a column named "DepID" to the table "Employee", but for existing records value of "DepID" will be NULL. 
If you want to set a default value for existing records you can use the query below


Modify Existing Column

You can change data type of an existing column as below;

Drop Existing Column

To delete (drop) column in a table you can user following SQL queries as your DBMS.


Add Constraints

You also can add constraints (Primary Key, Foreign Key, Indexes...)using this statement. Here I am adding foreign key constraint to Employee table linking Department table.


Drop Existing Constraints

This is how you can delete (drop) existing constraints.



Read More

Monday 21 April 2014

SQL Between Operator

Image from => http://tapoueh.org/images/sql-logo.png

Sometimes you may need to select values thin a range in your query. SQL has a powerful operator for this kind of situations. It is the "BETWEEN" Operator. it has a very simple syntax; let discuss it with an example.

Example 1

Above query will return all customer data whose have ID is in between 1 and 100.

Example 2


This query will return all customer data whose age is not in between 45 and 50.

Example 3


Query has use another condition with between operator. It will return all customer data whose ID is in between 1 and 100 and age is 45.

Similarly you can use Numbers, text or dates as values for between operator.

Example 4

Here query will return all the products with PRODUCTNAME beginning with any of letter between 'A' and 'D'.

Example 5

Finally values used in the between operator has to be same data type as the column data type used to select range. And this operator is inclusive operator so it select the range including the given values.

You can get similar functionality by using >= and <= operator instead of between operator as follows;

Example 6

Read More

Thursday 20 March 2014

How to Initialize Objects By Using Object Initializer (C#)




 There are many ways to initialize an object. But using this method you can initialize your object from one line of code. So this is efficient and easy for the developer. No need to write repeating object names to set the properties of the initializing object. As my experience this way it is easy to track and trace errors of your code. No more talking lets see how to do it;

I will you a class called student, then I will initialize it in the later code;
Read More

Wednesday 19 March 2014

How to Format a DateTime Object Using ToString() Method



It is very important that how we display dates and time to the user. Fortunately .Net framework facilitates us to convert DateTime objects to its equivalent string using a specific format. To do this we can use DateTime objects' ToString() method. The format should be mention within the brackets of the method. 

There are lot of formats we can use to format DateTime objects, here I have mention some commonly useful formats. First we will see standard formats;


Then some custom formats;
Above examples are working on and above .Net Framework 1.0.
Read More