Archive

Archive for the ‘Concept & ideas’ Category

Write your own Progress Listener

May 17th, 2011 No comments

While writing some other articles over Anonymous Classes, I wrote a code to watch over how many bytes of a file has bean read or write. I am sharing that code with all of you to improve understanding in use of anonymous Classes, advanced java concept.

This is very simple and handy code. You can change it as per your need like to keep a watch over file uploading (to limit upload file size), or intimating admin via mail when log file size exceed etc.

This article will also help you to understand need of interfaces over abstract classes.

myFileWriter.java

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;

/**
 * Copyright (C) 2011 Amit Gupta
 * You are free to redistribute the code or its modified version
 * by giving the credit to original code.
 *
 * This code is useful to understand the concept and
 * importance of anonymous class. And how to reuse java classes
 * @author Amty
 *
 */
public class myFileWriter extends OutputStreamWriter //implements myProgressListener
{
	myProgressListener mpl;
	long pBytesWrite;
	public myFileWriter(OutputStream arg0) {
		super(arg0);
		//mpl=this;
		pBytesWrite=0;
	}

	@Override
	public void write(int c) throws IOException {
		super.write(c);
		pBytesWrite++;
		if(mpl != null){
			mpl.update(pBytesWrite);
		}
	}

	public void setProgressListener(myProgressListener mpl){
		this.mpl = mpl;
	}
	//public void update(long pBytesRead, long pContentLength, int pItems){}

	public static void main(String[] args) throws Exception{
		FileOutputStream fos = new FileOutputStream("D:\\article-stack\\amtyOutput.txt");
		FileInputStream fis = new FileInputStream("D:\\article-stack\\amtyInput.txt");
		InputStreamReader isr = new InputStreamReader(fis, "UTF8");
		Reader in = new BufferedReader(isr);

		myProgressListener mpltest = new myProgressListener() {

			@Override
			public void update(long pBytesWrite) {
				System.out.println(pBytesWrite + "Bytes are written");
			}
		};

		myFileWriter mfw = new myFileWriter(fos);
		mfw.setProgressListener(mpltest);
		int ch;
	    while ((ch = in.read()) > -1) {
	       mfw.write((char) ch);
	    }
	    in.close();
	    mfw.close();
	}
}

myProgressListener.java

public interface myProgressListener {
	public void update(long pBytesWrite);
}

Output:

74381Bytes are written
74382Bytes are written
74383Bytes are written
:
77710Bytes are written
77711Bytes are written
77712Bytes are written
77713Bytes are written
77714Bytes are written

Here is attached code for your reference.
This area is protected to registered users only.

Interface vs Abstract classes, a practical difference

May 16th, 2011 No comments

An Interface: This is a collection of methods. They have no definition whatsoever and their function is determined by the class that implements them. An example of an interface is a List. All lists (ArrayList, LinkedList) have add() and remove() methods because they implement the List interface, which demands them.

public interface List {
    public void add (Object o);
    public void remove (Object o);
}

public class MyList implements List {

    public void add (Object o) {
       // I must implement this method because of the interface List
    }

    public void remove (Object o) {
       // I must implement this method because of the interface List
    }
}

The implements keyword is used by a class to indicate that it is going to implement the methods demanded by an interface. A class can implement as many interfaces as it likes; the only requirement is that it provides a definition for each of those methods. It can also be defined as abstract and rely upon its subclasses to define some. Then, those methods are just like the abstract methods of any other abstract class.

Take an example of List interface. Most methods don’t care what kind of list they get; they just want to know that the object supports the common list methods. In the statement:

List<String> myList = new ArrayList();

You are creating an actual ArrayList object, but hiding it’s implementation under the List interface. Then, later, if you decide to use a LinkedList instead, you don’t have to change all of your code since it is also implementing the List interface.

Interface is programming structure where you define your functions/services that you want to expose to public or other modules. Kind of a contract where you promise that you are providing some functionalities or services, but hiding the implementation so that implementation can be changed without affecting your contract.

