- Variables
Kinds of variables base on scope: local, instance, class
Hiding/Shadowing Variables
- redeclaring a variable that’s already been declared somewhere else. The closest scope is used when you refer it through simple name.
1) local var hides instance var
- use this to access the instance var
2) instance var hides inherited var
- use super.name or cast the object to its super class, with the syntax ((Superclass)object).name
- when the variable is accessed thru the object containing it, the variable used depends on the type the object it was declared with or casted to, not the runtime type of the object. - Methods
Overloading
- same name, diff arguments, return type doesn't matter
Overriding
- same signature (method name + arguments), same return type diff classes
- instance to instance method only
Hiding
- static to static only
- when the method is called thru the object containing it, the method used depends on the type the object it was declared with or casted to, not the runtime type of the object.
Not allowed in methods but allowed in variables/fields:
- static to non-static or vice versa
- narrowing visibility
- different return type (but same signature/name) -> compile error in methods - Object
- implicit superclass of all classes
- must be overridden in objects -> equals(), hashCode(), toString()
clone() method
-protected|public Object clone() throws CloneNotSupportedException
aCloneableObject.clone();
- aCloneableObject must implemenet Cloneable interface
- default behavior of Object's clone() -> creates an object of the same class as the original object and initializes the new object's member variables. But if a member variable is an external object, say ObjExternal, ObjExternal is not cloned but shared. A change in ObjExternal made by one object will be visible in its clone also.
equals() method
- uses ==
- if overridden, u must override hashCode() too. If two objects are equal, their hash code must also be equal.public boolean equals(Object obj) { if (obj instanceof Book) return ISBN.equals((Book)obj.getISBN()); else return false; }
- Abstract vs Interface
- http://mindprod.com/jgloss/interfacevsabstract.html
- when to use one over the other:
General rule is if you are creating something that provides common functionality to unrelated classes, use an interface. If you are creating something for objects that are closely related in a hierarchy, use an abstract class.
Saturday, March 6, 2010
Java Inheritance
Friday, March 5, 2010
Sample CVS config spec
-main
-branch
element * CHECKEDOUT element * /main/LATEST load \Acctsvcs
-branch
element * CHECKEDOUT element * /main/nae_phase1c/LATEST element * /main/NAE_ROOT_PHASE1C -mkbranch nae_phase1c element * /main/LATEST -mkbranch nae_phase1c load \Acctsvcs
Eclipse Pointers / Links
- {object} cannot be resolved in Eclipse
http://blog.sherifmansour.com/?p=207
- installing plugins in Eclipse
http://www.venukb.com/2006/08/20/install-eclipse-plugins-the-easy-way
- SVN Working Copy xxx locked and cleanup failed - Right click on the project then Team -> Cleanup
- setting for debug
SET JAVA_OPTS= -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
or
set MEM_ARGS=-Xms32m -Xmx200m
set JAVA_OPTIONS=-Xverify:none -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=7919
- display tool/icon for showing method only or all source
Window > Customize Perspective.... > Tool Bar Visibility > Editor Presentation > Show Source of Selected Element Only
http://blog.sherifmansour.com/?p=207
- installing plugins in Eclipse
http://www.venukb.com/2006/08/20/install-eclipse-plugins-the-easy-way
- SVN Working Copy xxx locked and cleanup failed - Right click on the project then Team -> Cleanup
- setting for debug
SET JAVA_OPTS= -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
or
set MEM_ARGS=-Xms32m -Xmx200m
set JAVA_OPTIONS=-Xverify:none -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=7919
- display tool/icon for showing method only or all source
Window > Customize Perspective.... > Tool Bar Visibility > Editor Presentation > Show Source of Selected Element Only
Monday, March 1, 2010
Monday, February 22, 2010
Weblogic 9 setup
- Create domain directory
- Go to {weblogic.dir}\weblogic92\common\bin and run config.cmd
- Select Create a new Weblogic domain
- Select the source (automatic or with template)
- Input admin username and password
- Choose startup mode and JDK. Use JRocket for JDK.
- Enter domain name & location and click Create Check Start Admin Server and click Done
- Change port number
- Go to http://{hostname/localhost}:7001/console and login
- Navigate to {domain name}->Environment-Servers. Select AdminServer(admin)
- Change the Listen Port and save changes.,/li>
- Activate changes
- Add the db2jcc jars for the DB2 driver classes
- Go to your DB2 installation or <sqllib_home>\java directory
- Copy the following jars to your <weblogic_domain>\lib directory:
- db2jcc.jar
- db2jcc_license_cu.jar
- db2jcc_license_cisuz.jar
- Restart server
- Add JDBC Data Source
- Navigate to {domain name}->Services->JDBC->Data Sources. Add new data source.
- Set Data Source properties and click Next
Name: db2Pool JNDI Name: db2Pool Database Type: DB2 Database Driver: IBM's DB2 Driver(Type 2)
- Select transaction options (use defaults)
- Set connection properties and click Next
Database Name: db2test Host Name: Port: Database User Name: coreusrt Password:
- Test Database Connection. Update the following:
Driver Class Name: com.ibm.db2.jcc.DB2Driver URL: jdbc:db2://db2t.vigslbp.bear.com:5510/DB2TEST
click Test Configuration and Next - Select the server and click Finish
- Activate changes
- Deploy Web App
Note: Make sure that the WEB-INF/lib of the webapp contains all needed lib (ex. by copy.runtime.lib)- Navigate to {domain name}->Deployments. Click Install
- Select the path of your application root directory (webapp directory). Click Next
- Select Install this deployment as an application and click Next
- Set settings (use default) and click Next
- Review choices and click Finish
- Activate changes
- Navigate back to {domain name}->Deployments. Select webapp and click Start servicing all requests. Start deployment
- Finish! You may now go to your webapp.
Sample: http://pbctx60.bsna.bsroot.bear.com:7831/acctsvcs-nae/nae/acctvwup?action=showPage
Tuesday, February 16, 2010
Java Annotations
- provides data about a program but do not directly affect the program semantics
- defined similar to interface
@interface Author {
String author();
String date();
String[] reviewers(); // Note use of array
} - sample use:
@Author(
name = "Benjamin Franklin",
date = "3/27/2003",
reviewers = {"Alice", "Bob", "Cindy"} // Note array notation
)
class MyClass() { }
3 Predefined Annotation Types:
1) @Deprecated - should also be documented using the Javadoc @deprecated tag
/**
* @deprecated
* explanation of why it was deprecated
*/
@Deprecated
2) @Override
3) @SuppressWarnings
@SuppressWarnings("deprecation") //deprecation warning - suppressed
@SuppressWarnings({"unchecked", "deprecation"}) // legacy code & deprecation warning - suppressed
Detailed explanation here: http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html
Subscribe to:
Posts (Atom)