28 May, 2012

Java : JVM Inside. The Story behind JVM. Continue......

In , the previous post , we have discussed some points about JVM in Java platform. Including JVM, java has its own Run time environment(JRE). There are many versions available for JRE, download here.Being byte codes are binary format, Programs intended to run on a JVM must be compiled into a standardized portable binary format, which typically comes in the form of .class files. A program may consist of many classes in different files. For easier distribution of large programs, multiple class files may be packaged together in a .jar (Java Archive file ) file.

The Java application launcher, java, offers a standard way of executing Java code. The JVM runtime executes .class or .jar files, emulating the JVM instruction set by interpreting it, or using a just-in-time compiler (JIT) such as Oracle's HotSpot. JIT compiling, not interpreting, is used in most JVMs today to achieve greater speed. There are also ahead-of-time compilers that enable developers to precompile class files into native code for particular platforms.

Almost virtual machines are similar and the Java virtual machine has a stack-based architecture akin to a microcontroller/microprocessor. However, the JVM also has low-level support for Java-like classes and methods.


JVM have following inside paradigm :- 

1. Bytecode verifier
2. Stack
3. Garbage Collected Heap
4. Method Area


Bytecode Verifier :

It helps to jvm to verifies all bytecode before it is executed. This verification consists basic of three types of checks:-
       1. Branches are always to valid locations
       2. Data is always initialized and references are always type-safe
       3. Access to private or package private data and methods is rigidly controlled.

Stack: 

Stack in Java virtual machine stores various method arguments as well as the local variables of any method. Stack also keep track of each an every method invocation. This is called Stack Frame. There are three registers thats help in stack manipulation. They are vars ( local variable), frame (Execution environment), optop ( Operand Stack ). This registers points to different parts of current Stack.


Method Area:

The byte codes are here. The program counter (PC) points to some byte in the method area. It always keep tracks of the current instruction which is being executed (interpreted). After execution of an instruction, the JVM sets the PC to next instruction ( As we know in ASM language). Method area is shared among all the threads of a process. Hence if more then one threads are accessing any specific method or any instructions, synchorization is needed. Synchronization in JVM is acheived through Monitors (Read this post).

Garbage Collected Heap:

This is one of the main part of java/jvm .This is the place where the objects in Java programs are stored. Whenever we allocate an object using new operator, the heap comes into picture and memory is allocated from there. Unlike C++, Java does not have free operator to free any previously allocated memory. Java does this automatically using Garbage collection mechanism.The garbage collection logic for make memory free and available the resource for more development.

Point to Remember: The local object reference resides on Stack but the actual object resides in Heap only. Also, arrays in Java are objects, hence they also resides in Garbage-collected Heap.



Java: JVM Inside .A story behind JVM.

The word JVM is the core heart of java programming language. It stands for Java Virtual Machine , a simple virtual machine inside your physical computer/system. The virtual refers to not physically it is conceptual.So, it is a virtual machine which can understand byte code.

It is the code execution component of java software platform.A Java virtual machine is software that is implemented on virtual and non-virtual hardware and on standard operating systems. A JVM provides an environment in which Java byte code can be executed, enabling such features as automated exception handling, which provides root-cause debugging information for every software error (exception), independent of the source code. A JVM is distributed along with a set of standard class libraries that implement the Java application programming interface (API). Appropriate APIs bundled together with JVM form the Java Runtime Environment (JRE). 

The term WORA (Write Once and Run Anywhere) make java popular & easy . JVM understand byte code which is the intermediate language between programming and system.The WORA  and   write once, compile anywhere,(WOCA)  which describes cross-platform compiled languages Thus, the JVM is a vital component of the java platform. Typically , we can say JVM makes java platform independent. 


                                                 Java Source File (.java)
                                                                  |
                                                                  |
                                                   Java Compiler ( javac)     
                                                                  |
                                                                  |
                                       Byte code ( .class file, secure code)    
                                        |                         |                         |
                                        |                         |                         |
                                     JVM                   JVM                  JVM
                                       |                          |                         |
                                       |                          |                         |
                                Windows                Linux                   Mac

                                                                                                         Continue to read this in next post

24 May, 2012

MYSQL: Password security problem with mysql Database,Be Aware about secure your Password

Yes , it is true in mysql your password may not secure . It happens with any developer those are using mysql as database. Normally developers are not aware about the password hacking and apply normal query for retrieving  data from database.

