Friday, 11 July 2014
First Website using Servlets in J2EE

This is a step-by-step tutorial to show how to create your first website in J2EE. Some people also call it as Advanced Java. We have a .JSP page to display the website and a Java class i.e. a Action Servlet to handle the request generated in the .JSP page.

NOTE :- To create this website, you must have installed the IDE i.e. NetBeans with Apache Tomcat Server.

Here are the steps :-

Step 1 :- Create a new project.

File->New Project->Java Web->Web Application

Step 2:- 

Give it a name.

 

Step 3:- Choose the server

Please choose Apache Tomcat. If your IDE is not showing  it, then you have to reinstall the IDE and make sure that during re-installation, you customize the installation of by choosing the server. After choosing the server, click FINISH.

Step 4:-

After clicking finish button, your IDE will look like this. It means your project has been created.


Step 5:- 

Now next you have to do is edit the code in .JSP file i.e. index.jsp file.

CODE:-

    <body>
        <form action="ActionServlet" method="POST">
            <input type="text" name="text" value="" />
            <input type="submit" value="Ok" />
        </form>
    </body>

Step 6:- Create a new servlet.

Just right click the project -> New -> Servlet


Step 7:-

Give the name of servlet. THe name of the servlet must be same as you have set the value of action attribute in form. We have used " <form action="ActionServlet" method="POST"> ", so name of the servlet should be ActionServlet.


Step 8:- Configuration of Servlet Deployment

Remember to check the checkbox saying "Add information to deployment descriptor(Web.xml). It will add the information of the Servlet in Web.xml file for mapping. After that click FINISH.

Step 9:- 

Now your servlet will be created. Please change your servlet code as following.




Now your website is done. All you have to do is run your project and see your output.

Download the sample project :- Click Here

Please do comment if you have any queries. We value your comments.
Friday, 11 April 2014
Make Windows Bootable Using Commands

In this tutorial, I will show you how to make Windows Bootable using simple Commands in command prompt. Please follow the following steps :

 1. Run the command prompt [i.e. cmd] in Administrotor mode.


2. Type the first command :
diskpart

3. Find the available disks in your system:
list disk

4. Select the disk for your pen drive:
select disk 1

5. The very next command is to clean the drive :
clean

6. After that we have to divide the disk into partitions :
create partition primary

7. The first partition of disk must be selected :
select partition 1
8. activate the selected partition:
active

9. Assign the activated partition using the command:
assign
The moment you execute the assign command, a pop up will come. This pop up will ask you to format the disk.
NOTE:- If this doesn't com, Please follow the steps from beginning.

10. Format the disk in NTFS mode.

11.exit the diskpart mode:
exit


12. Copy the path of /boot/ folder of the Windows 7.

13. Change the working directory of cmd to the boot folder of the OS.
cd G:\boot
G:

14. execute the final command to install the bootcode in the pen drive:
bootsect.exe /nt60 i:
here i: is the label of pendrive.

If the output of the final command comes like shown in the above image, then your pen drive is made bootable successfully. Now you have to copy the files from the Windows folder and paste in your pen drive. That's it.

If you have any queries regarding the above post, write the comments or contact us.
Tuesday, 1 April 2014
What happens when a function is called before its declaration in C


In C, if a function is called before its declaration, the compiler assumes return type of the function as int.

For example, the following program fails in compilation.

#include <stdio.h>
int main(void)
{
    // Note that func() is not declared
    printf("%d\n", func());
    return 0;
}

char func()
{
   return 'G';
}

The following program compiles and run fine because return type of func() is changed to int.

#include <stdio.h>
int main(void)
{
    printf("%d\n", func());
    return 0;
}

int func()
{
   return 10;
}

What about parameters?
            Compiler assumes nothing about parameters. Therefore, the compiler will not be able to perform compile-time checking of argument types and parity when the function is applied to some arguments. This can cause problems. For example, the following program compiled fine in GCC and produced garbage value as output.

#include <stdio.h>
int main (void)
{
    printf("%d", sum(10, 5));
    return 0;
}
int sum (int b, int c, int a)
{
    return (a+b+c);
}

