Archive for the ‘Java’ Category
Maven quick start in presentation.
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
Limit of maximum iterfaces per class.
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.
Visitor Design pattern to traverse hierarchical object structure.
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
Open Search Servlet – build open search configuration on the fly
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 war file (includes example usages)
Usages:
- Copy “open-search-x.jar” file on your WEB-INF/lib/ directory
- Edit web.xml file.
- 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 >
- Now place configuration properties file with in your WEB-INF/classes/
- 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
- 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,
JavaFX: Parse HTML content with DOMParser
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;
Remind me: servlet, Jsp performance tuning note
hi,
here is a great collection on servlet jsp performance related stuffs.
http://www.javaperformancetuning.com/tips/j2ee_srvlt.shtml
best wishes,
JavaFX: How to run your HelloWorld
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,
struts rewrite, link rewrites url with “;jsessionid=” session id.
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
আসো আদর্শ সফটও্যয়ার প্রোগ্রামিং শিখি – ২ (”final” এর ব্যবহার)
“আমার টারগেট রিডার হল যারা 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”;
}
এই কোড টুকু কম্পাইল টাইম এরর দিবে …
আর মনে পরছেনা (ক্লোজআপহাসি)
Variable fun ( o_o )
Those who like to fun with coding, hope you will enjoy this variable ![]()

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