Anyone using MySQL on a computer connected to the Internet should read this section to avoid the most common security mistakes.
In discussing security, it is necessary to consider fully protecting your password when login. Commonly we are using such below where clause for comparison for login or validation . But, it is completely not safe.

where binary pass='yourpassword'

But, this above code is not secure and it can be overlapped by using '=' . In place of you password you can use '=' , and see it will hack your password. Your condition is going to true and login success. So, Be careful if you are a responsible developer for your organization.

Your data can be fetch if your condition is '=', it is hacked or checked true. So, follow the process below.

Always use password security mechanism for secure your password.Always follow mysql manual for security before applying security on mysql password.

But when retrive data , you can  use HEX() function from convert it to Hexa decimal format .
As below :

HEX(vchadmin_pass)=HEX('YOur password')

Or use

MD5() other function mentioned below table.


So, Always follow the password security for secure. You can encrypt or decrypt the password when store using the following table :-

AES_DECRYPT()Decrypt using AES
AES_ENCRYPT()Encrypt using AES
COMPRESS()Return result as a binary string
DECODE()Decodes a string encrypted using ENCODE()
DES_DECRYPT()Decrypt a string
DES_ENCRYPT()Encrypt a string
ENCODE()Encode a string
ENCRYPT()Encrypt a string
MD5()Calculate MD5 checksum
OLD_PASSWORD()Return the value of the pre-4.1 implementation of PASSWORD
PASSWORD()Calculate and return a password string
SHA1(), SHA()Calculate an SHA-1 160-bit checksum
SHA2()Calculate an SHA-2 checksum
UNCOMPRESS()Uncompress a string compressed
UNCOMPRESSED_LENGTH()Return the length of a string before compression






23 May, 2012

JAVA: Implementing Singleton design patten for creating single instance with example.

As per the old post related to singleton design patten , here the example of implementation.For implementing the singleton design patten for creating single instance of a class , below one example for better understanding:

//Class with Main function for calling singleton class
public class TestSingleTon {

    /**
     * @param args
     */

    public static void main(String[] args) {
    SingleTonClass classinstance=SingleTonClass.getInstance();
    System.out.println("My SingleTon member value is="+classinstance.testval);
    }

}


//Singleton class 
public class SingleTonClass {

    //create an instance
    private static SingleTonClass my_instance=new SingleTonClass();
   
    private SingleTonClass(){
        //Private Constructor here
        //Not allow to create an object out side
    }
   
    //method to access the instance
    public static SingleTonClass getInstance(){
        return my_instance;
    }
   
    //Member variable
    int testval=10;
   

     //if remove comment from below line , the program will not execute.
    //SingleTonClass s1=new SingleTonClass();
   
}


The output of this program is :-

My SingleTon member value is=10

This is the simple implementation & ensuring one object creation of singleton design patten.Also there are so many other methods are there for implementing signleton ( lazy loading, multiple jvm, etc ).

Thank you
Good Reading.

18 May, 2012

HTML/JAVASCRIPT: Creating a window in Javascript

Some times its an useful job to create a window with a new requirement. But , when we are in development room/area , we always remember any search engine to fine the solutions for any type of problem. Even I , also  following some of the search engine. 

But, it is a fact that I am always try to avoid this type of habits. Be , traceable  for finding any solution. This article is one of the mail memory & also my teaching my myself , that don't guess any coding is normal and easy , so don't remember.


So, below the topic:- code line put inside script tag


window.open('','','left=0,top=0,width=1000,height=780,toolbar=0,scrollbars=0,status=0');orwondow.open();

All parameters are not mandatory  to put with values. If you don't need any scrollbar,toolbar,status bar then you can put 0 as the value here, either put 1. 

17 May, 2012

How to set print area in JSP/HTML page for printer

This is one the interesting topic related to print the specific data from a jsp/html page. Directly to printer, without other browser data. I have done a quite obvious way in javascript for set the print area for printing. I faced this problem in my development team with me, for set a specific area for print.

Caution:-  Use of JavaScript may not be  always acceptable, due to client. If user/client disable the script setting in browser these may not work properly. But, every browsers are support script by default.  

As we know, window. Print() is used for print in JavaScript. There are so many ways to do a printing task in jsp/html page. Out of all I have mentioned 2 process below with advantage & disadvantage.  Put the below function in script area of your page:-

