hasan's blog (বল্গ)

work for fun!!!

Archive for the ‘Java’ Category

Maven quick start in presentation.

with 4 comments

Here in our company, we got many new java developers, as we are strict on project structure and coding convention stuffs, at the same time we are aware of giving a good feed to our honorable new developers.

this project was intended for new to medium maven experienced java developers, who wants to use maven. or already been using. i belief you guys will get it helpful.

here is the presentation on maven

banner

Written by nhm tanveer hossain khan

June 27, 2007 at 5:23 am

Limit of maximum iterfaces per class.

leave a comment »

I was reading through java doc for Proxy class. suddenly my eyes were stucked on the following lines of code – bit interesting perhaps,

The resulting proxy class must not exceed any limits imposed on classes by the virtual machine. For example, the VM may limit the number of interfaces that a class may implement to 65535; in that case, the size of the interfaces array must not exceed 65535.

Written by nhm tanveer hossain khan

June 1, 2007 at 11:07 pm

Visitor Design pattern to traverse hierarchical object structure.

with one comment

Those who know about visitor design pattern, i am not triggering my write up for them. but those who didn’t know about this or heard but always ignored i am writing for them.

Visitor design patter is used to traverse through the object structure. it is used to separate the iterating logic from the object.

Let’s imagine, you have the following object structure :

class Tree {

private List mBranches;

public List getBranches() {

return mBranches;

}

}

how we usually iterate through this list of objects, lets think like following code -

// ….

final List branches = tree.getBranches();

for (final Branch branch : branches) {

// …

}

// …

visitor design pattern emphases API designer to hide underlying object structure and iterating logic. now let’s see how we can implement the above example using visitor design pattern:

interface Visitor {

void visit(final Branch pBranch);

}

interface Visitable {

void accept(final Visitor pVisitor);

}

class Tree implements Visitable {

// … previous code

public void visit(final Visitor pVisitor) {

for (final Branch branch : mBranches) {

pVisitor.visit(branch);

}

}

}

now my concern is to make it “n” depth. so it will become a real tree with “n” depth, where can traverse branches and leafs. who is it possible over visitor dp.

here is simple extension over visitor patter, which will enable visitor to visit “n” depth hierarchical object structure.

let’s define our interfaces:

interface Visitor {

void visit(final int pDepth, final TreeItem pItem);

}

interface Visitable {

void accept(final Visitor pVisitor);

}

our tree class:

class Tree implements Visitable {

private TreeItem mRootItem;

// … setter getter

class TreeItem {

private String name;

// .. Setter getter

private List
mTreeItems;

// .. Setter getter

}

public void accept(final Visitor pVisitor) {

visitRecursivlyTreeItem(0, pVisitor, mRootItem);

}

private visitRecursivlyTreeItem(int pLevel, final Visitor pVisitor, final TreeItem pItem) {

pVisitor.visit(pLevel, pItem);

for (final TreeItem item : pVisitor.getTreeItems()) {

visitRecursivlyTreeItem(pLevel + 1, pVisitor, pItem);

}

}

}

That’s all :)

Written by nhm tanveer hossain khan

June 1, 2007 at 11:05 pm

Posted in Java, Java SE, tips

Open Search Servlet – build open search configuration on the fly

leave a comment »

Here is open search specification – http://www.opensearch.org/Specifications/OpenSearch/1.1

Let’s enable your browser to detect your search engine automatically; using open search servlet you can generate open search configuration file on the fly.

Download information is here –

Binary library

Source maven project

Binary war file (includes example usages)

Usages:

  1. Copy “open-search-x.jar” file on your WEB-INF/lib/ directory
  2. Edit web.xml file.
  3. add these entries -