There is this misconception that the compiler assumes input parameters also int. Had compiler assumed input parameters int, the above program would have failed in compilation.

It is always recommended to declare a function before its use so that we don’t see any surprises when the program is run.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
A few C programs that won’t compile in C++


Although C++ is designed to have backward compatibility with C there can be many C programs that would produce compiler error when compiled with a C++ compiler. Following are some of them :

1) In C++, it is a compiler error to call a function before it is declared. But in C, it may compile (See http://sh.st/qMeGg)

#include<stdio.h>
int main()
{
   func(); // func() is called before its declaration/definition
   return 0;
}

int func()
{
   printf("Hello");
   return 0;
}

2) In C++, it is compiler error to make a normal pointer to point a const variable, but it is allowed in C.

#include <stdio.h>
int main(void)
{
    int const j = 20;

    /* The below assignment is invalid in C++, results in error
       In C, the compiler *may* throw a warning, but casting is
       implicitly allowed */
    int *ptr = &j;  // A normal pointer points to const

    printf("*ptr: %d\n", *ptr);

    return 0;
}

3) In C, a void pointer can directly be assigned to some other pointer like int *, char *. But in C++, a void pointer must be explicitly typcasted.

#include <stdio.h>
int main()
{
    void *vptr;
    int *iptr = vptr; // In C++, it must be replaced with int *iptr = (int *)vptr;
    return 0;
}

This is something we notice when we use malloc(). Return type of malloc() is void *. In C++, we must explicitly typecast return value of malloc() to appropriate type, e.g., “int *p = (void *)malloc(sizeof(int))”. In C, typecasting is not necessary.

4) This is the worst answer among all, but still a valid answer. We can use one of the C++ specific keywords as variable names. The program won’t compile in C++, but would compiler in C.

#include <stdio.h>
int main(void)
{
    int new = 5;  // new is a keyword in C++, but not in C
    printf("%d", new);
}

Similarly, we can use other keywords like delete, explicit, class, .. etc.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Wednesday, 26 March 2014
Program to Draw a Bouncing Ball on Surface using C++ Graphics

This is a simple C++ graphics program that draws a Bouncing Ball over a Plain Surface. This program uses simple <graphics.h> functions to draw the ball. In this program , cos function is used to bounce the ball.  setfillstyle and floodfill functions are used to fill the ball.

Program:



#include<dos.h>
#include<iostream.h>
#include<graphics.h>
#include<math.h>
#include<conio.h>
void main()
 {

   int d=DETECT,m;
   initgraph(&d,&m,"e:\tcc\bgi");
   float x=1,y=0.00000,j=.5,count=.1;
   float r=15;
   setcolor(14);
   line(0,215,650,215);
    sleep(1);
    for(int k=0;k<=7;k++)
     {

      for(float i=90;i<270;i+=10)
       {
 y=cos(((i*22/7)/180))/j;

 if(y>0)
 y=-y;
 x+=5;

 setcolor(14);
 setfillstyle(1,14);
 circle(x,y*100+200,r);
 floodfill(x,y*100+200,14);

       delay(100);

 setcolor(0);
 setfillstyle(1,0);
 circle(x,y*100+200,r);
 floodfill(x,y*100+200,0);

       }

      j+=count;
      count+=.1;

     }
   getch();
 }
  

Output :

 

You may also like:

-Snake and Ladder game in C++ : Click here
-Program for Analog Clock in C : Click here 
-Animated circles in C : Click here 
 
WCF Step by Step Tutorial


Definition of WCF

Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF we can build secure, reliable, transacted solutions that integrate across platforms.

WCF is a unified framework which provides :
      1. NET Remoting 
      2.Distributed Transactions 
      3.Message Queues and 
      4.Web Services 
into a single service-oriented programming model for distributed computing.

WCF interoperate between WCF-based applications and any other processes that communicate via SOAP (Simple Object Access Protocol) messages.

Features of WCF

    -Service Orientation
    -Interoperability
    -Multiple Message Patterns
    -Service Metadata
    -Data Contracts
    -Security
    -Multiple Transports and Encodings
    -Reliable and Queued Messages
    -Durable Messages
    -Transactions
    -AJAX and REST Support
    -Extensibility

