Archive for February, 2013

Change Icon of an EXE FileSome times it becomes necessary to change the icon of an executable (.exe) file so that the file get’s a new appearance. Many of the tools such as TuneUP Winstyler does this job by adjusting the Windows to display a custom icon to the user. But, in reality if the file is carried to a different computer, then it shows it’s original icon itself.

This means that in order to permanently change the icon, it is necessary to modify the executable file and embed the icon inside the file itself. When this is done the executable file’s icon is changed permanently, so that even if you take file to a different computer it show’s a new icon.

For this purpose I have found a nice tool which will modidify the executable file and embed the icon of your choice into the file itself. ie: The tool changes the icon of the executable file permanently.

I will give you a step-by-step instruction on how to use this tool to change the icon:

  1. Go to www.shelllabs.com and download the trial version of IconChanger and install it (Works on XP, Vista and Win 7).
  2. Run the IconChanger program from Start -> All Programs and you should see an interface as shown below:

    IconChanger-Screenshot

  3. Now you will see a window stating that “Choose an object whose icon you want to change”. Click on the “OK” button.
  4. Now select the executable file for which you wish to change the icon.
  5. Icon changer will automatically search for all the icons on your “C:\ drive” so that you can select any one of those. If your desired icon is not shown in the window, you may paste the path of your icon file in the field which says “Search icons in” so that your desired icon gets displayed.
  6. Select the ICON of your choice and click on Set button.
  7. Now a popup window will appear and ask you to select from either of these two options.
    • Change embeded icon.
    • Adjust Windows to display custom icon.
  8. Select the first option (Change embedded icon). You are done. The icon get’s changed.

I hope you like this post. Pass your comments in case if you have any queries or clarifications.

 

How to compile C programsIn many of my previous posts especially in the VIRUS CREATION section, I have used C as the programming language for writing the programs. If you’re new to C programming and find it difficult to compile the C source codes then this post is for you.

Here is a step-by-step procedure to install Borland C++ compiler 5.5 on your PC and compile the C programs.

How to Install Borland C++ compiler?

Follow the below steps to install Borland C++ compiler 5.5 on your PC:

  1. Download Borland C++ compiler 5.5 (for Windows platform) from the following link:
  2. After you download, run the file C++5.51.exe. The default installation path would be:
    C:\Borland\BCC55

How to configure Borland C++ compiler?

Here is a step-by-step instruction on how to configure the compiler:

  1. After you install Borland C++ compier, create two new Text Documents.
  2. Open the first New Text Document.txt file and add the following two lines into it:

    -I”c:\Borland\Bcc55\include”

    -L”c:\Borland\Bcc55\lib”

    Save changes and close the file. Now rename the file from New Text Document.txt to bcc32.cfg.

  3. Open the second New Text Document (2).txt file and add the following line into it:
    -L”c:\Borland\Bcc55\lib”

    Save changes and close the file. Rename the file from New Text Document (2).txt to ilink32.cfg.

  4. Now copy the two files bcc32.cfg and ilink32.cfg, navigate to C:\Borland\BCC55\Bin and paste them.

How to Compile the C Source Code (.C files)?

Here is a detailed instruction on how to compile C source codes:

  1. You need to place the .C (example.c) file to be compiled in the following location:
C:\Borland\BCC55\Bin
  1. Now go to the command prompt (Start->Run->type cmd->Enter)
  2. Make the following path as the present working directory (use the CD command):
C:\Borland\BCC55\Bin
  1. To compile the file (example.c) use the following command:
bcc32 example.c
  1. Now if there exists no error in the source code, you’ll get a compiled executable module (example.exe) in the same location (C:\Borland\BCC55\Bin).
  2. Now you have successfully compiled the source code into an executable file(.exe file).
NOTE: The above tutorial assumes that you’ve installed the compiler onto the C: drive (by default).

Different Types of MalwareMalware is a collective term used to represent virus, worms, spyware and other malicious programs out there on the Internet. In simple words, any software program that is intended to cause direct or indirect harm to the computer system is referred to as a malware.

Some malware programs cause serious problems such as destroying the system files, causing disruption to the computer operation or gathering sensitive information while others may only have a light impact such as redirecting websites to pornographic content or annoying the users with pop-ups and banners.

In the normal routine, we have often seen every malicious program being referred to as a virus, but this is not correct! In fact, as mentioned earlier, there exists several malicious programs where virus is one among them. Now, many of you may be wondering to know what’s the difference between them. Well, this article gives a detailed information on different types of malware that exist, how they work and how they differ from each other:

Computer Virus:

As we all know, this is the type of malware that has become highly popular and is one of the most widely discussed topic in the field of computer security. A virus is just a computer program that is designed to take unauthorized control of the infected computer so as to cause harm to the system’s data or degrade its performance.

