Time in 24-Hour Format Regular Expression Pattern ([01]?[0-9]|2[0-3]):[0-5][0-9] Description ( #start of group #1 [01]?[0-9] # start with 0-9,1-9,00-09,10-19 | # or 2[0-3] # start with 20-23 ) #end of group #1 : # follow by a semi colon (:) [0-5][0-9] # follw by 0..5 and 0..9, which means 00 to 59 The 24-hour clock […]

Read more How to validate Time in 24 Hours format with regular expression

Time in 12-Hour Format Regular Expression Pattern (1[012]|[1-9]):[0-5][0-9](\\s)?(?i)(am|pm) Description ( #start of group #1 1[012] # start with 10, 11, 12 | # or [1-9] # start with 1,2,…9 ) #end of group #1 : # follow by a semi colon (:) [0-5][0-9] # follw by 0..5 and 0..9, which means 00 to 59 (\\s)? […]

Read more How to validate Time in 12 Hours format with regular expression

This article focus on how to validate an IP address (IPv4) using regex and Apache Commons Validator. Here is the summary. IPv4 regex explanation. Java IPv4 validator, using regex. Java IPv4 validator, using commons-validator-1.7 JUnit 5 unit tests for the above IPv4 validators. IPv4 regex final version. ^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.(?!$)|$)){4}$ # Explanation ( [0-9] # 0-9 | […]

Read more Java IP Address (IPv4) regex examples

Image File Extension Regular Expression Pattern ([^\s]+(\.(?i)(jpg|png|gif|bmp))$) Description ( #Start of the group #1 [^\s]+ # must contains one or more anything (except white space) ( # start of the group #2 \. # follow by a dot "." (?i) # ignore the case sensive checking for the following characters ( # start of the […]

Read more How to validate image file extension with regular expression

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 convert Java source code to HTML page

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 How to determining whether Apache is already installed?

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 Apache error – (13)Permission denied: make_sock: could not bind to address

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 restart apache services in unix?

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 How to install Apache Http server on Ubuntu

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 Java – Create file checksum with SHA and MD5

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 byte[] to BufferedImage 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 How to convert BufferedImage to byte[] in Java

Today, i received an email, subject as “Account Review Department” from PayPal ([email protected]). This email said my Paypal account is limited access due to some fault credit card cases, request download the attached form and open in my browser to restore my Paypal password. It’s just a funny email, how can i trust an email […]

Read more Beware of Email – Paypal Account Review Department

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 How to send email in Python via SMTPLIB

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 HTML Elements

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 Top 5 Strongest Password

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 Tomcat Error – prunsrv.c Failed creating java (jvm.dll)

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 MySQL Error – exceeded the ‘max_questions’ resource (current value: 1000)

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 How to modify the ‘max_questions’ resource value in MySQL?

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 Connect to MySQL with JDBC driver

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 org.hibernate.AnnotationException: Unknown Id.generator

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 PhP file display as downloading instead of interpreted by Apache

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 How to download a website in Linux (wget)