Category: Cross-Platform

Cross-Platform, Java

Capture screen shot in Java

It’s really easy to capture screen shots using java code. Let’s see how: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 package screenshot;   import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO;   public class Screenshot { public static void main(String[] args) …

Cross-Platform, PHP

Simple AES Encryption with PHP

Today we will see how we can use mcrypt_encrypt PHP function to encrypt a plain text using AES 128! 1 2 3 4 5 6 7 8 function encrypt($plaintext, $key) { $crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, MCRYPT_MODE_ECB); return base64_encode($crypt); }function encrypt($plaintext, $key) { $crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, MCRYPT_MODE_ECB); return base64_encode($crypt); } Usage: $cipher_text = …

Cross-Platform, Java

Creating a simple Web Service in Java

Create a web service application project in Netbeans. Create a class named Customers. In this class we will declare the methods that our service will provide to clients. 1 2 3 4 5 6 7 8 9 10 11 12 13 import javax.jws.WebMethod; import javax.jws.WebService;   @WebService public class Customers {   public Customers(){}   …

Cross-Platform, Java

Generating unique IDs in Java

With the UUID class you can generate unique ids. The identifiers generated by UUID are universally unique identifiers. UUID is the fastest and easiest way to generate a unique ID in Java. import java.util.UUID; .. .. public String generateID(){ return String.valueOf(UUID.randomUUID()); } ..import java.util.UUID; .. .. public String generateID(){ return String.valueOf(UUID.randomUUID()); } ..

Cross-Platform, Java

Using mysql with Java

First of all download the Connector/J. Don’t forget to add in your project a reference to mysql-connector-java-x.x.x-bin.jar file. Let’s see the code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 import java.sql.Statement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; …

Cross-Platform, PHP

Get File extension in PHP

Let’s see three different ways to get file extension. Just pick one! 1 2 3 4 5 6 7 8 9 $filename = ‘myfile.txt’; $ext = substr(strrchr($filename, ‘.’), 1); echo $ext."<br>";   $ext = substr($filename, strrpos($filename, ‘.’) + 1); echo $ext."<br>";   $ext = preg_replace(’/^.*.([^.]+)$/D’, ‘$1’, $filename); echo $ext."<br>";$filename = ‘myfile.txt’; $ext = substr(strrchr($filename, ‘.’), …