Thursday, June 13, 2013

Eager and Lazy Loading


The JVM must be able to load JVM class files. The JVM class loader loads referenced JVM classes that have not already been linked to the runtime system. Classes are loaded implicitly because:

  • The initial class file - the class file containing the public static void main(String args[]) method - must be loaded at startup.
  • Depending on the class policy adopted by the JVM, classes referenced by this initial class can be loaded in either a lazy or eager manner.

An eager class loader loads all the classes comprising the application code at startup. 

Lazy class loaders wait until the first active use of a class before loading and linking its class file.

The first active use of a class occurs when one of the following occurs:
  • An instance of that class is created
  • An instance of one of its subclasses is initialized
  • One of its static fields is initialized

Certain classes, such as ClassNotFoundException, are loaded implicitly by the JVM to support execution. You may also load classes explicitly using thejava.lang.Class.forName() method in the Java™ API, or through the creation of a user class loader.


Friday, June 29, 2012

Communicate with Multiple USB / Serial Port


When requirement will come to listen more than one USB / Serial Port in Java, make some changes in Java/jdk/jre/lib/javax.comm.properties file. By default the Application will listen only one port at a time but after make the changes simultaneously it'll listen multiple ports. changes need to be done: open the above mentioned file add the following line in particular section # Paths to server-side serial port devices serpath0 = /dev/ttyS0 #added.... serpath1 = /dev/ttyS1 serpath2 = /dev/ttyACM0 serpath3 = /dev/ttyACM1

Friday, May 18, 2012

Low Graphic Mode Error in Ubuntu



If the low graphic mode error comes in Ubuntu:
sudo apt-get update
sudo apt-get -d install --reinstall gdm
sudo apt-get remove --purge gdm
sudo apt-get install gdm
sudo apt-get install Ubuntu-desktop
sudo dpkg-reconfigure -phigh xserver-xorg
sudo reboot

how to start the wireless internet if the machine run in low graphic mode
when the GUI is unable to load press ALT+F2 key and open other terminal
login with credentials
type startx
type iwlist scan (for searching the network, if wireless is down then type sudo ifconfig up)
for registering with network type iwconfig essid (like interface=>ra0  essid=>“MyNetwork”).
If the above command not work then type nm-applet

Sunday, April 15, 2012

Set the Java_Home and Maven M2_HOME

Write the below line in /etc/bash.bashrc

// user jdk path
JAVA_HOME=/home/test/java/jdk1.6.0_30
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH
PATH=$PATH:JAVA_HOME

//user maven path (expecting extract in /usr/local/apache-maven/)
M2_HOME=/usr/local/apache-maven/apache-maven-3.0.4
export M2_HOME
M2=$M2_HOME/bin
export PATH=$M2:$PATH

Monday, February 14, 2011

Find Files By Access, Modification Date / Time Under Linux or UNIX

I don't remember where I saved pdf and text files under Linux. I have downloaded files from the Internet a few months ago. How do I find my pdf or text files?

You need to use the find command. Each file has three time stamps, which record the last time that certain operations were performed on the file:

