Posts

Showing posts from April, 2013

Important Abbreviations used in Java/J2EE

Hi Everyone, in this blog post, I am mentioning about the important abbreviations used in Java, J2EE and other related services. Java JDK - Stands for Java Development Kit . JDK contains software development tools which are used to compile and run java programs. Different versions of JDK are JDK 1.4, 1.5, 1.6. JRE - Stands for Java Runtime Environment . JRE is used as a interpreter of byte code to machine code. JVM - Stands for Java Virtual Machine . JVM is used to compile the Java program which converts source code to byte code. Web Development HTML - Hyper Text Markup Language . Main markup language for creating web pages. XML - eXtensible Markup Language.  XML is a markup language that defines a set of rules for encoding documents in a format. CSS - Cascading Style Sheets. Style sheet language used for describing the presentation semantics of a document written in a markup language. DHTML - Dynamic HTML. DHTML is a collection of technologies used together to cre

Java program to check whether 2 numbers have opposite signs

Hi Everyone, this blog post is about how to check whether 2 numbers have the opposite signs. The immediate solution which comes to our mind when we see this question is check using ' if ' loop. But there is much simpler way than doing this. When we see the integers in terms of bits, we can see that if the integer is negative, the MSB (Most Significant Bit) of that integer is set to 1. The MSB is 0 if the integer is positive. So, the algorithm to check whether 2 numbers have opposite signs is based on bits. We just needed to XOR both the numbers. An XOR would return 1, if there is 1 and 0 or 0 and 1. For similar numbers, they will just return 0. If we XOR both the numbers, the result should be negative if both the numbers have different sign and it will be positive if both the numbers have same sign. The java program is as follows: public   class  DifferentSigns {           public   static   void  main(String args[])     {          int  num1=-20;          int  nu

Java program to convert Integer to String

Hi Everyone, this post deals with the conversion of Integer to String. Please refer my earlier post which deals in converting String to Int. The logic of the program is very simple. We have to divide the given number by 10 and append the remainder to a String until the number reaches 0. The program is as follows: public   class  program {      public   static   void  main (String args[])     {          int  num = 52;         String str = IntToStr(num);         System.out.println(\ " The string representation of the number is : \" +str);     }           public   static  String IntToStr ( int  num)     {          boolean  isNegative =  false ;          if (num <0 )               {             num = num* -1;             isNegative= true ;         }         StringBuilder build =  new  StringBuilder();          if (isNegative)         {             build.append(\ '-\' );         }         StringBuilder build1 =  new  StringBuilder();     

Hibernate Made Easy : 1 - Hibernate Introduction

Image
Hi Everyone, in this blog post, I am writing about a sample program in hibernate. By definition hibernate is an object relational mapping library for java, providing a framework for mapping an object domain model to a traditional relational database (Wikipedia definition). In simpler terms, hibernate is used to map java objects to database tables. Object Relational Mapping - Programming technique for converting data type between incompatible type systems in object oriented programming techniques. Here objects and variables in a class are converted to table and fields in database respectively. Framework - An abstraction in which software providing generic functionality can be selectively changed by additional user written code. Relational Database - Collection of data items organized as a set of formally described tables from which data can be accessed easily. Hibernate is mainly used for mapping from java objects to database tables and from java data types to sq

Sample test case program using JUnit

Hi Everyone, in this post, I will be writing a sample case using JUnit. JUnit is an unit testing framework for java application. JUnit has been important in developement of test driven developement, and is one of a family of unit testing framework which is collectively known as xUnit that is originated from sUnit. Here, I am writing a sample test case program for the program conversion of String to Int in Java.  Before starting the program we have to download the jar file of JUnit and put it in the lib folder. The program is as follows: package com.program; import com.program.*; import static org.junit.Assert.*; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import com.program.InvalidNumberException; import com.program.StringToInt; public class StringToIntTestCase { @BeforeClass public static void setUpBeforeClass() throws Exception { System.out.println("SetUp BeforeClass