Tag: java

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, Java

Establish FTP connection with Java

To establish a connection with a FTP server we are going to use Apache commons Net library. You can download it from here. The code below is licensed under GPLv3. /* * SimpleFTP connection * Open Source FTP Connection Client sample * Copyright (C) 2011 SimpleFTP KARPOUZAS GEORGE * * This program is free software: …

Cross-Platform, Java

Create XML file with JAVA

If you would like to create an XML file similar to this: 1 2 3 <customers> <customer id="124587956" firstname="George" lastname="Karpouzas"/> </customers><customers> <customer id="124587956" firstname="George" lastname="Karpouzas"/> </customers> you can do it by using the following JAVA method: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 …

Cross-Platform, Java

Get URL contents with Java

It is very easy to download url contents using a few lines of java code: The source code below is licensed under GPLv3. GetURLContents.java (GetURLContents) import java.io.*; import java.net.*;   public class GetURLContents {   public static void main (String[] args) { URL url; InputStream input = null; BufferedReader inputs; String str;   try { …