[a] access (read the file's contents) - atime

[b] change the status (modify the file or its attributes) - ctime

[c] modify (change the file's contents) - mtime

You can search for files whose time stamps are within a certain age range, or compare them to other time stamps.

You can use -mtime option. It returns list of file if the file was last accessed N*24 hours ago. For example to find file in last 2 months (60 days) you need to use -mtime +60 option.

-mtime +60 means you are looking for a file modified 60 days ago.
-mtime -60 means less than 60 days.
-mtime 60 If you skip + or - it means exactly 60 days.
So to find text files that were last modified 60 days ago, use
$ find /home/you -iname "*.txt" -mtime -60 -print

Display content of file on screen that were last modified 60 days ago, use
$ find /home/you -iname "*.txt" -mtime -60 -exec cat {} \;

Count total number of files using wc command
$ find /home/you -iname "*.txt" -mtime -60 | wc -l

You can also use access time to find out pdf files. Following command will print the list of all pdf file that were accessed in last 60 days:
$ find /home/you -iname "*.pdf" -atime -60 -type -f

List all mp3s that were accessed exactly 10 days ago:
$ find /home/you -iname "*.mp3" -atime 10 -type -f

There is also an option called -daystart. It measure times from the beginning of today rather than from 24 hours ago. So, to list the all mp3s in your home directory that were accessed yesterday, type the command
$ find /home/you -iname "*.mp3" -daystart -type f -mtime 1

Where,

-type f - Only search for files and not directories
-daystart option

The -daystart option is used to measure time from the beginning of the current day instead of 24 hours ago. Find out all perl (*.pl) file modified yesterday, enter:

find /nas/projects/mgmt/scripts/perl -mtime 1 -daystart -iname "*.pl"
You can also list perl files that were modified 8-10 days ago, enter:
To list all of the files in your home directory tree that were modified from two to four days ago, type:

find /nas/projects/mgmt/scripts/perl -mtime 8 -mtime -10 -daystart -iname "*.pl"
-newer option

To find files in the /nas/images directory tree that are newer than the file /tmp/foo file, enter:

find /etc -newer /tmp/foo
You can use the touch command to set date timestamp you would like to search for, and then use -newer option as follows

touch --date "2010-01-05" /tmp/foo
# Find files newer than 2010/Jan/05, in /data/images
find /data/images -newer /tmp/foo

Monday, December 6, 2010

instance of in JAVA

Sometimes, knowing the type of an object during run time is useful. For example, you might have one thread of execution that generates various types of objects, and another thread that processes these objects. In this situation, it might be useful for the processing thread to know the type of each object when it receives it. Another situation in which knowledge of an object's type at run time is important involves casting. In Java, an invalid cast causes a run-time error. Many invalid casts can be caught at compile time. However, casts involving class hierarchies can produce invalid casts that can be detected only at run time. For example, a superclass called A can produce two subclasses, called B and C. Thus, casting a B object into type A or casting a C object into type A is legal, but casting a B object into type C (or vice versa) isn't legal. Because an object of type A can refer to objects of either B or C, how can you know, at run time, what type of object is actually being referred to before attempting the cast to type C? It could be an object of type A, B, or C. If it is an object of type B, a run-time exception will be thrown. Java provides the run-time operator instanceof to answer this question.
The instanceof operator has this general form:

object instanceof type

Here, object is an instance of a class, and type is a class type. If object is of the specified type or can be cast into the specified type, then the instanceof operator evaluates to true. Otherwise, its result is false. Thus, instanceof is the means by which your program can obtain run-time type information about an object.

The following program demonstrates instanceof:

// Demonstrate instanceof operator.
class A {
int i, j;
}
class B {
int i, j;
}
class C extends A {
int k;
}
class D extends A {
int k;
}
class InstanceOf {
public static void main(String args[]) {
A a = new A();
B b = new B();
C c = new C();
D d = new D();
if(a instanceof A)
System.out.println("a is instance of A");
if(b instanceof B)
System.out.println("b is instance of B");
if(c instanceof C)
System.out.println("c is instance of C");
if(c instanceof A)
System.out.println("c can be cast to A");
if(a instanceof C)
System.out.println("a can be cast to C");
System.out.println();
// compare types of derived types
A ob;
ob = d; // A reference to d
System.out.println("ob now refers to d");
if(ob instanceof D)
System.out.println("ob is instance of D");
System.out.println();
ob = c; // A reference to c
System.out.println("ob now refers to c");
if(ob instanceof D)
System.out.println("ob can be cast to D");
else
System.out.println("ob cannot be cast to D");
if(ob instanceof A)
System.out.println("ob can be cast to A");
- 230 -
System.out.println();
// all objects can be cast to Object
if(a instanceof Object)
System.out.println("a may be cast to Object");
if(b instanceof Object)
System.out.println("b may be cast to Object");
if(c instanceof Object)
System.out.println("c may be cast to Object");
if(d instanceof Object)
System.out.println("d may be cast to Object");
}
}

The output from this program is shown here:

a is instance of A
b is instance of B
c is instance of C
c can be cast to A
ob now refers to d
ob is instance of D
ob now refers to c
ob cannot be cast to D
ob can be cast to A
a may be cast to Object
b may be cast to Object
c may be cast to Object
d may be cast to Object

The instanceof operator isn't needed by most programs, because, generally, you know the type of object with which you are working. However, it can be very useful when you're writing generalized routines that operate on objects of a complex class hierarchy

Private final methods

If one class have one private final method so what happen if another class is try to overridden the same method in another class:
for reference check the below example

class Raptor{
private final void test(){
System.out.println("i am final of Raptor");
}
}

class Hawk extends Raptor {
public final void test(){
System.out.println("i am the final of Hawk");
}

public static void main(String[] args) {
Hawk hawk_obj = new Hawk();
hawk_obj.test();
}
}

Result:
compile and program may run the output is "i am the final of Hawk", because the test function is private and it'll never available in another class so the final method never be override in another class rule is not applicable.