Mode of operation:

Computer viruses operates by attaching themselves to an already existing file or program and replicates itself to spread from one computer to another. In most cases, they tend to infect executable files that are parts of legitimate programs. So, whenever the infected file is executed on a new computer, the virus gets activated and begins to operate by further replication or causing the intended damage to the system.

A virus cannot perform its task of harming and replication unless it is allowed to execute. This is the reason why viruses often choose an executable file as its host and get attached to them. Viruses are mainly classified into two types:

Non-Resident Viruses: This kind of virus will execute along with its host, perform the needful action of finding and infecting the other possible files and eventually transfers the control back to the main program (host). The operation of the virus will terminate along with that of its host.

Resident Viruses: In case of resident viruses, whenever the infected program is run by the user, the virus gets activated, loads its replication module into the memory and then transfers the control back to the main program. In this case, the virus still remains active in the memory waiting for an opportunity to find and infect other files even after the main program (host) has been terminated.

Damages caused:

Viruses are known to cause destruction of data and software programs. In some cases, a virus may do nothing other than just replicating itself. However, they are responsible for using a large portion of the system resources such as CPU and memory which results in the performance degradation of the computer.

In order to stay protected from a virus infection, you may refer my other post on 12 tips to maintain a virus free computer.

Trojan horse:

A Trojan horse or simply called as Trojan is a type of malicious program that disguises itself as something that is legitimate or useful. The main purpose of a trojan is to gain the trust of the user from the front end, so that it gets the permission to be installed. But, from the back end, it is designed to grant unauthorized control of the computer to the hacker.

Mode of operation:

A Trojan horse do not depend on the host to carry out its operation. So, unlike a computer virus, it does not tend to attach itself to other files. Trojans are often disguised as video codecs, software cracks, keygens and other similar programs downloaded from untrusted sources. So, one has to be careful about those untrusted websites that offer free downloads.

One of the most poplar example is the DNSChanger trojan that was designed to hijack the DNS servers of the victimized computers. It was distributed by some of the rogue pornographic websites as a video codec needed to view online content.

Damages caused:

Trojan horses are known to cause a wide variety of damages such as stealing passwords and login details, electronic money theft, logging keystrokes, modify/delete files, monitor user activity etc.

Worms:

Worms are standalone computer programs with a malicious intent that spread from one computer to another. Unlike viruses, worms have the ability to operate independently and hence do not attach themselves to another program.

Mode of operation:

Worms often use a computer network to spread itself by exploiting the security vulnerabilities that exist inside the individual computers. In most cases, worms are designed only to spread without causing any serious change to the computer system.

Damage caused:

Unlike viruses, worms do not cause damage to the system files and other important programs. However, they are responsible for consuming the bandwidth thereby degrading the performance of the network.

Spyware:

Spyware is a type of malicious software that can collect information about the activities of the target computer without the knowledge of its users. Spywares such as keyloggers are often installed by the owner or administrator of the computer in order to monitor the activities of the users. This can be a parent trying to monitor his child, a company owner trying to monitor his employee or someone trying to spy on his/her spouse.

Mode of operation:

Spywares are designed to operate in a totally stealth mode so that its presence is completely hidden from the users of the computer. Once installed, they silently monitor all the activities on the computer such as keystrokes, web activity, IM logs etc. These logs are stored secretly for later access or uploaded online so that the installer of the spyware program can have access to them.

Damage caused:

Apart from monitoring, spywares do not cause any damage to the computer. However, in some cases the affected computer may experience degradation in its performance.

Adware:

Adware is a software program that automatically renders advertisements to the users without their consent. Most common examples are pop-ups, pop-unders and other annoying banner ads. The prime reason behind the design of adware is to generate revenue for its author.

Mode of operation:

Adwares are are often bundled up with some of the free utilities such as a browser toolbars, video downloaders etc. When such programs are installed, the adware may take over and distract user activity by displaying annoying advertisements.

Damage caused:

Adware is harmless in most of the occasions. However, some are known to contain spywares that are used to monitor the surfing habits of users. This may pose a threat to the privacy of the users.

Generische Objektklassen der IUM

 

This tutorial is specifically designed with the intention to understand the creation of the generic class and how it works.

What is a generic class?

Java generic is a term that is used to denote a set of features which are related to the use of generic types and methods. A Generic class in java is nothing but an interface which one can parameterize for different types. We can follow the below format when it comes to defining a Generic class.

1
Class name<t1, t2,="" …tn=""> {/*…*/}

The angle bracket defined above is basically used to specify the type parameters which are also known as type variables T1, T2..Tn.

