Java email regex examples

The format of an email address is local-part@domain. Look at this email address [email protected] local-part = mkyong @ = @ domain = example.com The formal definitions of an email address are in RFC 5322 and RFC 3696. However, this article will not follow the above RFC for email validation. The official email "local-part" is too …

Read more

How to convert Java source code to HTML page

Java2HTML is a tool to converts Java source code into a colorized and browsable HTML page, and the steps are quite straight forward. Steps to convert it 1) Download Java2HTML – http://www.java2html.com/download.html 2) Unzip it , e.g “D:\Java2HTML” 3) Edit the “j2h.bat” file and modify the CLASSPATH variable. Make sure it point to the correct …

Read more

How to determining whether Apache is already installed?

If you are running Linux system, high chance Apache is already installed by default. In case, you can use the following commands to determining whether Apache is already installed. In RPM system like Fedora Core Issue httpd -v or /usr/sbin/httpd -v [root@snake init.d]# httpd -v Server version: Apache/2.2.11 (Unix) Server built: Mar 6 2009 09:12:25 …

Read more

Apache error – (13)Permission denied: make_sock: could not bind to address

I hit the Apache server error (13)Permission denied: make_sock in my console, while i try to start the Apache http server with the ./apache2 start script under init.d folder. mkyong@mkyong-desktop:/etc/init.d$ ./apache2 start * Starting web server apache2 apache2: Could not reliably determine the server fully qualified domain name, using 127.0.0.1 for ServerName (13)Permission denied: make_sock: …

Read more

How to restart apache services in unix?

Often times, as server administrator, have to telnet or SSH to their server to restart the Apache Http services. The Apache http services are usually located at the following location, 1) init.d start script folder. issue “./apache restart” to restart it debian:/etc/init.d# ./apache restart Forcing reload of web server (apache)… waiting . debian:/etc/init.d# 2) usr/local/apache/bin …

Read more

How to install Apache Http server in Windows

Installing Apache Http server in Windows is more easier than Linux. See my following posts for installing Apache http server in Linux system 1) How to install Apache Http server in Fedora Core 2) How to install Apache Http server in Ubuntu The steps are quite straight forward, download the binary installation and install it. …

Read more

How to install Apache Http server in Fedora Core

There are two ways to install Apache Http server in Fedora Core, either with yum command to install automatically and manual install it by compiling the source. Steps to install automatically 1) Search Apache package with yum search command yum search httpd P.S Apache http server in fedora is called httpd 2) Get the Apache …

Read more

How to install Apache Http server on Ubuntu

There is two ways to install Apache Http server on Ubuntu : Use apt command to install it automatically. Configure and build the source code, and install it manually. 1. Install it automatically 1. Search Apache package with “apt-cache search” command apt-cache search apache 2. Get Apache package name “apache2”, issue the “apt-get” install command. …

Read more

Java – Create file checksum with SHA and MD5

In this article, we will show you how to use a SHA-256 and MD5 algorithm to generate a checksum for a file. MessageDigest.getInstance(“algorithm”) Apache Commons Codec 1. MessageDigest d:\server.log hello world 1.1 Generate a file checksum with a SHA256 algorithm. FileCheckSumSHA.java package com.mkyong.hashing; import java.io.FileInputStream; import java.io.IOException; import java.security.DigestInputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class …

Read more

How to convert byte[] to BufferedImage in Java

This article shows how to convert a byte[] to a BufferedImage in Java. InputStream is = new ByteArrayInputStream(bytes); BufferedImage bi = ImageIO.read(is); The idea is puts the byte[] into an ByteArrayInputStream object, and we can use ImageIO.read to convert it to a BufferedImage. 1. Convert byte[] to BufferedImage. The below example shows how to convert …

Read more

How to convert BufferedImage to byte[] in Java

This article shows how to convert a BufferedImage to a byte array or byte[]. BufferedImage bi = ImageIO.read(new File("c:\\image\\mypic.jpg")); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(bi, "jpg", baos); byte[] bytes = baos.toByteArray(); The idea is uses the ImageIO.write to write the BufferedImage object into a ByteArrayOutputStream object, and we can get the byte[] from the ByteArrayOutputStream. …

