Archive for the 'Java' Category


Quick Eclipse Shortcuts ..

Oct 28, 2009 in Eclipse, Uncategorized


  • — Open Type – Ctrl+Shift+T
  • — Pick part of a string – select section, press Ctrl+1
  • — Quick Outline – Ctrl+O
  • — Enable ‘Breadcrumbs Bar’ – Alt+Shift+B
  • — Code formatting – highlight, Ctrl+Shift+F
  • — Watch the ‘Overview Ruler’ for errors or warnings

From the “Workbench User Guide” ..

History Navigate > Backward (Alt+Left Arrow)

Various Functions > Ctrl+3

Editor List > Ctrl+E

Global Find/Replace > Ctrl+H

Customize, View Keys / Shortcuts > Menu / General / Keys

Find a string incrementally > Edit / Incremental Find Next (Ctlr+J)
> or Find Previous (Ctrl+Shift+J)

Go to last edit location > Navigate / Go to last edit location (Ctrl+Q)

Manipulating lines > Insert new line above (Ctrl+Shift+Enter) or below (Ctrl+Enter)
> Convert to lowercase (Ctrl+Shift+Y) or uppercase (Ctrl+Shift+X)

Quick Diff (what changed while editing) > General / Editors / Text Editors / Quick Diff (Ctrl+Shift+Q)

Next / previous navigation > next = Ctrl+. , previous = Ctrl+, (plus comma)

Word completion > Alt+/. (Ctrl+. on the Mac)

Tomcat performance monitoring..

Aug 27, 2009 in Java, Tomcat


  • Tomcat Resource Pools.

    Connector Thread Pool

    Database Connection Pool

  • Use Tomcat Valves for implementing lightweight monitoring w/o JMX.

Hash table notes..

Aug 26, 2009 in Engineering, Java, JavaUsage, Software


  • Hash tables are backed by arrays.
  • A hash function is used to map the keys to an index within the backing array.
  • Put, Get, Delete operations all run in constant ( O(1) ) time.
  • Hash function determines performance.
  • Even with the best hash function, collisions can occur.
  • Main advantage of HTs over other data structures is speed.
  • Growing HTs need to be rehashed but the cost is amortized by constant cost of ‘put’.
  • Should not use HTs for small data sets, but everybody does.
  • Rehashing should occur when the load factor (occupied array slots / array size) reaches over .75.

Java example of basic cache (LRU) using LinkedHashMap ..

Aug 24, 2009 in Algorithms, Java, JavaUsage


import java.util.Map;
import java.util.LinkedHashMap;

public class t1 {

    final int MAX_ENTRIES = 2;

