Is there any constant in Java? how to declare it?

Recently, I’m been asked by my colleague (C++ programmer) regarding why java does not contains a constant keyword? Actually java do contains constant function , but it just appear as different keyword – final. A final variable in java is equal to C++ constant. The final keyword is declare before a data type, it make …

Read more

Why i choose Hibernate for my project?

Currently my company is using IBATIS and pure SQLs as database persistence mechanism. I like SQL query very much, especially in tuning, but i do not like to write all SQL statement in Java application, it’s easy to hit typo error and what a stupid and tedious job? Finally my company has a new project …

Read more

How to read file in Java – BufferedInputStream

Here is another example to show how to read a file in Java with BufferedInputStream and DataInputStream classes. The readLine() from the type DataInputStream is deprecated. Sun officially announced this method can not convert property from bytes to characters. It’s advised to use BufferedReader. You may interest to read this How to read file from …

Read more

How to read file in Java – BufferedReader

In this article, we will show you how to use java.io.BufferedReader to read content from a file Note Read this different ways read a file 1. Files.newBufferedReader (Java 8) In Java 8, there is a new method Files.newBufferedReader(Paths.get(“file”)) to return a BufferedReader filename.txt A B C D E FileExample1.java package com.mkyong; import java.io.BufferedReader; import java.io.IOException; …

Read more

Java HashMap example

HashMap is an object that stores both key=value as a pair. This HashMap permits null values and the null key, unsynchronized and no guarantees to the order of the map. ["key","value"] = ["java","mkyong.com"] 1. HashMap Basic 1.1 Add an Item Map map = new HashMap<String, String>(); map.put("PostgreSQL", "Free Open Source Enterprise Database"); 1.2 Get an …

Read more

Page Loading Effects with jQuery

JQuery is really a powerful and handy JavaScript library. The page or content loading effect is very easy to implement in jQuery. Here’s a example to make your web page content display a fade in page loading effect. It will make your reader a shock impression. 🙂 The idea is simple ~ 1. Create a …

Read more

PostgreSQL Point-in-time Recovery (Incremental Backup)

PostgreSQL “Point-in-time Recovery” (PITR) also called as incremental database backup , online backup or may be archive backup. The PostgreSQL server records all users’ data modification transaction like insert, update or delete and write it into a file call write-ahead (WAL) log file. This mechanism use the history records stored in WAL file to do …

Read more

JQuery is not working in wordpress – Solution

Since WordPress version 2.x, jQuery is a build-in Javascript library, explicitly include the jQuery library into WordPress is not necessary. Problem The jQuery is not working in WordPress plug-in writing? When you try to test a simple jQuery effect like following $(document).ready(function(){ alert(‘test’); }); It’s just not working, no alert message box pop up. The …

Read more

How to create a Zebra Stripes Table effect using jQuery

This article shows how to create a table with zebra stripes effect using jQuery. Table of contents: 1. Include the jQuery script 2. CSS styling the zebra stripes 3. Table Structure 4. jQuery Script 5. Full example 6. References P.S Tested with jQuery 3.7.1 1. Include the jQuery script Include the jQuery script from the …

Read more

JavaScript vs jQuery function calling examples

This article shows different function calling in both JavaScript and jQuery. At the end, we will show an example of how to call a function to create dynamic content after a page is loaded, both in JavaScript and jQuery. Table of contents: 1. JavaScript Function Calling 2. jQuery Function Calling 3. JavaScript – Function calling …

Read more

jQuery Hello World Example

jQuery is a fast, small, and feature-rich JavaScript library. It simplifies HTML document traversal and manipulation, event handling, and animation with an easy-to-use API that works across browsers. This article shows how to load a jQuery script and change the text of a div element to Hello World when the document is ready. P.S Tested …

Read more

Tomcat – java.lang.OutOfMemoryError: PermGen space

Often time, Tomcat may hits the following java.lang.OutOfMemoryError: PermGen space error. java.lang.OutOfMemoryError: PermGen space at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:620) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) It’s usually happened after the Tomcat restarts a few times. 1. Solution By default, Tomcat is assigned a very little PermGen memory for the running process. To fix it, increase the PermGen memory settings …

