Archive

Author Archive

How to remove duplicate array values in java

This afternoon one of my friend asked how to eliminate duplicate element on integer array. My solution is simple, first we need to sort the array, second loop the array and copy the different element to new array. The new array will have different element.

Read more…

Categories: JAVA

Troubleshooting Glassfish with HADB

Yesterday I played GlassFish 2.1.1 with HADB, there are two servers. First server I have a database status is nonoperational and second server status is stopped. Here workaround that I did.

Database status NonOperational

cypher_2

For this case the solution is quite easy. Read more…

Install Glassfish 2.1.1 with HADB

The following article is a note of my activity today play with high availability cluster in Glassfish 2.1.1.
The contents of this article can be use to learn to make HA-cluster in Glassfish 2.1.1 but not intended for production.

Note: when try to install Glassfish using java that came with installer. If you use java with higher versions then you will encounter an error when running the node agent and cluster. Read more…

Categories: JAVA Tags: , , ,

My JAVA Note

Categories: Umum

Class Members

Class members means methods and instance (nonlocal) variable. If a class cannot be accessed, its members cannot be accessed.

 

Access Modifier

For class members, access means:

  1. Can access a member of anotehr class.
  2. Can inherit a member of it superclass.

Class members have four access control level:
public
Can be accessed by all other classes, even in other package.

private
Can be accessed only by code in the same class.
Not visible to sublcass, so private members cannot be inherited.
For best practice, instance variable must be mark by private. There can be access by methods (mark by public).

protected and default
Default members can be acces only by classes in the same package.
protected members can be accessed by other classes in the same package, plus subclasses regardless of package.
For subclasses outside the package, the protected member can be access only through inheritance.
A protected member inherited by subclass from another package is not accessible to any other class in the subclass package, except for the subclass own subclasses.
Local variables declaration cannot have access modifier. The only one modifier is final. They don’t get default value, you must initialized before use.

 

Read more…

Categories: JAVA

Array

Declaring an array:

int[] key;
Thread[] threads;
String[][] occupantName;

Initialized array:

int[] key = new int[5];
Thread[] threads = new Threads[4];
String[][] occupantName = new String[10][]; //first bracket must given an size, second is optional.
int[] carList = new int[]; //will not compile, need size
String[] days = {"Sunday", Monday", Tuesday", "Wendsday", "Thirdday", "Friday", "Saturday"}; //the size determined by the number of comma-separated items between the curly braces

Note:

  1. Arrays can hold primitives or objects, but the array itself is always an object.
  2. When you declare an array, the brackets can be left or right of the name.
  3. It is never legal to include the size of an array in the declaration.
  4. You must include the size of an array when you construct it (using new) unless you are creating an anonymous array.
  5. Elements in an array of object are not automatically created, although primitive array elements are given default value.
  6. You’ll get a NullPointerException if you try to use an array element in an object array, if that element does not refer to a real object.
  7. Arrays are indexed beginning with zero.
  8. An ArrayIndexOutOfBoundException occurs if you use a bad index value.
  9. Arrays have a length variable whose value is the number of array elements.
  10. The last index you can access is always one less than the length of the array.
  11. Multidimensional arrays are just arrays of arrays.
  12. The dimension in a multidimentional array can have differeny lengths.
  13. An array of primintives can accept any value than can be promoted implicitly to the array’s declared type. Example byte variable can go in an int array.
  14. An array of object can hold any object that passes the IS-A (or instanceof) test for the declared type of the array.
  15. If you assign an array to the previously declared array references, the array you’re assigning must be the same dimension as the reference you’re assigning to.
  16. You can assign an array of one type to a previously declared array reference of one of is supertypes.

 

 

Categories: JAVA

Enum

  1. An enum specifies a list of constant value asigned to a type.
  2. An enum is not a String or int, an enum constant type is the enum type.
  3. An enum can be declared outside or inside a class, but not in a method.
  4. An enum declared outside a class mus not be marked static, final, abstract, protected or private.
  5. Enums can contain constructors, methods, variables and constant class bodies.
  6. enum constants can send arguments to the enum constructor.
  7. enum constructors can have arguments and can be overloaded.
  8. enum constructors can never been invoked directly in code. They are always called automatically when an enum is initialized.
  9. The semicolon at the end of an enum is optional.
  10. MyEnum.value() return an array of MyEnum’s values.

Read more…

Categories: JAVA
Follow

Get every new post delivered to your Inbox.