Read more

Adsense Daemon WordPress Plugin

Adsense Daemon is a WordPress plugin that is used to integrate “Google Adsense” into blog content easily. I had used few Google Adsense WordPress plugins, and found out many of those will hijack and replace my Google Adsense code with theirs. This inspired me to create this simplest solution to integrate Google Adsense into blog …

Read more

How to send email in Python via SMTPLIB

Here is an email example written in Python module “smtplib”. It will connect to the GMail SMTP server and do the authentication with username and password given (hardcoded in program), and use the GMail SMTP server to send email to the recipient. import smtplib to = ‘[email protected]’ gmail_user = ‘[email protected]’ gmail_pwd = ‘yourpassword’ smtpserver = …

Read more

HTML Elements

As simple, HTML documents are simply a text file made up of many HTML elements. These HTML elements are always between a start tag and end tag. Where the element appears is determined by the order in which the tags appear. HTML Elements An HTML element is everything from the start tag to the end …

Read more

How to clear / delete recent document history?

Windows store all the documents , images or files you have recently opened in “Recent Documents Folder” . Sometime it’s a handy function to access your recent document, but it also raise out a serious privacy issue, because anyone who has access to your computer can know what files you’ve opened recently. How to clear …

Read more

Top 5 Strongest Password

Many users are cracked because of their poor password structure, here i summarize 5 of the strongest password that i know. Hope this help. 5. Combine partial unrelated words together Combine partial 2 or 3 or even 4 unrelated words together (mix uppercase and lowercase), for example, combine these words together like “Diamond”, “Blog”,”Security” to …

Read more

Tomcat Error – prunsrv.c Failed creating java (jvm.dll)

I had encountered following error message while starting my Tomcat server. [2009-01-16 11:22:19] [1343 prunsrv.c] [debug] Procrun log initialized [2009-01-16 11:22:19] [info] Procrun (2.0.4.0) started [2009-01-16 11:22:19] [info] Running Service… [2009-01-16 11:22:19] [1166 prunsrv.c] [debug] Inside ServiceMain… [2009-01-16 11:22:19] [info] Starting service… … [error] The specified module could not be found. [2009-01-16 11:22:19] [994 prunsrv.c] …

Read more

How to Generate an unique ID in Java

Example UUID is the fastest and easiest way to generate unique ID in Java. import java.util.UUID; public class UniqueIDTest { public static void main(String[] args) { UUID uniqueKey = UUID.randomUUID(); System.out.println (uniqueKey); } } Result 0a6a3de7-b974-42d0-af9e-9c23473b09b9

How to calculate the MySQL database size

As i know, there are two ways to calculate MySQL database size. 1. SQL script Sum up the data_length + index_length is equal to the total table size. data_length – store the real data. index_length – store the table index. Here’s the SQL script to list out the entire databases size SELECT table_schema "Data Base …

Read more

MySQL Error – exceeded the ‘max_questions’ resource (current value: 1000)

While i using my little fancy program to simulate millions of data in MySQL database for volumn testing, my program straight hit the following error after execute few seconds. Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: User ‘mkyong’ has exceeded the ‘max_questions’ resource (current value: 1000) at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) at com.mysql.jdbc.Util.getInstance(Util.java:381) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3536) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3468) at …

Read more

How to modify the ‘max_questions’ resource value in MySQL?

Often times, the following error is happened. This is due to the MySQL resource monitor feature, the “max_questions” means “Number of queries the user can execute within one hour”. MySQL Error – exceeded the ‘max_questions’ resource (current value: 1000) Here i will demonstrate how to update or modify the ‘max_questions’ value in MySQL. 1) Log …

Read more

Where does MySQL stored the data in my harddisk?

Here i provide a simple user guide to find out where does MySQL database stored the data in our hard disk, both in Windows and Linux. Windows 1) Locate the my.ini, which store in the MySQL installation folder. For Example, C:\Program Files\MySQL\MySQL Server 5.1\my.ini 2) Open the “my.ini” with our favor text editor. #Path to …

Read more

Connect to MySQL with JDBC driver