To know more about features of WCF see: http://msdn.microsoft.com/en-us/library/ms733103.aspx

Terms of WCF

A WCF service is exposed to the outside world as a collection of endpoints.
      1. Endpoint: Endpoint is a construct at which messages are sent or received (or both). Endpoint comprises of ABC’s       
        What are ABC’s of WCF ? 
        A. Address - Address is a location that defines where messages can be sent
       B. Binding - Binding is a specification of the communication mechanism (a binding) that described how messages should be sent
       C. Contract - Contract is a definition for a set of messages that can be sent or received (or both) at that location (a service contract) that describes what message can be sent.
    2. Service: A construct that exposes one or more endpoints, with each endpoint exposing one or more service operations.
    3. Contracts: A contract is a agreement between two or more parties for common understanding and it is a is a platform-neutral and standard way of describing what the service does. In WCF, all services expose contracts.

           Types of Contracts:

           1) Operation Contract: An operation contract defines the parameters and return type of an operation.   
[OperationContract]
double Add(double i, double j);


           2) Service Contract: Ties together multiple related operations contracts into a single functional unit.
[ServiceContract] //System.ServiceModel
public interface IMath
{
    [OperationContract]
    double Add(double i, double j);
    [OperationContract]
    double Sub(double i, double j);
    [OperationContract]
    Complex AddComplexNo(Complex i, Complex j);
    [OperationContract]
    Complex SubComplexNo(Complex i, Complex j);
}

          3) Data Contract: The descriptions in metadata of the data types that a service uses. 
// Use a data contract
[DataContract] //using System.Runtime.Serialization
public class Complex
{
    private int real;
    private int imaginary;
 
    [DataMember]
    public int Real { get; set; }
 
    [DataMember]
    public int Imaginary { get; set; }
}

WCF Step by Step Tutorial

This is the Basic WCF Tutorial ‘wcfMathSerLib’ will be created in a step by step approach. This ‘wcfMathSerLib’ will be tested by ‘ConsoleMathClient’ and with ‘WCF Test Client’

Steps for creating wcfMathSerLib

1. Create a new project.
      a. Open Visual Studio 2010 and File->NewProject
      b.select WCF in ‘Recent Templates’
      c.select ‘WCF Service Library’
      d.Give Name as wcfMathServiceLibrary
      e.Click OK

2. Delete IService1.cs and Service1.cs
3. Add IMath.cs and MathService.cs and add the code listed below

IMath.cs

using System.Runtime.Serialization;
using System.ServiceModel;
 
namespace WcfMathServLib
{
    [ServiceContract] //System.ServiceModel
    public interface IMath
    {
        [OperationContract]
        double Add(double i, double j);
        [OperationContract]
        double Sub(double i, double j);
        [OperationContract]
        Complex AddComplexNo(Complex i, Complex j);
        [OperationContract]
        Complex SubComplexNo(Complex i, Complex j);
    }
 
    // Use a data contract
    [DataContract] //using System.Runtime.Serialization
    public class Complex
    {
        private int real;
        private int imaginary;
 
        [DataMember]
        public int Real { get; set; }
 
        [DataMember]
        public int Imaginary { get; set; }
    }
}

MathService.cs

namespace WcfMathServLib
{
    public class MathService : IMath
    {
 
        public double Add(double i, double j)
        {
            return (i + j);
        }
 
        public double Sub(double i, double j)
        {
            return (i - j);
        }
 
        public Complex AddComplexNo(Complex i, Complex j)
        {
            Complex result = new Complex();
            result.Real = i.Real + j.Real;
            result.Imaginary = i.Imaginary + j.Imaginary;
            return result;
        }
 
        public Complex SubComplexNo(Complex i, Complex j)
        {
            Complex result = new Complex();
            result.Real = i.Real - j.Real;
            result.Imaginary = i.Imaginary - j.Imaginary;
            return result;
        }
    }
}

4.Modify the App.config file as shown
App.config

