Debugging vicious java.net.BindException (Windows)
java.net.BindException is thrown when JVM fails binding a socket to a local address and port.. Most common reason is that port is already used by some other application/service. Message like “Port already in use: 1098;” further confirms this.
This is how you can debug this exception:
- Check which service is binding the port by command “netstat –b”
This will list down all port and the application which binds the port like:
Proto Local Address Foreign Address State PID
TCP hddlntd100000:1090 test.test.cim:1026 ESTABLISHED 2248 [OUTLOOK.EXE]
- Now check for the port which is shown as already in use. Like if the message resulted by BindException is “Port already in use: 1098”, then 1098 is in use by other application.
- Identify the application running on the given port. Like Outlook is acquiring port 1090.
- Either close the application which is acquiring the port directly by exiting the application like in case of Outlook or go to task manager and do end task for the given application/service. If application/service closes successfully you are done, now retry whatever had caused BindException earlier.
Forcing www in url using Apache
To enforce www to every url, we can use mod_rewrite module in apache.
The idea is to make only one entry point to your site e.g.
1. www.techpitcher.com
2. http://techpitcher.com
3. http://techpitcher.com/index.html
4. www.techpitcher.com/index.html
As listed above there are at least 4 ways to access the home page of the site. To make one access url like http://www.techpitcher.com, we need to configure apache’s configuration file.
To use this method, you must have write access to your apache’s configuration file.
1. Open httpd.conf file. In case of Apache2, this can be a blank file.
2. Verify that mod_rewrite.so moule is loaded, Then load mod_rewrite.so module.
LoadModule rewrite_module
3. Below is piece of code which will force www in every url
<VirtualHost www.techpitcher.com:80>
DocumentRoot /home/techpitcher/public_html
ServerName www.techpitcher.com
ServerAlias techpitcher.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.techpitcher\.com
RewriteRule ^/index\.html$ http://www.techpitcher.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^techpitcher\.com
RewriteRule ^/(.*) http://www.techpitcher.com/$1 [R=301,L]
</VirtualHost>
R[=code] Redirect to new URL, with optional code. Usually you also want to stop and do the redirection immediately. To stop the rewriting you also have to provide the ‘L’ flag.
ifconfig command : Manage network configuration in linux
The most frequent use of ifconfig command is setting an interface’s IP address and netmask, and disabling or enabling a interface.
To see IP address of the machine, open terminal and type ifconfig
It’ll list all the interfaces connected to the device e.g.
root@ubuntu:~$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:1c:23:a4:ed:b0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:160524 errors:0 dropped:0 overruns:0 frame:0
TX packets:59261 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:40668433 (40.6 MB) TX bytes:14468340 (14.4 MB)
Interrupt:17
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:21240 errors:0 dropped:0 overruns:0 frame:0
TX packets:21240 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3990382 (3.9 MB) TX bytes:3990382 (3.9 MB)
To view a particular interface, provide interface name after ifconfig command.
root@ubuntu:~$ ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:1c:23:a4:ed:b0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:160524 errors:0 dropped:0 overruns:0 frame:0
TX packets:59261 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:40668433 (40.6 MB) TX bytes:14468340 (14.4 MB)
Interrupt:17
here are few more frequent usages of ifconfig
ifconfig eth0 down
This flag causes eth0 interface to be shut down.
ifconfig eth0 up
If interface eth0 is in the down state then by setting this flag will make eth0 interface active.
ifconfig eth0 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.20
Assign eth0 with the above values for IP, netmask and broadcast address.
What is a Test Plan?
A Test Plan document describes the scope, approach, resources and schedule testing activity.
How to know which java version is installed in linux?
Go to shell and type java -version. It will show the installed version information of java
root@ubuntu:/# java -version java version "1.6.0_10" Java(TM) SE Runtime Environment (build 1.6.0_10-b33) Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode)
.
java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
I am getting following exception while using httpclient.
</p> <p>java.lang.NoClassDefFoundError:org/apache/commons/codec/DecoderException<br> at org.apache.commons.httpclient.HttpMethodBase.&lt;init(HttpMethodBase.java:216)<br> at org.apache.commons.httpclient.methods.GetMethod.&lt;init(GetMethod.java:88)</p> <p>
Please tell me why am I getting this exception?
What is singleton pattern? Write an example singleton class?
A singleton class is a class which has only one instance per application. Rather per JVM. This design pattern is extensively used when user needs exactly one instance. For example facade objects, state objects or for global variables (as it permits lazy allocation and initialization which may not happen in all languages).
To make a class singleton, its constructor is made private or protected so that it can not be instantiated. Instead, a getInstance () method is written to return a new instance of that class if it doesn’t exist or return the reference of that object if it already exists. If it’s a multithreaded environment make sure to synchronize the getInstance() menthod.
Conventional way of writing a singleton class is :
public class Singleton {
private static Singleton INSTANCE = null;
// to prohibit instantiation
private Singleton() {
}
public static Singleton getInstance() {
if (INSTANCE == null) {
// lazy initialisation
INSTANCE = new Singleton();
}
return INSTANCE;
}
}
You can synchronise on getInstance() method for a multi threaded environment.
Another thread-safe Java programming language lazy-loaded solution is:
public class Singleton {
private Singleton() {}
// lazy initialisation
private static class SingletonHolder {
private final static Singleton INSTANCE = new Singleton();
}
public static Singleton getInstance() {
return SingletonHolder.INSTANCE;
}
}
Remember a singleton class is one instance per JVM. So if you have your application running in a cluster of servers. Every server will have its own JVM, therefore its own instance of singleton class. In this case, purpose of making a class singleton is not fulfilled. Hence this pattern should be used with care.
nested exception is java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel /HSSFCellStyle
I am getting following exception while exporting jasper report in xls format.
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFCellStyle org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:899) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:793) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431) javax.servlet.http.HttpServlet.service(HttpServlet.java:690) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:265) org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107) org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
How you can force the garbage collection?
We can’t have forced garbage collection. System.gc( ) does not necessarily force a synchronous garbage collection. Instead, the gc( ) call is really a hint to the runtime that now is a good time to run the garbage collector. The runtime decides whether to execute the garbage collection at that time and what type of garbage collection to run.
nested exception is java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel /HSSFCellStyle
I am getting following exception while exporting jasper report in xls format.
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFCellStyle org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:899) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:793) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:431) javax.servlet.http.HttpServlet.service(HttpServlet.java:690) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:265)