Procedure-1
function setDivPrint(val){
var printdata=document.getElementById('printarea').innerHTML;
var srcOriginalContent=document.body.innerHTML;
document.body.innerHTML=printdata;
window.print();
document.body.innerHTML=srcOrigionalContent;
}
Here ‘printarea ‘ is the id of printable div. It has some limitation, with getting the cancel button click event and some more. I am not mentioning all here. But in procedure-2 is so eminent than procedure-1.

Procedure-2

function setDivPrint(val){
var printdata=document.getElementById('printarea').innerHTML;
var printwindow=window.open('','','left=0,top=0,width=1000,height=780,toolbar=0,scrollbars=0,status=0');
printwindow.document.write(printdata);
printwindow.document.close();
printwindow.focus();
printwindow.print();
printwindow.close();
}

Here ‘printarea ‘ is the id of printable div. .This method is recommended to use. In this method no need to get the cancel or print button event. Suppose the user click on cancel, then the main original page should come, but it may not coming with the Procedure-1 . So, No need to face this problem in Procedure-2.

03 May, 2012

Manoj.Blog: MYSQL: Daily auto backup of database for windows o...

Manoj.Blog: MYSQL: Daily auto backup of database for windows o...: Quite simple , because you have read the older pos t for creating backup  (dump) . But, here the process of automatic backup the mysql data...

MYSQL: Daily auto backup of database for windows or Scheduled backup

Quite simple , because you have read the older post for creating backup  (dump) . But, here the process of automatic backup the mysql database in a particular time in your local system. This may not run your remote system.

Steps for create a schedule for back :-

 Step 1- Create a batch file with the command mysqldump and necessary options that mentioned in the old post .

Step 2- Goto Start => All program => Accessories => System Tool => Scheduled Task

Step 3- Then create a new schedule with given batch file and scheduled date & time.




Now ,  wait for the given scheduled  time and see the backup file is created in the destination directory .






Manoj.Blog: MYSQL:How to create MySql Dumps using batch file ...

Manoj.Blog: MYSQL:How to create MySql Dumps using batch file ...: Manoj.Blog: MYSQL:How to create MySql Dumps using batch file ... : Too much ,, really in MYSQL finding complete solution like oracle & sql ...

02 May, 2012

MYSQL:How to create MySql Dumps using batch file ...

Manoj.Blog: MYSQL:How to create MySql Dumps using batch file ...: Too much ,, really in MYSQL finding complete solution like oracle & sql server is too difficult. That I have faced so many times with my d...

MYSQL:How to create MySql Dumps using batch file (WINDOWS)


Too much ,, really in MYSQL finding complete solution like oracle & sql server is too difficult. That I have faced so many times with my development team. One of my colleague asked about the dumps creation using batch file. Really I searches many sites on internet with unexpected   results. Taking dumps using command line I have already post on my blog , but in this case I need a batch file for execution. And finally when I prepare it for serve , I was really happy and now I am sharing this happiness with all my visitors .  Below the code inside the batch file :-

cd "c:\Program Files\MySQL\MySQL Server 5.0\bin\"
mysqldump -hyourIPaddress -uyour_user_name -pyour_password yourdbname > d:\output_backup.sql
exit


Now create a batch file and paste the code above with host,username, password,database name and output file name for store data.

Example 1:-
cd "c:\Program Files\MySQL\MySQL Server 5.0\bin\"
mysqldump -hlocalhost -uroot -proot manojdb > d:\mybackupdumps.sql
exit

If you want to take all database backup/dumps you can also do by following code :-

cd "c:\Program Files\MySQL\MySQL Server 5.0\bin\"
mysqldump -hlocalhost -umyuname -pmypassword --all-databases > d:\myalldatabasedumps.sql
exit


MYSQL Reference manual provides so many options for using with mysqldump . Some of the most useful are below :-


--add-locks  is used for    Surround each table dump with LOCK TABLES and UNLOCK TABLES statements.

 --all-databases  is used for Dump all tables in all databases.
  
 --comments  is used for Add comments to the dump file.

--compact is used for produce more compact out put .

--ignore-table=db_name.tbl_name is used for Do not dump the given table



You can also follow mysql reference manual for dumps creation  by Click Here. 



Hope it will help you.
Ping me always.