<configuration>
 
  <system .web="">
    <compilation debug="true">
  </compilation></system>
 
  <system .servicemodel="">
    <services>
      <service name="WcfMathServLib.MathService">
 
        <host>
          <baseaddresses>
            <add baseaddress="http://localhost:8732/Design_Time_Addresses/WcfMathServLib/MathService/">
          </add></baseaddresses>
        </host>
 
        <!-- Service Endpoints -->
        <endpoint address="" binding="wsHttpBinding" contract="WcfMathServLib.IMath">
          <identity>
            <dns value="localhost">
          </dns></identity>
        </endpoint>
 
        <!-- Metadata Endpoints -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
      </endpoint></service>
    </services>
    <behaviors>
 
      <servicebehaviors>
        <behavior>
           <servicemetadata httpgetenabled="True">
          <servicedebug includeexceptiondetailinfaults="False">
        </servicedebug></servicemetadata></behavior>
      </servicebehaviors>
    </behaviors>
 
  </system>
 
</configuration>

Result Using WCF Test Client


1. Run the WcfMathServLib project you will get the ‘WCF Test Client’
2. Select each method say ‘AddComplexNo’ Give the values in ‘Request’
3. Click on Invoke button
4. See the results in “Response”

Steps for creating ConsoleMathClient

1. Create a new C# project
     a. Open Visual Studio 2010 and File->NewProject
     b. select Visual C#->Windows in ‘Installed Templates’
     c. select ‘Console Application’
     d. Give Name as ConsoleMathClient
     e. Click OK



2. Go to ‘Solution Explorer’ Right click on ConsoleMathClient -> Select ‘Add Service
Reference’ the below dialog will be displayed
    a. Click on Discover button
    b. Give namespace as ‘MathServiceReference’ and click OK

The service reference will be added now modify the program.cs as shown below.

Program.cs

using System;
using ConsoleMathClient.MathServiceReference;
 
namespace ConsoleMathClient
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Press <Enter> to run the client....");
            Console.ReadLine();
 
            MathClient math = new MathClient();
            Console.WriteLine("Add of 3 and 2 = {0}", math.Add(3, 2));
            Console.WriteLine("Sub of 3 and 2 = {0}", math.Sub(3, 2));
 
            Complex no1 = new Complex();
            no1.Real = 3;
            no1.Imaginary = 3;
 
            Complex no2 = new Complex();
            no2.Real = 2;
            no2.Imaginary = 2;
 
            Complex result = new Complex();
            result = math.AddComplexNo(no1, no2);
            Console.WriteLine("Add of 3+3i and 2+2i = {0}+{1}i", result.Real, result.Imaginary);
 
            result = math.SubComplexNo(no1, no2);
            Console.WriteLine("Sub of 3+3i and 2+2i = {0}+{1}i", result.Real, result.Imaginary);
 
            Console.ReadLine();
        }
    }
} 

Result

Compile and Run the project to see the Result

Keep in touch for more updates. Contact Us for any queries.

You may also like:

Developing a Gadget for Windows Sidebars (Gadgets) : Click here
Tuesday, 25 March 2014
Sony launches Xperia Z2 - a new way of gaming

The Nokia Lumia 1520 was crowned "Best gaming device" at the beginning of the month but the HTC One (M8) stole that title and an even bigger one - it reached top place on Basemark OS II, which is an overall benchmark.

That didn’t last too long though, as less than 24 hours later the Sony Xperia Z2 displaced the One (M8) at the Basemark OS II bench. The two scored identical in the CPU and GPU test, but faster memory performance helped the Sony smartphone reach the top spot.

The Xperia Z2 is currently third in the gaming benchmark, but an update could push it forward – after all the M8 and Z2 use the same chipset and display resolution.
Web browsing also might see an improvement, since the Xperia Z2 is currently 7th, behind the Xperia Z1 at 6th place. The Sony flagship isn't officially available yet so such improvements are normal as the software reaches completion. Also, Basemark OS II, X and BrowserMark 2 are separate apps and a result in one doesn’t update the others.

Anyway, how long with Xperia Z2 last? The Samsung Galaxy S5, which has faster CPU is the likely phone to top it, though the Sony's 3GB RAM might be enough to keep the Z2 in front.

Specifications :

Weight
    -163 grams

Dimensions
    -146.8 x 73.3 x 8.2 mm