    Map cache = new LinkedHashMap(MAX_ENTRIES+1, .75F, true) {
        // This method is called just after a new entry has been added
        public boolean removeEldestEntry(Map.Entry eldest) {
            System.out.println("eldest: " + eldest.getKey() + "=" + eldest.getValue());
            return size() > MAX_ENTRIES;

    public void cacheAdd(String pkey, String pstr) {
        // Add to cache
        cache.put(pkey, pstr);

    public static void main(String[] args) {
        t1 ot1 = new t1();
        ot1.cacheAdd("k1", "str1");
        ot1.cacheAdd("k2", "str2");
        ot1.cacheAdd("k3", "str3");
        ot1.cacheAdd("k4", "str4");

    /* --
// Get object
Object o = cache.get(key);
if (o == null && !cache.containsKey(key)) {
    // Object not in cache. If null is not a possible value in the cache,
    // the call to cache.contains(key) is not needed

// If the cache is to be used by multiple threads,
// the cache must be wrapped with code to synchronize the methods
cache = (Map)Collections.synchronizedMap(cache);
-- */


Also, see
. . .

Notes on “Java Web Services” ..

Jul 02, 2009 in Books, Java, Software, WebServices

This book is a bit old.. 2002..

  • — SOA – Service Oriented Architecture
    — 3 major roles: Provider, Registry (Broker) and Requester.
    — SOA is based on web services.
  • — SOAP – Simple Object Access Protocol
    — 2 major methods: Message-based Document Exchange AND RPC
    (Remote Procedure Calls).
    — All structures based on XML.
    — A SOAP message contains an Envelope and a Header.
    — A SOAP message may contain (MIME) attachments.
    — Main transport protocol is HTTP(S).
    — Providers (Receivers) are usually based on Servlets.
  • — SOAP-RPC
    — Method signatures contain a single SOAP structure.
    — SOAP service methods must match info in deployment descriptor.
    — Errors and Faults: VersionMismatch, MustUnderstand, DTDNotSupported, etc..
  • — WSDL – Web Services Description Language
    — WSDL is an XML grammar for describing a web service
    as a collection of access end-points capable of exchanging
    messages in a procedure- or document-oriented fashion (p. 72)
    — The reasonable flow is to create service methods and
    than generate WSDL from code using tools.
    — Best practices: web service is (functionally) coarse-grained
    and messages are more business-oriented than programmatic.
  • — UDDI – Universal Description, Discovery and Integration
    — Similar to an Internet search engine for businesses.
    — UBR – UDDI Business Registry (the Public Cloud).
    — Designed for B2B mostly.
    — 2 APIs: inquiry and publishing API.
    — JAXR = Java API for XML Registries.
    — Some details: Categorization (NAICS, ISO, etc..),
    Identifier (DUNS, Thomas Reg, etc),
    tModel (web service metadata)
  • — JAX-RPC and JAXM
    — JAXM = Java API for XML Messaging.
    — JAX-RPC = Java API for XML-based RPC.
    — JAXM may be used as a frontend to SOAP-based messaging
    frameworks through the use of “profiles”.
    — JAX-RPC covers code generation for client and server parts,
    dynamic SOAP, creating services within J2EE and J2SE environments,
    bindings, serialization, mapping of datatypes between WSDL and Java,
  • — The Java Web Service (JWS) Standard
    — Proposed by BEA, using templates to create simple web services.
    — Example (HelloWorld.jws <- note the .jws extension)
    Note the annotations @operation, @conversation ..

    import com.bea.jws.*
    public class HelloWorld extends Service {
      * @operation
      * @conversation stateless
      public String getHelloWorld() {
        return "Hello, World!";

    Other values for @conversation are ‘start’, ‘continue’ or
    ‘finish’. The ‘start’ directive, for example, starts a session.

  • — Security notes
    — Use of SSL (HTTPS), encryption, signing and secure hashing.
    — Security Assertion Markup Language (SAML) – used with Single Sign-On (SSO).
  • — Resources

Colophon – European (Alpine) Ibex – a wild goat.

Java pattern matching example..

Jun 19, 2009 in Java, JavaUsage

import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class TestPattern {
    public static void main(String[] args) {
	String pin = "1234567";
	String pinPattern = "[0-9]+";
	String result = null;

	Pattern pattern = Pattern.compile(pinPattern);
	Matcher matcher = pattern.matcher(pin);

	result = "";
	while(matcher.find()) {
	    result +=;
	if (result.equals(pin)) {
	    result = "PIN accepted";
	else {
	    result = "PIN invalid";

Notes from ‘Java Web Services’ book ..

Jun 18, 2009 in Books, Java, JavaUsage

SOAP – Simple Object Access Protocol
WSDL – Web Services Description Language
UDDI – Universal Discovery, Description and Integration

Major characteristics:
— XML-Based
— Loosely coupled – interfaces may change without loss of service.
— Coarse-grained – provide high-level business functions.
— Both synchronous and Asynchronous
— Supports RPC (Remote Procedure Calls)
— Supports document exchange

Interface vs Abstract Class ..

Apr 23, 2009 in Engineering, Java, JavaUsage, Software

  • — Inheritance from anything (including abstract)
    should be a function of the business model.
  • — If a class does not _really_ inherit from
    an abstract, one should not use it.
  • — Use interface to avoid the problem of multiple
  • — Use interface to improve modularity.. if one
    uses an abstract class and the class changes,
    it may break subclasses.
    (not method signatures but logic/code.. changing
    method signatures is a problem for both abstract
    and interface)
  • — Use interfaces when some part of the design
    will change frequently.
  • — Interface for plug-in architectures – like
    the strategy pattern.
  • — Use abstract class to provide basic services
    for derived classes (event, message handling)
  • — In favor of abstract class:
    • — interfaces may be more difficult to read in
      code logic.
    • — interfaces are somewhat slower due to

Notes on Java Collections..

Mar 23, 2009 in Java, JavaUsage, Uncategorized

Collections characteristics:

  • synchronized (hashtable-yes, hashmap-no, vector-yes, arraylist-no)
  • directionality (iterators)
  • allow null values (hashtable-no, hashmap-yes)
  • preserve insert order
  • duplicates (set-no, list-yes)


  • Collections interfaces: Collection, Set, List and Map.
  • To synchronize HashMap:

    Map m = Collections.synchronizeMap(hashMap);

  • Some implementations: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.
  • An ArrayList is resizable, where as, an array is not.
  • Hashmap overrides?

    The methods to override are equals() and hashCode().

  • Difference between Enumeration and Iterator?

    Enumeration is read-only. Iterator provides remove and add methods
    and it is fail-fast in multi-threaded configurations.

Eclipse TPTP usage notes..

Sep 30, 2008 in Eclipse

Notes on setting profiling and performance monitoring in Eclipse with TPTP – Test and Performance Tools Platform.