Thursday, May 27, 2010
Charater set vs encoding
examples:
ASCII, ISO-8859-1 to ISO-8859-13 ISO-8859-15 (each set represent a different language set)
Unicode
An encoding maps a character set's code points to units of a specific width, and defines byte serialization and ordering rules.
example: UTF-8
UTF-8 unifies US-ASCII with Unicode.
http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/i18n/i18n2.html
Locale
Internationalization, also known as "I18n," is the process of separating locale dependencies from an application's source code.
Examples of locale dependencies include messages and user interface labels, character set, encoding, and currency and time formats.
Localization (also called "L10n") is the process of adapting an internationalized application to a specific locale. An application must first be internationalized before it can be localized.
Class java.util.Locale represents a locale in the Java 2 Platform, Standard Edition (J2SE). A Locale object is an identifier in a program that determines such factors as how numbers, currency, and time should be displayed, and the human language used to present data in a user interface.
Thursday, May 20, 2010
Localization vs. Internationalization
* Localization of internationalized software is done by simply adding locale-specific components, such as translated messages, data describing locale-specific behavior, fonts, and input methods, etc.
http://javaboutique.internet.com/tutorials/leskov/
More Reading
http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/i18n/i18n.html
Tuesday, May 18, 2010
Data Types
Java does not have any unsigned types
4 integer types
(int, long, short, byte)
4 bytes, 8 bytes, 2 bytes, 1 byte
long number: 400000000L
Hexadecimal: 0xCAFE
Octal: 0700
2 Floating point types
float (4), double (8)
exit code in Java
Thursday, May 13, 2010
Principles behind the Agile Software Development
http://agilemanifesto.org/principles.html
Our highest priority is to satisfy the customer through early and continuous delivery of valuable software.Welcome changing requirements, even late in development. Agile processes harness change for the customer's competitive advantage.
Deliver working software frequently, from a couple of weeks to a couple of months, with a
preference to the shorter timescale.
Business people and developers must work together daily throughout the project.
Build projects around motivated individuals. Give them the environment and support they need,and trust them to get the job done.
The most efficient and effective method of conveying information to and within a development team is face-to-face conversation.
Working software is the primary measure of progress.
Agile processes promote sustainable development.The sponsors, developers, and users should be able to maintain a constant pace indefinitely.
Continuous attention to technical excellence and good design enhances agility.
Simplicity--the art of maximizing the amount of work not done--is essential.
The best architectures, requirements, and designs emerge from self-organizing teams.
At regular intervals, the team reflects on how to become more effective, then tunes and adjusts its behavior accordingly.
linklist implementation in Java
private Object element ;
private Node next;
private Node prev;
// constructors
public Node(Object element){
this.element = element;
next = null;
prev = null;
}
}
public class LinkedList{
private Node tail;
private Node head;
//construct an empty list
public LinkedList(){
head= new Node(null);
tail = head;
}
public void addFirst(Node n){ // add to the beginning of the list
n.next = header.next ;
header.next = n;
}
public void addLast(Node n){ // add to the end of the list
n.prev = tail.prev ;
tail.prev = n;
}
remove();
find();
size();
}
the difference between a linked list and an array
downside: sequential access. Finding a node takes linear time. O(n)
Arrays are fixed in size, so resources must be anticipated and consumed in advance. Each element is the same size and must contain the same data type.Finding a node is fast, can be calculated mathmetically
Wednesday, May 12, 2010
Thread Safe Collections
A new Java JDK package was introduced at Java 1.5, that is java.util.concurrent
. This package supplies a few Collection implementations designed for use in multithreaded environments.
You can use the non-synchronized implementations in multiple thread environments, when you make sure that only one thread updating the collection at any given time.
The following table list all the syncronized collection classes:
syncronized | non-syncronized | |
---|---|---|
Vector | ArrayList | |
Stack | ||
LinkList | ||
CopyOnWriteArrayList | ||
jTreeSet | ||
HashSet | ||
LinkHashSet | ||
CopyOnWriteArraySet | ||
TreeMap | ||
Hashtable ConcurrentHashMap | jHashMap | |
LinkHashMap | ||
IdentityHashMap | ||
EnumMap |
Collection
the UML diagram are very clear on this page.
The Java JDK contains two high level Interfaces:
- java.util.Collection
- java.util.Map
java.util.Collection
interface. The Collection interface has three sub interfaces.- java.util.Set
(implementation are TreeSet,HashSet ...) Set
cannot have duplicates in it.- java.util.List
- ( implementation are Vector,Stack,ArrayList,LinkedList,AttributeList,RoleList...)
- interfaces SortedSet
- java.util.Queue
( implementation are: PriorityQueue, ArrayBlockingQueue ..) interface: BlockingQueque
java.util.Map implementations are:
TreeMap,HashMap, HashTable,LinkedHashMap,IdentityHashMap ..
Before selecting a particular collection implementation, ask the following question:
- Can my collection contain the same elements, i.e. are duplicates allowed?
- Can my collection contain the
null
element? - Should the collection maintain the order of the elements? Is the order important in any way?
- How do you want to access an element? By index, key or just with an iterator?
- Does the collection need to be synchronized?
- From a performance perspective, which one needs to be faster, updates or reads?
- From a usage perspective, which operation will be more frequent, updates or reads?
Tuesday, May 11, 2010
Java Annotations
Annotations do not directly affect program semantics, but they do affect the way programs are treated by tools and libraries, which can in turn affect the semantics of the running program. Annotations can be read from source files, class files, or reflectively at run time.
Annotations complement javadoc tags. In general, if the markup is intended to affect or produce documentation, it should probably be a javadoc tag; otherwise, it should be an annotation.
Define : An at-sign (@) precedes the interface keyword
/**
* Describes the Request-For-Enhancement(RFE) that led
* to the presence of the annotated API element.
*/
public @interface infoForMethod {
int id();
String s1();
String s2() default "[unassigned]";
String s3(); default "[unimplemented]";
}
Use Annotation:
An annotation is a special kind of modifier, and can be used anywhere that other modifiers (such as public, static, or final) can be used.
@infoForMethod (
id = 123456,
s1= "AAAAA",
s2= "BBBB",
s3= "4/1/2009"
)
public static void aMethod(Date destination) { ... }
---
An annotation type with no elements is termed a marker annotation type
define: public @interface example{ }
Use:
@example
public void aMethod()
--
In annotations with a single element, the element should be named value,
/**
* Associates a copyright notice with the annotated API element.
*/
public @interface Author{
String value();
}
use
m.isAnnotationPresent()
Sample Junit Test
import static org.junit.Assert.* ;
public class ATest {
@Test
public void test_method() {
A a = new A(200,2) ;
assertTrue(a.getM() == 1.0) ;
}
The marker @Test is called an
annotation in Java. When we later execute JUnit’s test runner it needs
to know which methods in your test class are test methods (e.g. you may
have several helper methods in your test class). The @Test is used to mark that a method is a test method.
Junit Version
currently I am using junit-3.8.2.jar which is installed eclipse plugin.
You can also find out Junit Version in Java by doing the following:
import junit.runner.Version;
System.out.println("JUnit version is: " + Version.id());