Camera
    -20.7 MP camera

Display
    -5.2” Full HD TRILUMINOS™ Display for mobile with X-Reality for mobile picture engine
    -16,777,216 colours Full HD 1920x1080 pixels

On the inside
    -Google Android 4.4 (Kitkat)
    -2.3 GHz Qualcomm MSM8974AB Quad-core

Durability
    -Waterproof (IP55 and IP58) ****
    -Dust-resistant (IP55) ****

Battery
    -Talk time: up to 19 hours***
    -Standby time: up to 740 hours***
    -Music listening time: Up to 120 hours***
    -Video playback time: Up to 10 hours***
    -Battery: 3200 mAh minimum


Keep in touch for more updates. Contact Us for any queries.

Facebook launches HACK Programming Language

Social networking site Facebook has brought out a new programming language, known as Hack. The name may confuse you but don't be baffled, as its a developmental tool. Some experts claim that Hack is a new version of PHP language, the one used by Mark Zuckerberg for developing Facebook.
A sample code of HACK Programming Language.
 This new programming language, designed by Facebook will provide programmers a platform to build complex websites and other software faster, with lesser flaws. According to a news report, Bryan O'Sullivan, the Facebook engineer who is the lead brain behind Hack, said, "We can say with complete assurance that this has been as battle-tested as it can possibly be," in a statement.

Earlier, Facebook co-founder Zuckerberg used PHP to build the social network for nearly a decade. It is said that the need to develop this new language originated due to the heavy growth of Facebook. Since with PHP, the set up required large computer servers to run the site, as compared to other languages. The difficulty in managing all the complex codes with bugs-free environment led the company to build the new programming tool that targets specifically at easing complex sites and compound software.

"You edit a file and you reload a web page and you immediately get the feedback. You get both safety and speed," added O'Sullivan. Hack's benefits come without slowing down the developer, as can run without compiling.

However, the new language also runs on the Hip Hop Virtual Machine, but it allows coders and programmers the liberty to use both dynamic typing and static typing.

The Facebook Inc. engineers say that there’s a deep connection between Hack and PHP and that most PHP files are already valid for Hack. They added static typing and made type checking incremental so that not all of the code in a single file must be converted to Hack. They call Hack a “gradually typed” language in which “dynamically typed code interoperates seamlessly with statically typed code.”

Keep in touch for more updates. Contact Us for any queries.

Wednesday, 19 March 2014
Creating Wi-Fi Hotspot using Connectify Tool



Connectify is a Wi-Fi Hotspot creating tool that you can use if you think virtual router's free version is missing some useful features.
connectify-tool-windows
You might be using a Hi Speed dongle for 3G internet access or a Broadband Connection using LAN Cable, if you do not have a Router installed in your home than you cannot access a Internet Connection on your other handheld devices, but with Connectify this can be connected easily with just one click. With Connectify you can simply connect unlimited devices to your computers internet connection, pairing is really easy and can be done in few minutes using Wi-Fi.
  1. Download Connectify Software for your PC.
  2. Now after you have downloaded it, just install it in a normal way and after successful installation you will be promoted to Reboot your computer do that its important.
    • Now after Reboot it will automatically start and show window like in the image above, just change the name if you want too and add a 8 digits password.
    • Now choose the internet connection you wanna share I am sharing my MTS 3G Dongle internet connection with my iPhone.
    • So after you have chosen the connection, just pick up how you wanna share your connection the best one is Wi-Fi but if you don’t have than you can choose Bluetooth or any other mentioned.
    • Now just click on Start Hotspot and you Hotspot is ready to be searched and to be connected, just open your mobile Wi-Fi settings menu and search for available connection and you will see the above name you have mentioned displaying just hit that and enter the 8 digits password you kept.
    • Now you are connected with your Internet Connection, so now you can browse or do anything you wanted to do, well you can see how many people are connected in the second window in the above image, that’s just for keeping track on people using your Wi-Fi connection.
    So now enjoy Internet Connection Tethering for free and easily on your any handheld devices equipped with Wi-Fi, well this tool works fine but we one another tool that claims to be working quite well so you can check that too.