Manoj.Blog: MYSQL: Create database dump from command line (WIN...

Manoj.Blog: MYSQL: Create database dump from command line (WIN...: Hi Readers, Really in MYSQL/WINDOW, I have many obstacles and searches internet more than 7-8 hour for create a dump file of my database...

MYSQL: Create database dump from command line (WINDOWS)

Hi Readers,


Really in MYSQL/WINDOW, I have many obstacles and searches internet more than 7-8 hour for create a dump file of my database with compatible for all mysql db engines. And finally I fry some thing below: -

Steps-1 Go to your MYSQL installed directory inside bin
              C:\Program Files\MySQL\MySQL Server 5.0\bin
Steps-2 Use mysqldump command for create the backup.
              mysqldump -uyour_username -pyour_password your_databasename > D:\mybackup.sql

Steps-3 Press Enter


Now check your D drive and find the mybackup.sql file.


Hope it will help you.
Ping me always.

25 April, 2012

Manoj.Blog: HTML Marquee : set Stop and Play on mouse over an...

Manoj.Blog: HTML Marquee : set Stop and Play on mouse over an...: Hello readers, As you  marquee  can create a scrolling preview. But when we need to make some operation like mouse over ,mouse out etc. S...

HTML Marquee : set Stop and Play on mouse over and mouse out

Hello readers,

As you  marquee  can create a scrolling preview. But when we need to make some operation like mouse over ,mouse out etc. Stop & play of marque like below:-


<marquee  onmouseover="this.setAttribute('scrollamount',0,0);" onmouseout="this.setAttribute('scrollamount',6,0);">
<a  style="color: #FF0000" href="#" title="Notice">New notice for Marquee readers</a>
</marquee>


This above code will help you for stop and play on mouse over and mouse out respectively.


Hope it will help you.
Thankx

20 April, 2012

Manoj.Blog: Java : Get Last inserted ID (Auto Increment) from...

Manoj.Blog: Java : Get Last inserted ID (Auto Increment) from...: Really I faced lot of questions & problems related to this topic , basically when we are using mysql as the backend. But its quite obvious ...

Java : Get Last inserted ID (Auto Increment) from Database Query

Really I faced lot of questions & problems related to this topic , basically when we are using mysql as the backend. But its quite obvious & simple for find the last inserted record id (Auto increment ) and primary key also from an insert query ( Not from a procedure). I am not using callable statement for achieve this task. Simple directly by query :-

You can retrive value by using:-

1. select last_insert_id()
2. RETURN_GENERATED_KEYS


Follow the example below:-


String query="insert into m_time_list(vchTime,vchGMT,createdDate) values('"+form.getTxtTime()+"','"+form.getRdbgmt()+"',curdate())";
            pstmt=connection.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);
            sts=pstmt.executeUpdate();   
            rs=pstmt.getGeneratedKeys();
            int sid=0;
            while(rs.next()){
                sid=rs.getInt(1);
            }

Now , Sid contains the return inserted ID.



Hope it will help you.
Ping me:
javadevelopersguide@blogspot.com


08 April, 2012

Manoj.Blog: Javascript : Password Validation with Regular expr...

Manoj.Blog: Javascript : Password Validation with Regular expr...: Hi viewers, This topic - Password Validation with Regular expression. Its a daily process for web developers to validating the passwo...

Manoj.Blog: FACEBOOK Link Integration to your Website. Share D...

Manoj.Blog: FACEBOOK Link Integration to your Website. Share D...: Copy the below given code inside your Html Page Tag and enjoy the facebook share plugin. <a name="fb_share" type="button"  share_...

How to validate Password with Regular expression.

In Today article,  we will see how to validate password with Regular expressionIts a daily process for web developers to validating the password with certain rules.With java script client side validate can be achieved. Below the code will help you to validate the password which contain at least one Letter , one Number & one special character. The password length must be within a given range.



/* Password must be at least one char, one special char & one digit & the length must be given*/
function validatePassword(pwdelem,alertmsg){
    var password_expression=/^((?=.*[a-zA-Z])(?=.*\d)(?=.*[#@%$]).{6,20})$/;
    if(pwdelem.value.match(password_expression)){
        return true;
    }
    else{
        alert(alertmsg);
        pwdelem.focus(); //Set focus to the given source element id ( textbox or password) ,it is optional .
        return false;
    }
}