< servlet >
    < servlet-name >openSearch< /servlet-name >
    < servlet-class >com.we4tech.openSearch.servlet.OpenSearchServlet< /servlet-class >
    < !-- URL matching pattern -- >
    < init-param >
      < param-name >url-match< /param-name >
      < param-value >.*/(.+).osd< /param-value >
      < !--< param-value >.*/search/(.+)< /param-value >-- >
    < /init-param >
    < !-- map open search configuration with url -- >
    < init-param >
      < param-name >open-search< /param-name >
      < param-value >open-search.properties< /param-value >
    < /init-param >
    < init-param >
      < param-name >somewherein-blog< /param-name >
      < param-value >somewherein-blog.properties< /param-value >
    < /init-param >
  < /servlet >

  < servlet-mapping >
    < servlet-name >openSearch< /servlet-name >
    < !--< url-pattern >/search/*< /url-pattern >-- >
    < url-pattern >*.osd< /url-pattern >
  < /servlet-mapping >
  1. Now place configuration properties file with in your WEB-INF/classes/
  2. for example: “open-search.properties”
# Default open-search. properties
shortName=colorful moment.
description=somewhere in blog
contact=hasan@somewherein.net

url.1=text/html,get,http://www.somewherein.net/blog/index.php?s={searchTerms}&submit=
image.1=16,16,image/x-icon,http://www.searchmash.com/favicon.ico
  1. Congratulations you have completed all steps ;)

Sample usages on your web site can be found here –

http://www.opensearch.org/Specifications/OpenSearch/1.1#Autodiscovery_in_HTML.2FXHTML

Best wishes,

Written by nhm tanveer hossain khan

May 20, 2007 at 5:58 am

Posted in Java, api, java ee

JavaFX: Parse HTML content with DOMParser

with one comment

I have started an interesting project. I will illustrate a crawler based on JavaFX scripting. Though there is no specific reason beyond using JavaFX except to enhance my knowledge on JavaFX scripting.

Here is some preliminary code that I have already written:

Import statement and package declaration –

———————————————————

package com.we4tech.linkcrawler.fx.script;

import java.lang.*;

import java.io.*;

import java.net.*;

import java.util.*;

import org.xml.sax.SAXException;

import org.w3c.dom.Document;

import org.w3c.dom.NodeList;

import org.w3c.dom.Node;

import org.w3c.dom.NamedNodeMap;

import com.sun.org.apache.xerces.internal.parsers.DOMParser;

Read the rest of this entry »

Written by nhm tanveer hossain khan

May 18, 2007 at 3:43 am

Posted in Java, JavaFX

Remind me: servlet, Jsp performance tuning note

with one comment

hi,
here is a great collection on servlet jsp performance related stuffs.
http://www.javaperformancetuning.com/tips/j2ee_srvlt.shtml

best wishes,

Written by nhm tanveer hossain khan

May 14, 2007 at 12:02 am

Posted in Java, java ee, remind me

JavaFX: How to run your HelloWorld

with 5 comments

Today i have started learning JavaFX. so you will get my new learning over my blog site.

Problem how to run your first hello world FX:

there are 3 alternatives as far i know -
1. using NetBeans.
2. using Eclipse JavaFX plugin.
3. using manual execution

1. using net beans – you will find enough information from the starter example over here

https://openjfx.dev.java.net/Getting_Started_With_JavaFX.html

2. using eclipse plugin – install plugin from this url :
http://download.java.net/general/openjfx/plugins/eclipse/site.xml

3. using manual execution:
include 4 directory/jar over your classpath
i. javafxrt.jar
ii. swing-layout.jar
iii. Filters.jar
iv. your src directory (where you will store your *.fx) files

Main-class: net.java.javafx.FXShellyourPackage.ScriptFileName

best wishes,

Written by nhm tanveer hossain khan

May 12, 2007 at 11:22 am

Posted in Introduction, Java, JavaFX

struts rewrite, link rewrites url with “;jsessionid=” session id.

leave a comment »

hi,
on my server i found some strange problem. it was actually related with tag. the problem was with the url rewriting, which was performed by struts tag library. struts tag library was creating an invalid URL.
for example i wrote the following code:
< img src=”my-image.gif” />

as i have only wrapped “${urlPrefix}” with in html:rewrite tag. so struts tag library wrote the following output.

which is totally a wrong url.

so how i resolved it?
very simple just fixing my weired code. now it looks like the following -
< img src=”" />

the generated output looks like -

here is a regex which may help you to find out the error tags:
“(.+)”

yeap it is working now :)

Written by nhm tanveer hossain khan

May 7, 2007 at 8:34 am

Posted in Introduction, Java, java ee, jsp

আসো আদর্শ সফটও্যয়ার প্রোগ্রামিং শিখি – ২ (”final” এর ব্যবহার)

leave a comment »

“আমার টারগেট রিডার হল যারা java জানেন”।
(টপিক: “final” keyword এর ব্যবহার).

java তে final ব্যবহার হয় কোন variable কে read only করার জন্য ।

member/local variable গুলো ভুল বশত value override হবার সম্ভনা দুর করার জন্য final ব্যবহার করার প্রয়োজন ।

final এর কিছু ব্যবহার দেখানোই আমার আজকের পোস্ট:

১. static initialized variable গুলো তে final ব্যবহার করুন । যেমন:
private static final BLA = new Bla(..);

২. class member variable গুলো তে value override করার প্রয়োজন না হলে, initialize করার সময় final ব্যবহার করূন । যেমন:
private Bla mBla = new Bla();

৩. local variable গুলোতে final ব্যবহার করুন । যেমন:
final String name = mBla.getName();

৪. for loop এর index variable কে final ব্যবহার করুন । যেমন:
for (final int i = 0; i < 10; i++) {…}

৫. foreach loop এর variable কে final ব্যবহার করুন ।
যেমন:
for (final Bar bar : bars) {…}

৭. method parameter কে final করূন । যেমন:
private void doBla(final String pName, final String pEmail) {…}

৮. protected method গুলোতে extended class গুলোর override করা দুর করার জন্য final  ব্যবহার করুন । যেমন:
class Animal {
protected final String getRootType() {
return “animal”;
}

protected String getType() {
return getRootType();
}
}

class Cat extends Animal {
/* Compilation error block start */
protected String getRootType() {
return “Bang”;
}
/* Compilation error block end */

protected String getType() {
return “Cat”;
}
}

এখানে
protected String getRootType() {
return “Bang”;
}

এই কোড টুকু কম্পাইল টাইম এরর দিবে …

আর মনে পরছেনা (ক্লোজআপহাসি)

Written by nhm tanveer hossain khan

May 2, 2007 at 5:23 pm

Posted in Java, bangla

Variable fun ( o_o )

with 6 comments

Those who like to fun with coding, hope you will enjoy this variable :)
variable_fun.gif

java allows “o_o” as variable name, so isn’t it cute to show an ugly exception ;)

Written by nhm tanveer hossain khan

March 5, 2007 at 12:20 am

Posted in Introduction, Java, fun