Sunday, June 30, 2013

Java Static Import Example

Static Import Example Static import java is the great feature, which is available in Java 1.5. Before static import came into picture, the developer needs to access the members through class name. For Example : ClassName.methodName();                      ClassName.dataMember; But with static imports you just import the members in the import section of the class, i.e import static members at the top of the class, after package statement and before declaring class. If the class is too...

Sunday, May 12, 2013

Access specifiers in java

Access specifiers in java : Access specifiers in java classified into four types for the members. Access specifiers place a very important  role in real time java applications. While developing the application we are defined the members which are  visible outside of the class and which should not visible out side of the package. Suppose in some scenarios  we strictly  hide some of the members which are only visible in side the class and the members which should  not visible any of the...

Java File Output Stream Example

Java File Output Stream Example We can write the file content by using File Output Stream . File Output Stream  writes the stream of raw bytes to the file. File output Stream writes the data by using the write() method. File output Stream Example: import java.io.File; import java.io.FileOutputStream; import java.io.IOException; //write the file content using File OutputStream. public class FileOutputStreamExample { public static void main(String[] args) { FileOutputStream...

Java File Input Stream Example

Java File Input Stream Example We can read the files content by using File Input Stream also. File Input Stream  reads the stream of raw bytes. File Input Stream reads the data by using the read() method. File input Stream Example: import java.io.File; import java.io.FileInputStream; import java.io.IOException; //Read the file content using File InputStream. public class FileInputStreamExample { public static void main(String[] args) { FileInputStream fis = null;//<i>File Input Stream</i>...

Java Constructor Example

Java Constructor Example In java the Objects are created by using the constructor. Once we define a class in the java application, automatically the java compiler provides the default constructor. We can define parameterized constructors also depends on our requirement. Example :  Test test = new Test();  class Test{  } In class Test we haven't defined any constructor, here the java compiler provides the constructor. //default constructor in class Test class Test{   Test(){  } } Constructor name must be same as...

Html5 Examples

Html5 Video Exampl...

Html5 Video Example

Html5 Video Example Html5 Video is very simple to embed video in the web page. It is very simple, to embed the video in our browser we just use the video tag as shown in below example. The controls attribute which adds video controls like volume, play and pause....etc source tag which will give the link to the video files. for src attribute , we should give the path of the media files and for type attribute  will give the media type. you can change the width and height based on webpage look and feel. Below you can find very simple...

Saturday, May 11, 2013

Java BufferedWriter

Java BufferedWriter  BufferedWriter is the class which is under the package java.io. BufferedWriter  Write text to a character-output stream. We can write characters to the file  by using the  write methods . Below i am giving the very simple example, which writes the some text content to the file. if file is there it overwrites the content, if file is not there, it creates one file Java BufferedWriter  Example import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException;...

Java BufferedReader

Java BufferedReader Example BufferedReader is the class which is there in java.io package. Buffered Reader reads the text from a character-input stream. We will pass the FileReader as constructor argument to the  Buffered Reader. BufferedReader reads the file line by line, character, group of characters. Create one .txt file under C directory. I am giving below very straight forward example which reads the file content line by line and print in the console. While iterating to the file, if the pointer reaches to the end of the...

Java String

Java String String class is available under the package java.lang.String. String class is very important class, we almost use most of the places while developing the applications. We no need to import this class in our code, automatically this class is available. String is final class, so the string object can not be modify. String class is immutable object, that means its contents can not be editable. There are lot of methods are there to perform string operations like indexOf, concat,charAt...etc We can create string objects in number...

Java static import

java import static Static import in java is the feature which is available in Java 1.5. This is the best feature if we want to use in some real time scenarios. Before java 1.5 if we want to use the static members in another classes/packages we are using the Classname.MemberName, For Example ClassA.Method(); But With this static import feature, we just define the classname/members starting with import static pkg.class; import static pkg.class.memberNames; In the code we can directly use the static members, if we write static import. But...

Linked HashSet Example

LinkedHashSet Example : LinkedHashSet is the class which is available in java.util package. The main advantage of LinkedHashSet is, it preserves the order of the elements. I mean while iterating the LinkedHashSet  the elements are retrieve in the same order how we insert into it. LinkedHashSet implements the Set interface, it allows the Null values and allows unique elements. LinkedHashSet  has lot of methods which are very much useful. LinkedHashSet which extends the java.util.HashSet Class...

Wednesday, April 10, 2013

Java HashSet Example

Java HashSet Example HashSet is the class, which is available in java.util package.  HashSet implements the set interface. HashSet does not preservs the order, suppose if we inert the elments in the HashSet in some order, while  Iterating we can not guarantee to get the same order. HashSet allows the null values. HashSet has the methods like add,remove,size,isEmpty...etc. Java HashSet Sample Code :    import java.util.Iterator; import java.util.HashSet; //HashSet Example Java public class JavaHashSetExample { public...