We can customize the Java classes as well since we don’t have generics just limited to the predefined classes in the Java APIs. The below is an illustration of the declaration we learned above.

Listing 1: Customizing the Java classes

1
2
3
4
5
6
7
8
9
10
11
12
13
public class Generic<E> {
    Class theClass = null;
    public Generic(Class theClass) {
        this.theClass = theClass;
    }
    public E createInstance()
    throws IllegalAccessException, InstantiationException {
        return (E) this.theClass.newInstance();
    }
}

What is <E>?

The alphabet E in the angle brackets displayed in the code above is a token that gives a hint that the class can have a type set once this is instantiated.

Let us understand the above said statement by using an example.

Listing 2: Defining type set

1
2
3
Generic<MyClass>  = new Generic<MyClass>(MyClass.class);
MyClass myClassInstance = createInstance();

Objective of Java Generics:

The main benefit of generic classes is that they are useful in early error detection at compile time. In order to get this benefit, we need to use a parameterized type such as LinkedList. This needs to be used in place of LinkedList and this will help the compiler to perform more type checks. This in turn requires lesser dynamic casts.

Using the above technique, it will be easier to detect the errors early since they will be reported at a compile time with the help of a compiler error message instead of getting an exception at run time.

Let us consider the example of LinkedList which is used to express the homogeneous list of elements. These homogenous lists of elements are of the type String.

Listing 3: Example of a parameterized type

1
2
3
LinkedList<String> list = new LinkedList<String>();
List.add(“abc”);
List.add(new Date());

Interfaces

In assition to classesclasses, we should also be aware of another hierarchy that is known by the name of interfaces which can be seen as a class specification. This however is not considered to be an implementation.

What does the interface lists?

An interface actually lists the method descriptors and not the actual code that are required by this interface. A class can always implement an interface by providing implementation to all methods declared in the interface. It is an interesting point to note that any class can be used to implement several interfaces and the only thing that is required to make this happen is the below method.

1
int compareTo(Object o) {...}

The advantage of using this method is that it helps the object to get compared -to other objects that are of the same type. The output of the above method could be in any form-positive, negative and even zero. This means the specified object here is either less than, greater than or equal to the object that is being passed as a parameter.

Generic type:

A generic type with formal type parameters is a declaration of a generic type with actual type of arguments. This is a reference type that has more than one parameter which are later replaced by type arguments the moment generic type is declared.

Listing 4: Example of a generic type

1
2
3
4
Interface Collections {
Public void add (E x);
Public Iterator iterator;
}

As discussed above the alphabet E in angle brackets is nothing but a place holder that will be later replaced by a type argument the moment generic type is declared.

Much on the similar lines of generic methods, the type parameter may comprise of more than one parameter that are separated by commas.

Why are these known as parameterized types? This is for the reason that they accept at least one parameter. Below is an example that illustrates this.

Listing 5: Example of a parameterized type

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class GenericClassExample<X> {
private X a;
public void set(X a) {
this.a = a;
}
public X get() {
return a;
}
public static void main(String[] args) {
GenericClassExample integerObj = new GenericClassExample<Integer>();
GenericClassExample stringObj = new GenericClassExample<String>();
integerObj.set(new Integer(50));
stringObj.set(new String("Mrbool"));
System.out.printf("Integer Type Object's Value :%d\n\n", integerObj
.get());
System.out.printf("String Type Object's Value :%s\n", stringObj.get());
}
}

The below Listing displays the output of the above code:

Listing 6: Output

1
2
Integer Type Object’s value: 50
String Type Object’s value: Mrbool

Here it can be observed that after the creation of a integer type object, the type of the variable X is modified to integer and same is the case with the String type .

We can use the below code to create a generic array with the following method signature.

Listing 7: Creating the generic array

1
2
3
4
5
6
7
public static T[] createArray(List list,Class ){
       T[1..n] array = (T[]) Array.newInstance(class, list.size());
       for(int i = 0; i < array.length; i++){
           array[i] = list.get(i);
       }
       return array;
   }

The point to note here is that we will not be able to make arrays and generics work together with current versions of Java and can only define arrays for non-generic types, and do casts in all the accessory.

Here in this tutorial so far we have defined a generic interface MyInterface and several classes that implement this interface. We would now be creating an array of the members of which can be assigned any object belonging to a class that implements the interface.

We can also make this happen by using an Object array. However this can lead to the loss of type information and then it needs to be cast each time we get something from the array. The other workaround of this could be to consider java.lang.reflect.Array.newInstance( Class C, int size ). But again this would require a single class C which would end up with an array that will allow assignments of C subclass objects.

The best way to do it is to use the wildcard HashMap[] x=new HashMap[3] and the prime reason behind this design is to maintain compatibility with existing code which is directly related to generics.

