Installing Sun Java JDK in CentOS is not as easy as I expected.
Download the Sun Java JDK from the Java SE Downloads page.
Using your root account, or the sudo command, run the jdk-7u51-linux-x64.rpm (chmod it if necessary). This will install Java packages.
If jdk sun installation failed, try to command: rpm –i –force jdk-7u51-linux-x64.rpm
Type java -version. In my case, it show OpenJdk info instead of Sun one.
For selecting the java command, we can use the alternatives program. Use:
/usr/sbin/alternatives –install /usr/bin/java java /usr/java/jdk1.7.0_51/bin/java 2
Now run
/usr/sbin/alternatives –config java
and select option 2.
Running java -version now should show Sun JVM info.
Remember that maybe you want to do the same with javac and other Java commands.