Read more

How to set / change default page in Apache

Here i will show how to set or change default page in Apache. Apache default page is very easy to configure, we just need to configure Apache conf file in following location Apache file path/conf/httpd.conf Make the following changes in httpd.conf file. Change index.html or index.php to whatever default page you want. # # DirectoryIndex: …

Read more

Adapter Design Pattern

Adapter , Adapter , Adapter ~ Actually Adapter design pattern can consider as a simple conversion program / class. It usually used to make two incompatible interfaces or classes to work together. Please review below Adapter design pattern image draw by me, a bit ugly 🙂 Case Study Company A developed a program in Java …

Read more

How to set static IP address on Unix

In Unix system like Debian, Ubuntu or Red Hat, It is possible to set a static IP address with ifconfig command. My current Debian system IP address is 10.70.0.61 mkyong:~# ifconfig eth0 Link encap:Ethernet HWaddr 00:15:17:1D:CE:2F inet addr:10.70.0.61 Bcast:10.70.3.255 Mask:255.255.252.0 I want change it to 10.70.0.66, just issue following command to set a static IP …

Read more

How to kill / terminate PostgreSQL hang query

Today, i found out that one of the SQL query is hanging in PostgreSQL, and never release itself. “Cancel query” command won’t help, and the query just hanging there and show an “idle in transaction” status. It left me no choice but go Debian terminal to issue “kill” command to terminate it manually. Query hanging …

Read more

Html Font Tutorial

According to World Wide Web Consortium (W3C), the tag in HTML is deprecated. It is removed in a from its recommendations.W3C encourage to use style sheets (CSS) to define the layout and display properties of HTML elements. However there still a lot of people using it, it still worth to mention a while here. Font …

Read more

Html Color Tutorial

Life is full of colors, so does HTML ~ Color formula as below RED + GREEN + BLUE = COLOR Colors are displayed combining RED, GREEN, and BLUE. Usually we can change html font color in two ways 1) Use Color Name Red Color Red Color 2) Use Hex code (#) Red Color Red Color …

Read more

TO_DATE function between PostgreSQL 8.2 and 8.3

As we all know PostgreSQL 8.3 make very strong checking on data type, it make a lot application hit many data type error after migration from PostgreSQL8.x to PostgreSQL8.3. Mostly is cause by data type checking. One of the common error is to_date() function. It accept two text as parameters. to_date(text,text) Ok now i create …

Read more

Spring AOP Interceptor transaction is not working

Problem The Spring AOP transaction is not working in following interceptors? <bean id="testAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="interceptorNames"> <list> <idref bean="urlInterceptorInsert" /> <idref bean="urlInterceptorCommit" /> <idref bean="urlInterceptorRelease" /> <idref bean="matchGenericTxInterceptor" /> </list> </property> <property name="beanNames"> <list> <idref local="urlBo" /> </list> </property> </bean> The “matchGenericTxInterceptor” transaction interceptor, suppose to intercept urlInterceptorInsert, urlInterceptorCommit,urlInterceptorRelease, but it’s not work as expected? …

Read more

PostgreSQL – How to change default schema

“public” is PostgreSQL default scheme, i have to change it because i had migrated a new database data into another new schema call “new_public”. Before start to change, i have to check what is current PostgreSQL default schema? 1) Command SHOW search_path 2) Check postgresql.conf #————————————————————————— # CLIENT CONNECTION DEFAULTS #————————————————————————— # – Statement Behavior …

Read more

How to check Linux / Unix distribution version

Today my boss ask me install a tomcat in linux machine. After i ssh into that machine, i wonder what is the Linux distribution version? Red Hat? Ubuntu? Fedora? Debian? However with a simple command, i can check what is linux distribution version mymachine:~# cat /proc/version Linux version 2.6.18-5-686-bigmem (Debian 2.6.18.dfsg.1-13etch3) ([email protected]) (gcc version 4.1.2 …