At the time of writing a generic which is nothing but a parameterized class, we have the class declaration that normally contains the type parameter in angle brackets. After this, we can have methods in a parameterized class which can make use of that parameter in the form of a return type. Also it can be used for its parameter types. As a result of this, we will observe that methods will view the type similar to concrete type because of its declaration in the class. The below example displays what we just discussed:

Listing 8: class declaration

1
2
3
4
5
6
7
public class LinkedList<A> {
...
public A getFront() { ... }
...
public void setFront(A a1) { ... }
...
}

Here is nothing but a type parameter that is normally passed to the class upon declaration. The point to note here is that A is being used as a return type for one method and a parameter type for another.

At the time of writing a parameterized code, we can also limit the range of acceptable types. This can be done with the introduction of a definite upper boundary which can be set so that only subtypes of that bound can be passed as the type parameter. In order to see the upper bound, we can make use of the extend keyword as shown below.

1
public class LinkedList<K extends Comparable> { ... }

We can see that any class that is normally used to implement the interface Comparable can accept this implementation of LinkedList.

It is a must to specify the type parameter whenever an instance of a parameterized object is created and the below example explains this.

1
LinkedList<String> _list = new LinkedList<String>();

The objective of the above code is to create a LinkedList. This can only be used to contain String objects and then we will have the compiler check that the actual type which in this case is a String is a subtype of the bound of the type parameter. Otherwise, the code will not compile.

Conclusion

We learned several techniques to create Generic Java classes . Hope you liked the article.

 

Best Books & Links

Posted: February 16, 2013 in Random Posts
558439_300x250 iPad2case

Posted: February 16, 2013 in Random Posts

Originally posted on Java Tutorials:

In the bottom up approach, we will write the java class and generates the WSDL file and other dependent components. The same will be deployed into the web containers.

In Top down approach, Architects will write the WSDL file based on the requirements. Developer need to make the corresponding service implementation using the WSDL provided. This post will explain how to create a service using the WSDL file.

Step 1:Create a dynamic or java project as mentioned here

Here, I have created a sample web dynamic project with the name SampleWS as given below.

Dyanmic web project

Step 2: generate the service using top down approach

Right click on the SamplWS project name -> New -> Other

SelectOther

Select the Web Service from the wizard as below and click on Finish button.

select webservice

Select the Web service type as ‘Top down Java bean Web service’ and provide the WSDL url in the Service definition drop down and…

View original 240 more words

Exquisite-print printer

Below the UN-commented  code is the in which you just give the path of the directory which contains files …. now the code see the files and send all files to the printer.

“I make that code for bulk of files send to printing in one time”

 

 

 
package javaapplication1;/*

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;

/**
*
* @author zeeshan
*/
public class JavaApplication1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, PrintException {
// TODO code application logic here which show u GUI of printer

//        FileInputStream textStream;
//        textStream = new FileInputStream(“C:\\\Users\\Zeeshan\\Desktop\\interestrates.xlsx”);
//        PrintRequestAttributeSet attributes =
//                new HashPrintRequestAttributeSet();
//        DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
//        Doc mydoc = new SimpleDoc(textStream, flavor, null);
//        PrintService[] services = PrintServiceLookup.lookupPrintServices(
//                flavor, attributes);
//        PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
//
//        if (services.length == 0) {
//            if (defaultService == null) {
//                //no printer found
//            } else {
//                //print using default
//                DocPrintJob job = defaultService.createPrintJob();
//                job.print(mydoc, attributes);
//
//            }
//
//        } else {
//
//            //built in UI for printing you may not use this
//            PrintService service = ServiceUI.printDialog(null, 200, 200, services, defaultService, flavor, attributes);
//
//
//            if (service != null) {
//                DocPrintJob job = service.createPrintJob();
//                job.print(mydoc, attributes);
//            }
//
//        }

try {
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));

/*  Online Printer Lists and select which you like
PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras);
if (pss.length == 0) {
throw new RuntimeException(“No printer services available.”);
}
PrintService ps = pss[3];
*/
/* Default Printer */
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintService ps = defaultService;
System.out.println(“Printing to ” + ps);
DocPrintJob job = ps.createPrintJob();
String files;
File folder = new File(“C:\\Users\\Zeeshan\\Desktop\\pics\\”);
File[] listOfFiles = folder.listFiles();

for (int i = 2; i < listOfFiles.length; i++) {

if (listOfFiles[i].isFile()) {
files = listOfFiles[i].getName();
FileInputStream fin = new FileInputStream(folder.getPath()+”\\” + files);
Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);

job.print(doc, pras);
fin.close();
System.out.println(files);
}
}

} catch (Exception e) {
e.printStackTrace();
}

}
}