Abstract class is a partially implemented class and it has no real meaning other than serving as a parent for multiple child classes those with real meaning. Abstract class is special parent class that provides default functionalities to multiple child classes. It is created as abstract because of unavailability of suitable concrete parent class.

The extends keyword is used by a class to indicate that it is going to add functionality to some existing class. If the parent class is abstract, the extending class must implement any of those abstract methods in the parent.

Unlike interfaces, abstract classes can contain fields that are not static and final, and they can contain implemented methods. Such abstract classes are similar to interfaces, except that they provide a partial implementation, leaving it to subclasses to complete the implementation. If an abstract class contains only abstract method declarations, it should be declared as an interface instead.

Points to remember:

Interfaces and interface methods are implicitly abstract even if not declared as so. So there is no need to explicitly specify it.

Below code is senseless.

public abstract interface <interface-name> {
 public abstract void <function-name>(...);
}

Other differences

  1. An interface can extend any number of interfaces.
  2. A class can optionally extend exactly one class; it extends Object if you don’t specify anything.
  3. A class can implement any number of interfaces.
  4. Any class can be declared abstract.
  5. Any class that has abstract methods must be declared abstract.
  6. Any class that extends an abstract class or implements an interface must implement all abstract and interface methods or else must be declared abstract.

Practical usages and designs to inscribe clear picture in your mind

  • Interfaces allow the creation of proxies that encapsulate a concrete class. This is used extensively by frameworks in order to intercept method calls to the concrete class (e.g., for starting a transaction before the method is executed or to write to the log).
  • Keep watch over upload file size
  • Creating progress monitor in Java
  • If an abstract class contains only abstract method declarations, it should be declared as an interface instead.

I am designing an java based API. I’ll share its design once it is completed. It’ll help you to understand the concepts of interfaces, abstract classes, enum, modifers, creating your own data type, delegators, OOPS concept etc. with example. So keep reading….

Qatar : a small land with new impressive stadium designs for 2022 FIFA World Cup

December 11th, 2010 No comments

This week, Qatar won in it’s bid to host the world cup. Qatar a small country does not yet have the facilities built to host the event, but their designers have come up with some great ideas for the 2022 World Cup.

qatar fifa 2022 worldcup stadium design

FIFA’s decision to pick Qatar to host the 2022 World Cup has been swirling in controversy since the choice was made last week. The answer to whether Qatar is the better option instead of the runner-up United States won’t be known until the tournament rolls around 12 years from now.

Some of the designs are inspired by a specific element of Qatari culture and tradition. And many of them are natural friendly. They are designed to use solar energy.

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

qatar fifa 2022 worldcup stadium design

Dan Meis, an architect with the Kansas City architecture firm Populous, led the stadium’s design. He explained that he wanted the venue to have a lasting effect. “Often countries will build stadiums for the events, and they have difficulty utilizing the building afterwards,”

Do you have headache? At least these products have….

November 12th, 2010 No comments

Panadol (pain relief tablets manufacturer) might have less effectively designed site but their advertisement on the products, makes a product alive.


panadol creative product design all

panadol creative product design coffee cup

panadol creative product design bag

panadol creative product design bag

wiping the pollution, an advertisement

November 11th, 2010 No comments

This advertisement can improve your imagination about the pollution free place. It shows the difference between polluted area where are we living actually and an area where we want to live.

No!! they are not advertising any organization fighting for safe and clean environment. But a car.

smart car advertisement


smart car advertisement

Panasonic nose trimmer, creative billboard advertisement

November 6th, 2010 No comments
Purpose of an advertisement is to fetch attention only. –amty

Creative designs of billboard definitely do the same thing without any celebrity face. Panasonic did it. See their advertisement on hoardings with the punch line “Afraid to trim sensitive nose hair” in the ad of nose hair trimmer. A good way to hang electric wires and advertisement in addition.

Panasonic nose trimmer on billboard

Panasonic nose trimmer on billboard

Panasonic nose trimmer on billboard

Social message and creative styled coated hoarding

October 24th, 2010 No comments

As per the different position of hoarding board, first I felt that it is an edited image not a actual hoarding. But it is real.

