Posts

Showing posts with the label open source

How to create, modify and save Excel spread sheets in Java using Apach POI

Image
    Java doesn't have built in support for accessing excel files. Various libraries are avialable in java for this purpose. In this turoial we are using Apache PoI Api. you can download the Api from apache poi website  http://poi.apache.org/download.html .The latest version is POI 3.10 . Don't forget to add these files to your build path in eclipse.      Using Apache POI, you can create both Xls and Xlsx files. Prior to 2007, the format of all excel files is .xls and from 2007 the format is .xlsx .      The base class that represents a excel work book in Apache POI is Workbook, for creation of .xls files the required class is HSSFWorkbook, and for .xlsx files it is XSSFWorkbook.  Now lets go into the details 1. How to create .xls/.xlsx work books ? use HSSFWorkbook, XSSFWorkbook for creating xls and xlsx files respectively.  Code Snippet 1 :  creating xls workbook, with default settings...

Quick Tutorial On Selenium For Impatient Learners

What is a selenium ? Selenium is a open-source testing tool, which can interact with the web content inside the real browser such as firefox, google chrome, internet explorer. Selenium is used for automating web application & in Regression testing. Regression testing means, testing the application after the code fixes, & enhancements, to make sure that existing features were not broken. This saves a lot of time and manual rework. Writing Selenium scripts requires some prior knowledge on java programming.  Let's come to the point,  How selenium interacts with the content inside a browser ?    The answer lies in Webdriver. So what is Webdriver ? Webdriver is a tool in selenium, which can open the real browser and can communicate with it. In java terms, Webdriver is an interface.  How to instantiate Webdriver ? You can instantiate Webdriver with FirefoxDriver, ChromeDriver, InternetExplorerDriver. The below examples shows how to d...

JSON - The New Data Interchange Format For Web Services

What is JSON ? JSON ( Javascript Object Notation) is a plain - text format for data storage. It has become quite popular as a data interchange format for web services, for configuration files and more. Features of JSON are, it is easy to read for humans and easy to parse by machines when compared to XML. JSON stores data as plain text. Its grammar is subset of the grammar of java script expressions. How to write a simple JSON object ? Writing a JSON object is very simple. All the members of JSON are nothing but name, value pairs. Its some what simillar to Hash Map of Java language. Just begin with a '{' and all the name, value pairs will be seperated by ',' & name , value are seperated by ':'. Here is an example. {      "First Name" : "speaking" ,      "Last Name" : "cs",      "Type"  : "Blog",      "Domain" : "www.speakingcs.com" } You can save a JSON object...

Executing External Programs From Java

Image
     Using java, you can open external programs such as notepad, command prompt, etc. But executing external processes from java is inherently operating system dependent and requires the developer to know the specific behaviors pertaining to the platform.        Here is the two ways to execute  1. Using java.lang.Runtime 2. Using Apache commons exec library. 1. Using java.lang.Runtime :                   Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method.        Runtime rt = Runtime.getRuntime(); you can execute a program by supplying the command related to that program to the exec method of runtime object.       rt.exec("notepad");     ...