Java ListIterator Example

Java List Iterator Example: List Iterator is the interface in java.util package. ListIterator has lot of methods which are very much useful based on our real time scenerios. ListIterator has methods which we can iterate in the forward / reverse direction. and ListIterator also have the methods like prviousIndex and nextIndex methods. and it also has set,remove and add methods. I am giving the below very basic ListIterator Sample.  Java List Iterator sample code : import java.util.ArrayList; import java.util.ListIterator; /* * Java...

Sunday, April 7, 2013

Java TreeSet Example

Java TreeSet Example TreeSet is the class which is available in java.util package. The main advantage of TreeSet is, it automatically sorts the elements. TreeSet implements the Set interface, it doesn't allow the Null values and allows unique elements. TreeSet has lot of methods which are very much useful. TreeSet isEmpty() method which checks whether the TreeSet is empty or not. TreeSet methods are remove,removeall, add,addall,contails,contailsall...etc  Java TreeSet Example Code import java.util.Iterator; import java.util.TreeSet; //TreeSet...

Java Enhanced For Loop Example

Java Enhanced For Loop Example : Enhanced For Loop is a more easy way and convenient way to iterate the elements from the collections or Arrays. I am giving very basic Enhanced For Loop Example below. The below code is very straight forward how you iterate the elements over the collections/arrays by using Enhanced For Loop. Enhanced For Loop Example Code  import java.util.ArrayList; //Java Enhanced for Loop Example public class EnhancedForLoopExample { public static void main(String[] args) { String[] array = new String[]...

Saturday, April 6, 2013

Java Iterator Example

Java Iterator Example I am giving the very straight forward example how you Iterate the elements from the ArrayList. Iterator is the interface which is there in the package java.util. You can iterate the elements from the Iterator by using the methods hashNext() and next(). By using remove() method we can remove the elements from the Iterator. Sample code for the Java Iterator Example : import java.util.ArrayList; import java.util.Iterator; /* * JavaIterator Example */ public class JavaIteratorExample { @SuppressWarnings({ "rawtypes",...

Friday, March 29, 2013

StringTokenizer Example

StringTokenizer Example: StringTokenizer is the class in java.util package. The use of StringTokenizer class is breaks the given string into number of tokens based on the delimiter. Here i am giving the very simple StringTokenizer Example. you can easily understand the below code. In the below example, i am using the delimiter as ';' While creating the StringTokenizer object I am passing the given string and the delimiter. By using the countTokens() method, will get the total number of tokens. String Tokenizer Sample code import java.util.StringTokenizer;...

Wednesday, March 20, 2013

Java HashMap Example

Java HashMap Example : HashMap is the class in java.util package, The main advantage of HashMap is to store the information in the form of Key/Value pairs. In this HashMap Object we can store the null values also. that means the HashMap accepts to store the null values as key/value pairs. Suppose you are retrieving the data from the database, if some records are returned with null values. you can store these null values also in this HashMap object. HashMap is not synchronized. Below is the very straight and quick start example for HashMap. The...

Sunday, March 17, 2013

Java ArrayList Example

Java ArrayList Example : Java ArrayList Example, I am giving very straight, short and easy description, you can straight away use this in your Code. ArrayList : You can find this ArrayList class in java.util package. There are lot of methods available to manipulate ArrayList Object. The advantage of ArrayList is to store the different kind of objects, either string or user defined class objects. In the below i am giving the ArrayList Example how you can store the String Objects and again get the objects from that ArrayList object. Here i...

Thursday, March 14, 2013

Core Java Samples

Hello World Example                                   LinkedHashSet Example Java ArrayList Example                               Java static import Java HashMap Example                               Java String StringTokenizer Example               ...

Hello World Example

Java Hello World Example  It is very simple in java to write the Hello World Example. In this Example, We just print the Text as Hello World Example on the console after executing this Program. The below Example is very straight forward example, take the below code and just compile using from the  command prompt or you can use any tools like eclipse. Use the Javac command to compile the java program, for Example Javac HelloWorld.java. Once you compile this program, the Java compiler compiles and generates the .class file....

Monday, March 11, 2013

Java Interview Questions

  if(null==null){ System.out.println("Both are equal");           }else{ System.out.println("Both are not equal");           }                    What is the output for the above code?           Output : Both are equal. Difference between finally and finalize? What is cloning? what is deep and shallow cloning? How to do deep cloning? How you write the program to read the...

 
Disclaimer : If you find any mistakes / corrections / feedback Please let us know...This website author shall not accept liability or responsibility for any errors, mistakes or misstatements found in this website.