This hoarding is made by two layers. You can see the lower layer in last image. Where the upper layer is impaired due to the season. On the hoarding, you can read a social message too, “Winter weather makes poverty even harder”


creative styled coated hoarding with Social message to show the effect of season on poverty

*Open the image in new window or save it for bigger version

Does your bone as strong as this? advertisement review

October 19th, 2010 No comments
An advertisement can take any shape.

Just see below images where pillars, to support a bridge, are deigned in a bone shape. And the side below part is written to advertise “dumocalcin”. Dumocalcin is not a very famous brand. They took a very good option for advertisement


dumocalcin giant bones in pillar shape

Advertisement on Escalator & Stair

October 18th, 2010 No comments

While roaming around the shops inside a mall, people generally look for advertisement hanged or taped to a wall. There are some advertisement on stairs and escalators, not only to save space for advertisement but also to give them a unique look. By the good and correct use of lighting and colors, a simple poster stuck to floor might look a real 3d object from the top of stairs.

View such ads for new ideas and creativity.

red cross Advertisement on Escalator and Stair


pizza Advertisement on Escalator and Stair

suitcase Advertisement on Escalator and Stair

Advertisement on Escalator and Stair

spa Advertisement on Escalator and Stair


hair cut Advertisement on Escalator and Stair

Advertisement on Escalator and Stair

juice salon Advertisement on Escalator and Stair

gillette Advertisement on Escalator and Stair

DHL Advertisement on Escalator and Stair

console energy Advertisement on Escalator and Stair

coca cola Advertisement on Escalator and Stair

ikea Advertisement on Escalator and Stair

Eco friendly signature

October 11th, 2010 No comments

Using green accessories might be helpful to spread “Go green” message among the people. But it’ll be better if you explain it to people about how to go green. It doesn’t require any effort. You just need to replace existing go green images in your signature with the images given below.

My sister (Manisha Gupta) made all below images to give words for “Go Green” message. These all images and messages are self explanatory. Just use them in your mail signature or wherever you can.

Use cycle avoid bike for short distances

Avoid rickshaws support car pooling use public transportation

*open above images in new browser

Best suitable for your signature

Use cycle avoid bike for short distances  signature image

Avoid rickshaws support car pooling use public transportation signature image

*Please suggest if you have some other ideas.

Sharing advertisement space, a concept

October 9th, 2010 No comments

Advertisements are needful to make the identity of a product. Just see the below hording board good for sharing and advertising. Not only to advertise a product but to keep the advertisement cost less.


bill board advertisement space sharing beer poster

Help us keep this beer a buck. Share our billboard.

Creatively designed stairs

October 8th, 2010 No comments

You can buy gadgets to decorate a dirty place. Or you can redesign a place beautiful. So that, all gadgets automatically looks beautiful and fit to that place. It’s up to you.



creative scaring design stairs


creative design stairs

creative design stairs

creative art gallery design stairs


creative show case design stairs

Some useful stairs design

October 1st, 2010 No comments

It is very difficult to arrange all items properly in a small space like they don’t only fit accordingly the space but looks like a decoration show pieces.

Just see below images and get some ideas about how to cut a library, playing room, kitchen etc in a 2 – 4 room houses.


useful creative book case library stairs

useful creative book case library stairs

useful creative book case library stairs

useful creative book case library stairs

useful creative book drawers library stairs

useful creative drawers case library stairs

useful creative drawers case library stairs

How much time you spend to see the time in your watch

September 30th, 2010 1 comment

Tokyoflash Design Studio from japan designed a watch challenging you to watch the time. This watch creates an optical illusion. You can train your eyes to see the hidden numbers through the green and black maze. Just press the button and see the green LEDs animate to light up the whole face and show you time in 4 big digits.
This is not the single watch which creates optical illusion. You can see more designs at tokyoflash. But unfortunately this is a concept only. These watches are not in market till now


optical illusion watch

optical illusion watch pattern

Know about Social Networking in next 2 minutes

September 20th, 2010 No comments

Social networking is nothing but a process/ way to keep contacts with many people over the net. Even you don’t know many of them.

