Got this error for broadband connection from reliance : "Connection has limited connectivity or no connection" when starting up the system. To solve this problem we need to release the existing IP and get a new IP. To do the same,
1. execute from cmd prompt : ipconfig/release
2. then, ipconfig/renew (no space between ipconfig and renew).
Saturday, April 28, 2007
Thursday, December 28, 2006
EJB Lookup
1. When deploying EJB, it has a name(if specified using annotation : @Stateless(name="SessionEJB") or if descriptor: <ejb-name>SessionEJB</ejb-name>.
2. This EJB deployed to OC4J. Now to do a lookup for this EJB, we can use either ApplicationClientInitialContextFactory or RMIInitialContextFactory.
3. In case of RMIInitialContextFactory, no need of application-client.xml and the context lookup will be : new InitialContext.lookup("SessionEJB").
4. In case of ApplicationClientInitialContextFactory, we need application-client.xml. It has to introduce the ejb refrence going to be used in code as:
<application-client xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application-client_1_4.xsd" version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee">
<display-name>InterceptorTest-app-client</display-name>
<ejb-ref>
<ejb-ref-name>ejb/SessionEJB</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<remote>myEJB.SessionEJB</remote>
<ejb-link>SessionEJB</ejb-link>
</ejb-ref>
</application-client>
5. Here, ejb-link is used to link to the actual bean. Now, in the client code we use the ejb-ref-name for lookup as:
new InitialContext().lookup("java:comp/env/ejb/SessionEJB");
2. This EJB deployed to OC4J. Now to do a lookup for this EJB, we can use either ApplicationClientInitialContextFactory or RMIInitialContextFactory.
3. In case of RMIInitialContextFactory, no need of application-client.xml and the context lookup will be : new InitialContext.lookup("SessionEJB").
4. In case of ApplicationClientInitialContextFactory, we need application-client.xml. It has to introduce the ejb refrence going to be used in code as:
<application-client xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application-client_1_4.xsd" version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee">
<display-name>InterceptorTest-app-client</display-name>
<ejb-ref>
<ejb-ref-name>ejb/SessionEJB</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<remote>myEJB.SessionEJB</remote>
<ejb-link>SessionEJB</ejb-link>
</ejb-ref>
</application-client>
5. Here, ejb-link is used to link to the actual bean. Now, in the client code we use the ejb-ref-name for lookup as:
new InitialContext().lookup("java:comp/env/ejb/SessionEJB");
Sunday, December 24, 2006
MDB deployment in OC4J
1. Create the MDB(normal java class with @MessageDriven annotation). Set the ActivationConfigs.
@MessageDriven(
activationConfig = {
@ActivationConfigProperty(propertyName="connectionFactoryJndiName", propertyValue="jms/TopicConnectionFactory"),
@ActivationConfigProperty(propertyName="destinationName",
propertyValue="jms/demoTopic"),
@ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Topic"),
@ActivationConfigProperty(propertyName="messageSelector", propertyValue="RECIPIENT = 'MDB'") } )
2. Create EJB jar deployment profile(MDBServer.deploy) for the above MDB and deploy it to OC4J server(application name = MDBServer)
3. In same project, create the MDBClient. Inject the resources @Resource(name="jms/demoQueue") and @Resource(name="jms/TopicConnectionFactory"). Use connectionFactory and create connection, then session, message and send the message using producer.
4. In Jdeveloper create jndi.properties file with:
java.naming.factory.initial= oracle.j2ee.naming.ApplicationClientInitialContextFactory
java.naming.provider.url=ormi://localhost:23791/MDBServer
java.naming.security.principal=oc4jadmin
java.naming.security.credentials=welcome
5. Create client Jar deployment profile from Jdeveloper. This creates application-client.xml. Modify application-client.xml and add following lines for the resource reference entries(Make sure to mention the main class file name in descriptor creation)
<application-client xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application-client_1_4.xsd" version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee">
<display-name>MDB1-app-client</display-name>
<resource-env-ref>
<resource-env-ref-name>jms/demoTopic</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Topic</resource-env-ref-type>
</resource-env-ref>
<resource-env-ref>
<resource-env-ref-name>jms/TopicConnectionFactory </resource-env-ref-name>
<resource-env-ref-type>javax.jms.TopicConnectionFactory </resource-env-ref-type>
</resource-env-ref>
</application-client>
6. Deploy the deployment profile MDBClient.deploy to MDBClient.jar.
7. From command prompt containing the jar file, set class path and run :
D:\installs\JdevStudio10131\jdev\mywork\MDB\MDB1\deploy>set CLASSPATH =.\;D:\installs\oc4j\j2ee\home\oc4jclient.jar;D:\installs\oc4j\j2ee\home\lib\javax77.jar;
D:\installs\JdevStudio10131\jdev\mywork\MDB\MDB1\deploy>java oracle.oc4j.appclient.AppClientContainer MDBClient.jar
Output from the application server log will contain:
06/12/24 20:26:44 onMessage() - Message[ID:Oc4jJMS.Message.krishnamoorthy.64e0c3
ab:10fb4f6b670:-8000.4]
onMessage method of the MDB just does a system.out.println(message)
Note: Without creating jar of client files and if I directly run using:
D:\installs\JdevStudio10131\jdev\mywork\MDB\MDB1\classes>java -Djava.naming.factory.initial=oracle.j2ee.naming.ApplicationClientInitialContextFactory -Djava.naming.provider.url=ormi://localhost:23791/MDBServer -Djava.naming.security.principal=oc4jadmin -Djava.naming.security.credentials=welcome myJMSClient.TestJMSClient
I get
Exception in thread "main" java.lang.NullPointerException
at myJMSClient.TestJMSClient.main(TestJMSClient.java:22)
So, should a JMS client be run always using AppClientContainer as :
java oracle.oc4j.appclient.AppClientContainer MDBClient.jar
@MessageDriven(
activationConfig = {
@ActivationConfigProperty(propertyName="connectionFactoryJndiName", propertyValue="jms/TopicConnectionFactory"),
@ActivationConfigProperty(propertyName="destinationName",
propertyValue="jms/demoTopic"),
@ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Topic"),
@ActivationConfigProperty(propertyName="messageSelector", propertyValue="RECIPIENT = 'MDB'") } )
2. Create EJB jar deployment profile(MDBServer.deploy) for the above MDB and deploy it to OC4J server(application name = MDBServer)
3. In same project, create the MDBClient. Inject the resources @Resource(name="jms/demoQueue") and @Resource(name="jms/TopicConnectionFactory"). Use connectionFactory and create connection, then session, message and send the message using producer.
4. In Jdeveloper create jndi.properties file with:
java.naming.factory.initial= oracle.j2ee.naming.ApplicationClientInitialContextFactory
java.naming.provider.url=ormi://localhost:23791/MDBServer
java.naming.security.principal=oc4jadmin
java.naming.security.credentials=welcome
5. Create client Jar deployment profile from Jdeveloper. This creates application-client.xml. Modify application-client.xml and add following lines for the resource reference entries(Make sure to mention the main class file name in descriptor creation)
<application-client xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application-client_1_4.xsd" version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee">
<display-name>MDB1-app-client</display-name>
<resource-env-ref>
<resource-env-ref-name>jms/demoTopic</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Topic</resource-env-ref-type>
</resource-env-ref>
<resource-env-ref>
<resource-env-ref-name>jms/TopicConnectionFactory </resource-env-ref-name>
<resource-env-ref-type>javax.jms.TopicConnectionFactory </resource-env-ref-type>
</resource-env-ref>
</application-client>
6. Deploy the deployment profile MDBClient.deploy to MDBClient.jar.
7. From command prompt containing the jar file, set class path and run :
D:\installs\JdevStudio10131\jdev\mywork\MDB\MDB1\deploy>set CLASSPATH =.\;D:\installs\oc4j\j2ee\home\oc4jclient.jar;D:\installs\oc4j\j2ee\home\lib\javax77.jar;
D:\installs\JdevStudio10131\jdev\mywork\MDB\MDB1\deploy>java oracle.oc4j.appclient.AppClientContainer MDBClient.jar
Output from the application server log will contain:
06/12/24 20:26:44 onMessage() - Message[ID:Oc4jJMS.Message.krishnamoorthy.64e0c3
ab:10fb4f6b670:-8000.4]
onMessage method of the MDB just does a system.out.println(message)
Note: Without creating jar of client files and if I directly run using:
D:\installs\JdevStudio10131\jdev\mywork\MDB\MDB1\classes>java -Djava.naming.factory.initial=oracle.j2ee.naming.ApplicationClientInitialContextFactory -Djava.naming.provider.url=ormi://localhost:23791/MDBServer -Djava.naming.security.principal=oc4jadmin -Djava.naming.security.credentials=welcome myJMSClient.TestJMSClient
I get
Exception in thread "main" java.lang.NullPointerException
at myJMSClient.TestJMSClient.main(TestJMSClient.java:22)
So, should a JMS client be run always using AppClientContainer as :
java oracle.oc4j.appclient.AppClientContainer MDBClient.jar
Friday, December 22, 2006
Running EJB Client Standalone
HelloWorld.java
package myEJB;
import javax.ejb.Remote;
@Remote
public interface HelloWorld {
public String sayHello(String name);
}
HelloWorldBean.java
package myEJB;
import javax.ejb.Stateless;
@Stateless
public class HelloWorldBean implements HelloWorld {
private int count;
public String sayHello(String name) {
count++;
System.out.println("sayHello method from Bean ");
return "Hello " + name + " Count : " + count;
}
}
Compile the classes and run in embedded oc4j of jdeveloper. Or create a ejb jar deployment profile and deploy it to standalone oc4j server. Deployment name is the application name in the standalone oc4j. Let us say application is HelloWorldDeploy. Ear file contains jar file and META-INF. Inside META-INF is the application.xml containing the name of ejb module jar file. Jar file contains the interface and bean classes. After deploying, create a test client as follows:
HelloWorldClient.java
package myEJB;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class HelloWorldClient {
public static void main(String [] args) {
try {
final Context context = new InitialContext();
HelloWorld helloWorld = (HelloWorld)context.lookup("java:comp/env/ejb/HelloWorldBean");
// Call any of the Remote methods below to access the EJB
System.out.println(helloWorld.sayHello( "Krishna" ));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
To invoke ejb method from command line:
D:\work\MyWork\ejb\ejb3>set CLASSPATH=D:\installs\JdevStudio10131\j2ee\home\oc4jclient.jar;.\;
D:\work\MyWork\ejb\ejb3>java -Djava.naming.factory.initial=oracle.j2ee.naming.Ap
plicationClientInitialContextFactory -Djava.naming.provider.url=ormi://localhost
:23791/HelloWorldDeploy -Djava.naming.security.principal=oc4jadmin -Djava.naming
.security.credentials=welcome myEJB.HelloWorldClient
Output is : Hello Krishna Count : 1
package myEJB;
import javax.ejb.Remote;
@Remote
public interface HelloWorld {
public String sayHello(String name);
}
HelloWorldBean.java
package myEJB;
import javax.ejb.Stateless;
@Stateless
public class HelloWorldBean implements HelloWorld {
private int count;
public String sayHello(String name) {
count++;
System.out.println("sayHello method from Bean ");
return "Hello " + name + " Count : " + count;
}
}
Compile the classes and run in embedded oc4j of jdeveloper. Or create a ejb jar deployment profile and deploy it to standalone oc4j server. Deployment name is the application name in the standalone oc4j. Let us say application is HelloWorldDeploy. Ear file contains jar file and META-INF. Inside META-INF is the application.xml containing the name of ejb module jar file. Jar file contains the interface and bean classes. After deploying, create a test client as follows:
HelloWorldClient.java
package myEJB;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class HelloWorldClient {
public static void main(String [] args) {
try {
final Context context = new InitialContext();
HelloWorld helloWorld = (HelloWorld)context.lookup("java:comp/env/ejb/HelloWorldBean");
// Call any of the Remote methods below to access the EJB
System.out.println(helloWorld.sayHello( "Krishna" ));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
To invoke ejb method from command line:
D:\work\MyWork\ejb\ejb3>set CLASSPATH=D:\installs\JdevStudio10131\j2ee\home\oc4jclient.jar;.\;
D:\work\MyWork\ejb\ejb3>java -Djava.naming.factory.initial=oracle.j2ee.naming.Ap
plicationClientInitialContextFactory -Djava.naming.provider.url=ormi://localhost
:23791/HelloWorldDeploy -Djava.naming.security.principal=oc4jadmin -Djava.naming
.security.credentials=welcome myEJB.HelloWorldClient
Output is : Hello Krishna Count : 1
Thursday, December 21, 2006
Transaction Isolation Level
Good link for getting a refresh on the isolation level: http://www.oracle.com/technology/oramag/oracle/05-nov/o65asktom.html
Oracle supports READ COMMITTED and SERIALIZABLE. Oracle doesn't allow dirty reads(READ UNCOMMITTED). It allows a third isolation level which is READ ONLY. No insert, update, delete can be done in this mode.
Oracle supports READ COMMITTED and SERIALIZABLE. Oracle doesn't allow dirty reads(READ UNCOMMITTED). It allows a third isolation level which is READ ONLY. No insert, update, delete can be done in this mode.
Wednesday, December 20, 2006
RMI tutorial on SUN
1. Start the rmiregistry at the default port 1099. (rmiregistry.exe)
2. Start the Local Http server for delivering class files between server-RMI and RMI-Client.
D:\work\MyWork\rmi\suntutorial>java examples.classServer.ClassFileServer 1185 D:\work\MyWork\rmi\suntutorial
3. Then start the ComputeEngine server using :
D:\work\MyWork\rmi\suntutorial>java -cp .\;compute.jar -Djava.rmi.server.codebase=http://pc-krsethur-in:1185/ -Djava.rmi.server.hostname=pc-krsethur-in -Djava.security.policy=D:\work\MyWork\rmi\suntutorial\server.policy engine.ComputeEngine
4. Remove the client files from the suntutorial folder and place it in a folder named test under this suntutorial so that RMI will get the files using http from the client(thus, the above classpath doesn't include the client classes).
5. server.policy should have the line
grant {
permission java.net.SocketPermission "*:*", "listen,accept,connect";
};
for the binding of remote object to the registry(1099).
6. Now run the client as
D:\work\MyWork\rmi\suntutorial\test>java -cp .\;..\compute.jar; -Djava.rmi.server.codebase=http://pc-krsethur-in:1185/test/ -Djava.security.policy=D:\work\MyWork\rmi\suntutorial\client.policy client.ComputePi pc-krsethur-in 45
Output
3.141592653589793238462643383279502884197169399
7. Client.policy should have similar line above(5)
8. here -Djava.rmi.server.codebase=http://pc-krsethur-in:1185/test/ will be set because during client execution, we call executeTask on the proxy remote object. The remote object running in the RMI runtime will delegate to the task object. Now, the task object is still not present in the RMI runtime and will give class not found exception. To prevent that we set the codebase to http://pc-krsethur-in:1185/test/. Here pc-krsethur-in:1185 will deliver files present under D:\work\MyWork\rmi\suntutorial. However, the task class is present in D:\work\MyWork\rmi\suntutorial\test folder. Hence, we append the test/ in the URL for the codebase. Our local file server will serve the classes from D:\work\MyWork\rmi\suntutorial\test for RMI runtime during client execution. Similarly, when the server was started, during binding of remote object, the interface classes(Compute.class and Task.class) for the RMI runtime was served by -Djava.rmi.server.codebase=http://pc-krsethur-in:1185/.
9. After a single execution of both server and client, the classes(Compute.class and Task.class) for the server execution and the class(Task.class) from client execution will be present in the RMI runtime and hence if the local file server is stopped at this time and the server is aborted and restarted, it will work fine without any error about class not found. Similarly if the client is run now also, the client will work fine, because the Task.class is already loaded in the RMI runtime.
10. Now if we stop the rmiregistry.exe(thus all the classes loaded in RMI runtime are gone) and restart the rmiregistry and then start the server or client(with the local file server stopped), they will fail with class not found exception.
2. Start the Local Http server for delivering class files between server-RMI and RMI-Client.
D:\work\MyWork\rmi\suntutorial>java examples.classServer.ClassFileServer 1185 D:\work\MyWork\rmi\suntutorial
3. Then start the ComputeEngine server using :
D:\work\MyWork\rmi\suntutorial>java -cp .\;compute.jar -Djava.rmi.server.codebase=http://pc-krsethur-in:1185/ -Djava.rmi.server.hostname=pc-krsethur-in -Djava.security.policy=D:\work\MyWork\rmi\suntutorial\server.policy engine.ComputeEngine
4. Remove the client files from the suntutorial folder and place it in a folder named test under this suntutorial so that RMI will get the files using http from the client(thus, the above classpath doesn't include the client classes).
5. server.policy should have the line
grant {
permission java.net.SocketPermission "*:*", "listen,accept,connect";
};
for the binding of remote object to the registry(1099).
6. Now run the client as
D:\work\MyWork\rmi\suntutorial\test>java -cp .\;..\compute.jar; -Djava.rmi.server.codebase=http://pc-krsethur-in:1185/test/ -Djava.security.policy=D:\work\MyWork\rmi\suntutorial\client.policy client.ComputePi pc-krsethur-in 45
Output
3.141592653589793238462643383279502884197169399
7. Client.policy should have similar line above(5)
8. here -Djava.rmi.server.codebase=http://pc-krsethur-in:1185/test/ will be set because during client execution, we call executeTask on the proxy remote object. The remote object running in the RMI runtime will delegate to the task object. Now, the task object is still not present in the RMI runtime and will give class not found exception. To prevent that we set the codebase to http://pc-krsethur-in:1185/test/. Here pc-krsethur-in:1185 will deliver files present under D:\work\MyWork\rmi\suntutorial. However, the task class is present in D:\work\MyWork\rmi\suntutorial\test folder. Hence, we append the test/ in the URL for the codebase. Our local file server will serve the classes from D:\work\MyWork\rmi\suntutorial\test for RMI runtime during client execution. Similarly, when the server was started, during binding of remote object, the interface classes(Compute.class and Task.class) for the RMI runtime was served by -Djava.rmi.server.codebase=http://pc-krsethur-in:1185/.
9. After a single execution of both server and client, the classes(Compute.class and Task.class) for the server execution and the class(Task.class) from client execution will be present in the RMI runtime and hence if the local file server is stopped at this time and the server is aborted and restarted, it will work fine without any error about class not found. Similarly if the client is run now also, the client will work fine, because the Task.class is already loaded in the RMI runtime.
10. Now if we stop the rmiregistry.exe(thus all the classes loaded in RMI runtime are gone) and restart the rmiregistry and then start the server or client(with the local file server stopped), they will fail with class not found exception.
Monday, October 23, 2006
Mapping URL to servlet
- Request URI = context path + servlet path + path info
- Context Path and Servlet Path start with a / but do not end with it.
Identifying Servlet Path
- Exact match of URI to any servlet mapping. In this case, entire match is servlet path and path info is null
- Recursive match the longest path by stepping down the request URI path tree to a directory at a time, using / character as a path separator.
- last node of request URI contains extension and there exists servlet that handles request for that extension,
- forward to default servlet. If no default servlet, send an error message
My Notes for SCWCD
- Browser sends web request when
- user clicks on the hyperlink
- form post
- enters address in address bar and press enter - For form data in POST method, enctype attribute should be set as multipart-formdata
- Difference between GET and POST on : resource type, type of data,amount of data,visibility and caching
- Signature of method doXXXX is protected void and it throws ServletException, IOException
- ServletRequest defines getParameter(String Name), getParameterValues(String Name) and getParameterNames() which return String, String[] and Enumeration respectively.
- HttpServletRequest defines getHeader(String Name), getHeaders(String Name) and getHeaderNames() which return String, Enumeration and Enumeration respectively.
- getWriter on ServletResponse returns PrintWriter object and getOutputStream returns ServletOutputStream(extends OutputStream).
- Call to setContentType for setting the mimetype should be done on response object before getWriter or getOutputStream is invoked.
- Either getWriter or getOutputStream should be called. Mixing will result in IllegalStateException
- setHeader on response object sets the header. setIntHeader and setDateHeader similar functions. addHeader, addIntHeader and addDateHeader sets new value for same header if already exists. containsHeader which returns boolean returns true if the header is already set.
- Common headers are : Date, Expires, Last-Modified and Refresh
- sendRedirect on response object does a browser redirect. Calling redirect after response is committed (calling flush on writer) will cause IllegalStateException
- sendError(int errorcode) will send the error code in response header so that browser can display appropriate message(or web server sends appropriate contents).
- ServletContainer loads and instantiates servlet by calling Class.forName(...).new Instance(). To do this there should be a public constructor with no arguments. Having a default class with no constructor or a public class with some constructor having arguments(no default constructor) will error when accessed by client with 500 status.
- Two init methods. one takes ServletConfig and the other none. Overriding the one which takes parameter requires a call to super.init to store the config object. instead the GenericServlet's init method which takes parameter makes a call to the no argument init method. So, overriding the no argument init method takes care of everything. To get servletconfig in no arg method call, getServletConfig()
- Servlet not initialized at startup to reduce the startup time. However if large initialization is done then the first request for servlet will take long time. To prevent this servlet can be preinitialized at startup by the element in descriptor.
- ServletConfig class has getInitParameter and getInitParameterNames which return String and Enumeration respectively. It has getServletContext and getServletName methods.
- getResource on ServletContext return java.net.URL. call openStream on URL to get InputStream. Instead call getResourceAsStream to directly get Stream corresponding to resource.
- Limitation of getResource is that any URL for any active resource cannot be passed. This will result in security loophole. getResource on jsp file returns the source code of jsp and not the executed output.
Oracle Collections
Good Link for on Oracle collection : http://sheikyerbouti.developpez.com/collections/collections.htm
Thursday, October 19, 2006
Microsoft Fiddler - HTTP Proxy
Installed IE7 and got a good add-on for debugging http traffic. Fiddler Link
Monday, September 25, 2006
Cleared SCJP 5.0 atlast
Cleared SCJP5 today with 91%.
Split Up:
Declarations, Initialization and Scoping - 100
Flow control : 81
API : 100
Concurrency : 87
OO concepts: 90
Collections / Generics : 90
Fundamentals : 90
Split Up:
Declarations, Initialization and Scoping - 100
Flow control : 81
API : 100
Concurrency : 87
OO concepts: 90
Collections / Generics : 90
Fundamentals : 90
Sunday, September 24, 2006
finalize method
if in finalized method, there is a call to super(), then handle the throwable in the finalize method of the class, as the finalize of Object class throws Throwable.
synchronized code
synchronization possible on objects only and not on primitives
int x;
synchronized(x) will be compiler error. No autoboxing here...
int x;
synchronized(x) will be compiler error. No autoboxing here...
Assign String to String Buffer
StringBuffer sb = "hello";
this won't compile. StringBuffer have to be explicity created by new operator.
this won't compile. StringBuffer have to be explicity created by new operator.
Ambiguous Match
When class implements two or more interface(or extends classes) containing same member varaible type(say, int i). Referencing this variable in the new class will cause ambiguous match for compiler as long as that variable is not redefined in the new class. Redefining the variable in new class will resolve the issue.
Method of private inner class : Accessibility
Not possible to access methods of private inner class as the following code will give compile error.
class MyOuter{
private class MyInner{
public float f(){return 1.2f;}
}
public MyInner getMyInner(){
return new MyInner();
}}
public class Test13{
public static void main(String... args){
MyOuter o = new MyOuter();
float f = new MyOuter().getMyInner().f();
}
}
Format string conversion
For %b(boolean) : All data types can be passed
For %c(char) : byte, char, short, int
For %d(int) : byte, short, int, long (No char)
For %f(float) : only float and double
For %s(string) : everything
=======================================
public class Test12{
public static void main(String... args){
boolean b = false;
byte by = 2;
char c = 'A';
short s = 7;
int i = 35565;
long l = 2345676436323746l;
float f = 234.567f;
double d = 234.678;
//System.out.printf("%d\t", b);
System.out.printf("%d\t", by);
//System.out.printf("%d\t", c);
System.out.printf("%d\t", s);
System.out.printf("%d\t", i);
System.out.printf("%d\t", l);
//System.out.printf("%d\t", f);
//System.out.printf("%d\t", d);
System.out.println();
System.out.printf("%b\t", b);
System.out.printf("%b\t", by);
System.out.printf("%b\t", c);
System.out.printf("%b\t", s);
System.out.printf("%b\t", i);
System.out.printf("%b\t", l);
System.out.printf("%b\t", f);
System.out.printf("%b\t", d);
System.out.println();
System.out.printf("%s\t", b);
System.out.printf("%s\t", by);
System.out.printf("%s\t", c);
System.out.printf("%s\t", s);
System.out.printf("%s\t", i);
System.out.printf("%s\t", l);
System.out.printf("%s\t", f);
System.out.printf("%s\t", d);
System.out.println();
//System.out.printf("%f\t", b);
//System.out.printf("%f\t", by);
//System.out.printf("%f\t", c);
//System.out.printf("%f\t", s);
//System.out.printf("%f\t", i);
//System.out.printf("%f\t", l);
System.out.printf("%f\t", f);
System.out.printf("%f\t", d);
System.out.println();
//System.out.printf("%c\t", b);
System.out.printf("%c\t", by);
System.out.printf("%c\t", c);
System.out.printf("%c\t", s);
System.out.printf("%c\t", i);
//System.out.printf("%c\t", l);
//System.out.printf("%c\t", f);
//System.out.printf("%c\t", d);
}
}
========================
Output:
2 7 35565 2345676436323746
false true true true true true true true
false 2 A 7 35565 2345676436323746 234.567 234.678
234.567001 234.678000
A ?
For %c(char) : byte, char, short, int
For %d(int) : byte, short, int, long (No char)
For %f(float) : only float and double
For %s(string) : everything
=======================================
public class Test12{
public static void main(String... args){
boolean b = false;
byte by = 2;
char c = 'A';
short s = 7;
int i = 35565;
long l = 2345676436323746l;
float f = 234.567f;
double d = 234.678;
//System.out.printf("%d\t", b);
System.out.printf("%d\t", by);
//System.out.printf("%d\t", c);
System.out.printf("%d\t", s);
System.out.printf("%d\t", i);
System.out.printf("%d\t", l);
//System.out.printf("%d\t", f);
//System.out.printf("%d\t", d);
System.out.println();
System.out.printf("%b\t", b);
System.out.printf("%b\t", by);
System.out.printf("%b\t", c);
System.out.printf("%b\t", s);
System.out.printf("%b\t", i);
System.out.printf("%b\t", l);
System.out.printf("%b\t", f);
System.out.printf("%b\t", d);
System.out.println();
System.out.printf("%s\t", b);
System.out.printf("%s\t", by);
System.out.printf("%s\t", c);
System.out.printf("%s\t", s);
System.out.printf("%s\t", i);
System.out.printf("%s\t", l);
System.out.printf("%s\t", f);
System.out.printf("%s\t", d);
System.out.println();
//System.out.printf("%f\t", b);
//System.out.printf("%f\t", by);
//System.out.printf("%f\t", c);
//System.out.printf("%f\t", s);
//System.out.printf("%f\t", i);
//System.out.printf("%f\t", l);
System.out.printf("%f\t", f);
System.out.printf("%f\t", d);
System.out.println();
//System.out.printf("%c\t", b);
System.out.printf("%c\t", by);
System.out.printf("%c\t", c);
System.out.printf("%c\t", s);
System.out.printf("%c\t", i);
//System.out.printf("%c\t", l);
//System.out.printf("%c\t", f);
//System.out.printf("%c\t", d);
}
}
========================
Output:
2 7 35565 2345676436323746
false true true true true true true true
false 2 A 7 35565 2345676436323746 234.567 234.678
234.567001 234.678000
A ?
Saturday, September 23, 2006
Friday, September 22, 2006
Some more SCJP5 tips
- enum declaration outside class cannot contain static, final or any access modifiers, although enum type is implicity static and final. However enum declaration inside class can be declared as static(although implicitly static) but explicit declaration as final will be compiler error. Explicit declaration of static or final for enums outside class is also compiler error.
- Two special cases where primitive == doesn't match the object equals method. NaN and +0.0f with -0.0f. For first case, primitive == is false(so equals will return true) and for second case primitive == is true(so equals will return false).
- final instance variables need to get initialized before the constructor ends.(else compiler error).
- Protected member inherited to subclass can be accessed in the subclass by a member of declared type as subclass but not by a member of declared type as superclass. Inherited protected member will not be accessible by other classes in the same package of subclass(unless they also extend the subclass).
- ArrayStoreException : Storing a object in a array of another object type. E.g., Object[] a = new String[5]; a[0] = new Integer(1); here storing a integer in a array object(whose runtime type is String array causes Heap Pollution).
- Compile type determines which overloaded method to be invoked. Run time type determine which overridden method to be invoked.
- Constructor is never inherited and hence no overriding. static methods are inherited but can not be overridden.
- result of expression is integer. so, byte b = 7+3; will be compile error. Needs explicit cast. However for compound assignment, explicit cast is not required. Thus, byte b = 127; b += 3; will run fine and will give output as -126.
- local variable initialization before use. Even null check on a local variable cannot be done before the local variable is initially set as null. Thus, Date d; if(d == null) will cause variable not initialized error. Initialization within if condition or for loop which the compiler is not certain will be executed and then accessing the variable later down the line will also cause variable not initialized error.
- When initializing multi-dimension array, the second size can be omitted. However, before assigning the elements into the second dimension array, it has to be initialized with the size of the second dimension. i.e., each of the first dimension array should be assigned a new array object with size specified in the new constructor.
- auto-unboxing may result in NPE. e.g., passing wrapper objects to method which expects a primitive and that the wrapper object passed is a instance member variable not initialized.
- overloading between methods is fine between one which takes a primitive and other which takes the wrapper of primitive.
- In switch statement, case labels should be compile time constants(final variable should be initialized in same line when declared). Duplicate case label will be a compile time error. case label constants should be within the range of the switch argument otherwise compile error.
Wednesday, August 30, 2006
KeepResident plugin for Eclipse/Jdeveloper
Jdeveloper being slow when shifting the application in windows. Reason being the windows swapping the jdeveloper memory even when large amount of physical memory is available.Application has a working set size. The default value is much too small for big Java applications like Eclipse. Hence, windows does a swapping. To prevent this, one thing that can be done is to increase the minimum water mark of this working set size. Then, there is another problem that when the user memory is less than the minimum working set size, windows will think that the application is not used and will do swapping again. Using VirtualLock() will prevent this and force Windows to keep Eclipse in memory.
Got this information from the blog : http://www.orablogs.com/gdavison/archives/001659.html
FAQ on this plugin also provides a clear information : http://suif.stanford.edu/pub/keepresident/faq.html
Got this information from the blog : http://www.orablogs.com/gdavison/archives/001659.html
FAQ on this plugin also provides a clear information : http://suif.stanford.edu/pub/keepresident/faq.html
Subscribe to:
Posts (Atom)