Read more

How to get random row from sql query – PostgreSQL

How can i get a random row from a query result in PostgreSQL? The answer is easy, just using RANDOM() built-in function in PostgreSQL SELECT scoreid FROM n_score ORDER BY RANDOM() limit 1; Above example will get a random score id from table n_score. Everytime execute it will get a random score id. Done.

How to Enable Mouse Wheel Scrolling in Ubuntu (VMware)

Problem Ubuntu…beside Default VI is suck, here is another issue for me. My mouse wheel scrolling is not working in Ubuntu8.04. However i installed Ubuntu in vmware, but i do not think it is vmware cause of this issue. Solution Here i find some useful information regarding Mouse Wheel Scrolling malfunction issuse, please check Ubuntu …

Read more

Convert Subquery Result to Array

I want my subquery results (multi rows) return as a singale row in my query. For example. select u.url, (select c.categoryid from category c where c.categoryid = u.categoryid) from url u If url contains multiple categories, subquery will return multiple rows as following P.S Subquery return multiple rows is not supported in most of the …

Read more

JavaScript – How to disable right click button on a website

Many webmasters like to disable the right click button to protect their own content. Here is the JavaScript to disable right click button on a website : <script> <!– //edit this message to say what you want var message = "Function Disabled"; function clickIE() { if (document.all) { alert(message); return false; } } function clickNS(e) …

Read more

Java Web Start (Jnlp) Tutorial

Here is a brief explanation about Java Web Start from SUN “Java Web Start is a mechanism for program delivery through a standard Web server. Typically initiated through the browser, these programs are deployed to the client and executed outside the scope of the browser. Once deployed, the programs do not need to be downloaded …

Read more

How to install Tomcat on Ubuntu

This tutorial shows you how to install Tomcat on Ubuntu, with help of the buith-in apt-get command. 1. apt-get install 1.1 Find an available Tomcat package to install $ sudo apt-cache search tomcat //… tomcat7 – Servlet and JSP engine tomcat7-admin – Servlet and JSP engine — admin web applications tomcat7-common – Servlet and JSP …

Read more

Tomcat – java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)

Problem As i said in previously post, Tomcat 5.5.25 made a lot of modification in policy file, which may enhance security on web application but it also causing a lot of problem, see another error message : SEVERE: Context initialization failed java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers) at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323) Solution Policy file issue, vi 04webapps.policy, this …

Read more

How to check Tomcat version Installed

To find out the Tomcat version, find this file – version.sh for *nix or version.bat for Windows. This version.sh file is normally located in the Tomcat bin folder. For example : mkyong@hcompass:/usr/share/tomcat7/bin$ ./version.sh Using CATALINA_BASE: /usr/share/tomcat7 Using CATALINA_HOME: /usr/share/tomcat7 Using CATALINA_TMPDIR: /usr/share/tomcat7/temp Using JRE_HOME: /usr Using CLASSPATH: /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar Server version: Apache Tomcat/7.0.28 Server built: Apr …

Read more

Tomcat – java.security.AccessControlException: access denied (logging.properties read)

Problem After upgraded to Tomcat version 5.5.25, it starting to hit a lot of errors in security policy : Caused by: java.security.AccessControlException: access denied (java.io.FilePermission /usr/share/tomcat5.5- webapps/jsp-examples/WEB-INF/classes/logging.properties read) Solution Above error is caused by the Tomcat’s policy file, Tomcat 5.5.25 made a lot of modification on policy file. To fix it, you need to make …

Read more

What is Tomcat default administrator password ?

Is there or what is the default administrator user and password for Tomcat? Tested : Tomcat 8.0.30 Tomcat 7.0.67 Tomcat 6.0.44 Article update history Updated 03/02/2016 : Add support for Tomcat 7 and 8. Updated 08/04/2011 : Update article. 1. Tomcat 7 and Tomcat 8 Tomcat users are defined in the file – $TOMCAT_HOME/conf/tomcat-users.xml, by …

Read more