You say others about you, about what are you doing or what are your future plans. Many times there is no reason behind talking, but talking only. In other words you can say that it is a way of public sharing.



Sixth Sense Technology, an introduction

September 18th, 2010 No comments

Can you imagine the time when there will be no distance between virtual world and real world?

Just imagine about a paper with movable pictures that Harry Potter was reading. Or when you can feed contents of a paper into computer without scanner.

Just watch below video about future technology where you can control everything with your fingers.

WordPress security hack

September 16th, 2010 No comments

Do you avoid people to get registered on your site? …… Many people do this because they afraid.

There is common thinking in everyone’s mind that if you want to secure your wordpress blog then you must disable users to get registered on your site.


amty wordpress security hack logo

Registration on a site always attracts hackers. Many plug-ins may secure your blog. But some of them might be proved as a powerful & useful tool for hackers.

Here I am discussing about a plug-in which is very useful in point of security. But I used this to hack my own site.

Let’s do it.

1
Install wp file monitor plug-in. This plug-in monitors all files on your site. It prompts you if any file is manipulated by any hacker, virus or by any other utility. It prompts you even if you do any changes. It also can mail summary of changes.
2
Now register at your own site. And login as a subscriber. Remember that below steps shall not work until you log in.
If you are testing this hack on your localhost then you must know, how to register users on local machine?
3
Now this is the time to hack your own site. Put following URL in address bar of any internet browser like Epic.


http://localhost/wp-admin/options-general.php?page=WordPressFileMonitor&display=alertDesc

or
< your blog url >/wp-admin/options-general.php?page=WordPressFileMonitor&display=alertDesc

My aim behind writing this post is not to improve hacking but to aware people.

Here you’ll get a page informing you last modified files. You also can remove this information without any administrator permission. So the next time when owner of that site logins to dashboard, shall not be prompt for any modification. Only the problem is that if mail service for this plug-in is already enabled then the owner would be prompted via mails.

This hack will help you to collect more information about the site like latest changes, posts in draft, plug-in recently installed, theme, and various path along with file name.

Spiral stairs art

September 15th, 2010 No comments

You already had seen many houses and places with stairs where stairs are used just go up or to come down. Now see these stairs and their architecture.

I found many more spiral stairs good in quality, color, material used. But I picked which are very well designed and creative.


Never Ending spiral stair

surrounded creative spiral stairs

creative spiral stairs

Never Ending creative spiral stairs

black creative spiral stairs

polygon creative spiral stairs

Bulb style creative spiral stairs

How to get the path of wordpress installation directory

August 1st, 2010 No comments

I seen many people asking site owners about their CMS platform.
It is easier to know it yourself. There is a fixed path pattern of every CMS. If a site is using wordpress CMS then path pattern should be like,

Domain Name/wp-admin

If you get wordpress login page by entering above path then you surely can say that site is built on wordpress CMS. But wordpress provides an easier way to change the path of wordpress installation directory. This option is available in wordpress dashboard under settings option. If a user had changed the path then it is really difficult to guess the path. Specially when site owner restricts crawler to index their site contents. In this case below google search will not help you

inurl:wp-admin site:article-stack.com

Well! it is pretty easy to know wordpress installation directory path. Use the below path

Domain Name/robots.txt

You’ll get a text file containing path as follow

Sitemap: Domain Name/sitemap-web.xml

User-Agent: *
Disallow: /wp/wp-admin/
:
Disallow: /go/
Disallow: /forums/profile/

If robots.txt revealing the path you are trying to hide then you must know why robots.txt is imported for your site.

In case of above example, wordpress installation directory is Domain Name/wp/

Please note this
This hack is not to attract hackers. But to improve security only.

Pool table on wheel

July 28th, 2010 No comments
creative pool table on wheel
creative pool table on wheel

Imaginative minds find ways to create something cool out of it. Here is an example. This 1965 Volkswagen Micro Bus that has its steering, gear and engine removed to give it a new form, a trailer billiard table.


I hope these images will surely make Engg students do creative.

Categories: Concept & ideas Tags: , ,