A JDBC example to show you how to connect to a MySQL database with a JDBC driver. Tested with: Java 8 MySQL 5.7 MySQL JDBC driver mysql-connector-java:8.0.16 1. Download MySQL JDBC Driver Visit https://dev.mysql.com/downloads/connector/j/ to download the latest MySQL JDBC Driver. 2. JDBC Connection 2.1 Make a connection to the MySQL database. JDBCExample.java import java.sql.Connection; …

Read more

org.hibernate.AnnotationException: Unknown Id.generator

Problem Runing the following Hibernate’s annotation sequence generator with PostgreSQL database. @Id @Column(name="user_id", nullable=false) @GeneratedValue(strategy = GenerationType.SEQUENCE ,generator="account_user_id_seq") private Integer userId; Hits the following Unknown Id.generator exception. Caused by: org.hibernate.AnnotationException: Unknown Id.generator: account_user_id_seq at org.hibernate.cfg.BinderHelper.makeIdGenerator(BinderHelper.java:413) at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1795) at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1229) at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:733) The sequence “account_user_id_seq” is created in PostgreSQL database, what caused the above exception? Solution …

Read more

PhP file display as downloading instead of interpreted by Apache

Problem While accessing the PHP file, it display as “application/x-httpd-php” downloading instead of interpreted properly by Apache. See figure below : Solution The PHP downloading issue is caused by the Apache didn’t load the PHP module properly. 1. Find and edit Apache configuration file, which should be able to find at $APACHE_PATH/conf/httpd.conf. 2. Make sure …

Read more

How to download a website in Linux (wget)

The wget is a useful command to download a website in Linux. For example , wget [url]. [mkyong@snake ~]$ wget -r -p -k -E http://www.google.com –2009-07-19 14:07:27– http://www.google.com/ Resolving www.google.com… 64.233.189.104 Connecting to www.google.com|64.233.189.104|:80… connected. HTTP request sent, awaiting response… 302 Found Location: http://www.google.com.my/ [following] –2009-07-19 14:07:27– http://www.google.com.my/ Resolving www.google.com.my… 64.233.189.147 Connecting to www.google.com.my|64.233.189.147|:80… connected. …

Read more

svn+ssh hit Connection closed unexpectedly error in Eclipse – (Solution)

Latest Eclipse IDE is required to support the hibernate tools plug-in. However my “svn+ssh” is not working correctly after updated to the latest Eclipse IDE and Subeclipse version of 1.6.x. While i initial the “svn+ssh” access connection in Eclipse IDE, i had encountered the following error message. Network connection closed unexpectedly svn: Connection closed unexpectedly …

Read more

How to fix Left 4 dead always crashes issue?

While i playing the left 4 dead game after 5 to 20 minutes, it always crashes and return back to Windows. I try to find Left 4 Dead patch file to fix it, but failed, Left 4 dead does not release any patch file for it. To fix Left 4 Dead crashes issue, we need …

Read more

How to check reboots history in Linux

As Unix / Linux server administrator, we always need to know when is our last rebooted date and time. Actually, we are able to list out the system rebooted history by issue following command. last reboot Output mkyong@mkyong:~$ last reboot reboot system boot 2.6.28-11-generi Thu Jul 16 21:42 – 23:46 (02:04) reboot system boot 2.6.28-11-generi …

Read more

How to Limit the application CPU usage in Linux (CPUlimit)

CPULimit is a simple program to limit the CPU usage of certain application in Linux. It’s reside in the Ubuntu repositories by default. We can install it by issue the following command in Ubuntu sudo apt-get install cpulimit Output mkyong@mkyong:~$ sudo apt-get install cpulimit [sudo] password for mkyong: Reading package lists… Done Building dependency tree …

Read more

How to know the Hardware Details in Linux

The “dmidecode” is a handy tool in Linux to display the hardware specification detail. For example, memory, processor , BIOS and etc. man dmidecode DMI TYPES The SMBIOS specification defines the following DMI types: Type Information —————————————- 0 BIOS 1 System 2 Base Board 3 Chassis 4 Processor 5 Memory Controller 6 Memory Module 7 …

Read more