Category: Java

  • Retrieving Files Recursively in Java

    Sometimes I need to read recursively all the files from a directory. I kept using DirectoryScanner class from the Apache(located in ant.jar in my case). It has the advantage that it can filter through files based on the well-known asterisk matching. Recently I had to look-up in a directory containing lots and lots of files […]

  • Getting SunCertPathBuilderException when sending mail from Java via SSL?

    Do you get SunCertPathBuilderException: unable to find valid certification path to requested target when you try to send a mail from java via smtp(TLS and SSL)? There are 2 possible problems: One option could be from the antivirus/firewall which prevent the communication for a specific port(default 465 for SSL and 587 for TSL) or […]

  • How to Obtain the IP Address and DNS Details for a domain in java

    In the following snippet you can find out how to use the InetAddress class to obtain the ip of the server where a domain is hosted along with the DNS information. Using this class you’ll obtain only the technical DNS details(name server, SOA & MX records), not the emails or the names of the domain […]

  • Date Time Manipulation In Java

    There are 2 useful classes in java to manipulate dates: java.util.Date and java.util.Calendar. Another useful class to format and parse string dates is java.text.SimpleDateFormat.

  • How To Use JDBC addBatch Method with MySQL for Improved Performance

    [tweet-dzone]When you have to deal with a large amount of data to be operated on mySQL databases, the performance can be dramatically improved using a few simple tweaks. First of all you have to use Statement.addBatch/executeBatch instead of simple execute methods. For each added batch, the jdbc driver will store in local memory and when […]

  • How To Download a File in Java

    Here is a snippet that shows how to download a file in java. The snippet is tested and works just fine: static public void download(String address, String localFileName) throws MalformedURLException , FileNotFoundException , IOException { URL url = new URL(address); OutputStream out = new BufferedOutputStream( new FileOutputStream(localFileName)); URLConnection conn = url.openConnection(); InputStream in = conn.getInputStream(); […]

  • How to use Post Method using Apache HttpClient 4

    [tweet-dzone]HttpClient is an apache java library that can be used to read pages over http. It can be used mainly for webpages and provide a well defined API that can handle Cookies, Sessions,… It offers support for both Get and Post methods, so it’s very useful for writing http java clients that can login and […]

  • How to Convert InputStream to String

    [tweet-dzone]Sometimes I feel there are too many classes in java to work with streams and files. InputStream is the base class of all the classes in Java IO API. The input stream class is intended to be used to read the data from different sources in chunks. This is useful for large streams that don’t […]

  • Method Chaining

    [tweet-dzone]Method chaining is a simple programming technique that can be implemented in almost any programming language. In simple words, it means that a method performs some operations on “this” object and then returns it so it can be used further more. It allows us to invoke several methods one after another, on one or different […]

  • Using VBS to set the environment variables

    I use windows and I hate when I have to switch on another computer or when I have to do any change related to windows especially changing the environment variables. I like to download the tool, framework, … I use as a zip and then to do minimal operations to install it. The thing I […]