Java Example Codes and Tutorials

Java is great programming language for the development of enterprise grade applications. This programming Language is evolved from a language named Oak.


Learning Java for non programmers Why You Should Learn Java in 2018? Installing JDK 9 on Windows 10 How to convert binary to decimal in Java? How to add two numbers in Java? What is Applet in Java with Example? What is nested class in Java with Example? Exception handling in Java Programming Examples What is Constructor Overloading in Java? How to display image in Swing? What is Java programming used for? How to create custom exception in Java? How to set CLASSPATH in Java? What is Multithreading in Java? IO Streams in Java with Examples How to convert String Date to Timestamp in Java? Best Java Tutorial for Beginners Read user input in Java using Scanner Java Programming Examples Read file line by line in Java 8 What are the benefits of learning Java Programming? A brief history and future of Java programming language Importance of Java for Mobile Application Development How To Become A Good Software Developer? Learn Java Programming for beginners 5 Reasons Java is Still a Great Language to Boost Your Career Prospect as a Programmer How to learn Java with no programming experience? How to learn Java? What are Classes and Interfaces in Java? Converting a String to Integer in Java How to check if a string exists in a string in JavaScript? Installing JDK 8 on Windows 10 and configuring the settings Video Tutorial of reading file in Java 9 Invincible Reasons to learn Java New to Java programming Java Programming Tips, Articles and Notes How to download JDK 1.6? Encapsulation in Java Programming How to format number in Java? Generics Example Program in Java

Java Tutorials - Java Example Codes and Tutorials

Java is great programming language for the development of enterprise grade applications. This programming Language is evolved from a language named Oak. Oak was developed in the early nineties at Sun Microsystems as a platform-independent language aimed at allowing entertainment appliances such as video game consoles and VCRs to communicate . Oak was first slated to appear in television set-top boxes designed to provide video-on-demand services. Oak was unsuccessful so in 1995 Sun changed the name to Java and modified the language to take advantage of the burgeoning World Wide Web.

Java is an object-oriented language, and this is very similar to C++. Java Programming Language is simplified to eliminate language features that cause common programming errors. Java source code files are compiled into a format called bytecode, which can then be executed by a Java interpreter.

If you are beginner read How to Get Started with Java? and New to programming section.

Section I - Introduction to Java

This section introduces you the Java programming language. These days Java programming language is being used for programming web  applications. It is also widely used for mobile and electronic items.

  1. What is Java?
    Java is a high-level object-oriented programming language developed by the Sun Microsystems. Though it is associated with the World Wide Web but it is older than the origin of Web.
  2. Java as an Internet Language
    Java is an object oriented language and a very simple language. Because it has no space for complexities. At the initial stages of its development it was called as OAK. OAK was designed for handling set up boxes and devices.
  3. Java as general purpose language
    Java is an Object oriented application programming language developed by Sun Microsystems.

Java programming tutorials:

Java Flavors
Java For Beginner   Master-Java
  1. New to Java?
    If you are new to Java technology and you want to learn Java and make career in the Java technology then this page is for you.
  2. Use of Java
    Java technology is a high-level programming and a platform independent language. Java is designed to work in the distributed environment on the Internet.
  3. Java Exception
    In this Java exception handling tutorial, you will learn about different types of exception and errors with the solutions to handle it. Basically exceptions in Java are used to handle errors and exceptional events. Go through the given tutorial to find out more on exceptions..
  4. Java Get Example
    An introduction to various methods and functions to get the different values in Java. After going through this section, you will be able to get the date, time, certain values and directory path etc..
  5. Pass Value Example
  6. Java Break Example
  7. Java Biginteger
  8. Java Bigdecimal
  9. JavaScript Array
  10. Java Methods
  11. Java Write
  12. Java Programming Introduction
    Java programming language is useful for development of enterprise grade applications. Java language comes in light from a language named Oak.
  13. Learn Java In A Day
    Java is the most exciting object oriented programming language in computer programming landscape
  14. Learn Java Quickly
    This is one page introduction to java, that will teach you the basics of java. In this quick Java tutorial you will download, install and then create very first java program.
  15. Java Tools
    Java Development Kit or JDK comes with lots of tools for compiling and running the programs. These tools also contains programs to test and document the programs. In this Java Tools tutorials we will provide you detailed introduction of these Java Tools.
  16. Beginners Java Tutorials
    Java Tutorial for beginners.
  17. Java Conversion Tutorials
    Java conversion tutorials with example.
  18. Java Comparison
  19. Java String Examples
    Java String tutorials with example.
  20. Java Exceptions
    Exceptions are nothing but some anomalous conditions that occur during the execution of the program. Exceptions are the conditions or typically an event which may interrupt the normal flow of the program's instructions. 
  21. Wrapper Class Tutorials and Examples
    Wrapper class is a wrapper around a primitive data type. It represents primitive data types in their corresponding class instances e.g. a boolean data type can be represented as a Boolean class instance. 
  22. Reflection API Tutorials and Examples
    Reflection API is a powerful technique (that provides the facility) to find-out Its environment as well as to inspect the class itself. Reflection API was included in Java 1.1. 
  23. Java Applet Tutorials
    Introduction to Java Applet and example explaining how to write your first Applet. Java Applet tutorials for beginners, collection many Java Applets example with running code. 
  24. Java iText - Open Source PDF Libraries
    iText is a java library that provides the facilities for generating PDFs. You can improve the look and feel of your html which is the browser independent by using this java library. You can get more about the iText library inside the topic.
  25. Java Ftp Libraries
    Here you will get some tutorials related to the java ftp including ftp libraries and some important explained examples.
  26. Various Commands that are used in java are given below
    A Java Compiler javac is a computer program or set of programs which translate java source code into java byte code.
  27. Java ClassPath
    Java is an OOP language. In java programming language for compiling the program we use the compiler that converts the source code into the byte code after that, that byte code is interpreted by JVM that converts the bytecode into the machine independent code.
  28. Task Scheduling in JAVA
    In some applications some task need to run periodically, for example a application of report generating checks for new database entry after one day and make reports according to the entries then save all entries in company's permanent record.
  1. Master Java Tutorials (TOC)
    This tutorial will make you perfect in Java i.e. the master of Java. You can be master of Java by going through the Master Java Tutorial.
  2. Java as a programming language
    Java is an Object oriented application programming language developed by Sun Microsystems. Java is a very powerful general-purpose programming language.
  3. Java as an Object Oriented Language
    In this section, we will discuss the OOPs concepts along with  fundamentals  used to develop the java applications and programs.

  1. JEE 5 Tutorial
    Welcome to JEE 5 tutorial guide, here you will find everything need to know about Java Enterprise Edition 5 for developing best enterprise application based on JEE technologies.
  2. JDK 6 Tutorial
    The latest news for the java programmers that the Sun MicroSystems has released the Java SE 6 on Monday December 11. So go and grab your copy.  It has been released with the promises to ease the complexities faced in the jdk 1.5. 
  3. Java IO Package Examples
    The Java I/O is the collection of java classes and interfaces for reading and writing on to stream, byte stream and array of byte stream.
  4. Java AWT Package Examples
    In this section you will learn about the AWT package of the Java. Many running examples are provided that will help you master AWT package.
  5. Java UDP Tutorial
    UDP Tutorial with many examples in Java.
  6. Swing Example
    Here you will find many Java Swing examples with running source code. Source code provide here are fully tested and you can use it in your program.
  7. Java util Examples
    The util package or java provides many utility interfaces and classes for easy manipulation of in-memory data. The java util package tutorials  at introduces you with the Java util package of JDK.
  8. Java Threading Tutorial
    Threading concept is very important in Java Programming language. A thread is a sequential path of code execution within a program. And each thread has its own local variables, program counter and lifetime.
  9. Java 5 Tutorials
    Java 5.0 tutorials.
  10. Java-Network Tutorials
    The Java platform is extremely preferable to write an application program require to communicate with the resources on network.
  11. Simple java program
    Write a simple java program to makes a profit a local store marks up the prices of its items by 25%.
  12. Java Virtual Machine
    JVM is the main component of Java architecture and it is the part of the JRE (Java Runtime Environment) . It provides the cross platform functionality to java.
  13. Collection
  14. Java Date
Detailed Java Course Material

Java Features 

  1. Case sensitivity
    What is case sensitivity:  Case sensitivity is the mechanism in which words can be differ in meaning based on different use of uppercase and lowercase letters.
  2. Java is Simple and platform Independent
    The concept of Write-once-run-anywhere (known as the Platform independent) is one of the important key feature of java language that makes java as the most powerful language.
  3. Java Enabled browsers
    Java language is the most powerful language and is widely used in the web application. Today most of the web browser are java compatible.
    Java Tools 
  4. Java Compiler
    To commence with Java programming, we must know the significance of Java Compiler.
  5. Java Interpreter 
    We can run Java on most platforms provided a platform must has a Java interpreter.
  6. Java Debugger
    Java debugger helps in finding and the fixing of bugs in Java language programs.
  7. Java Header File Generator
    In Java programming we need to implement some native methods. To implement these methods Javah generates C header and source files that are used by C programs to reference an Object's instance variables from native source code.
  8. JavaDoc
    This tool is used to generate API documentation into HTML format from Java source code.
  9. Applet Viewer
    Applet viewer is a command line program to run Java applets.

 Section II- Java Language

  1. Java Comments
    To comprehend any programming language, there are several kind of comments which are used. 
  2. Java Keywords
    There are few keywords in Java programming language. Remember, we cannot use these keywords as identifiers in the program. The keywords "const" and "goto" are reserved though, they are not being currently used.  
  3. Java Data Types
    Java programming language is a language in which all the variables must be declared first and then to be used i.e. to specify the name and the type of the variable. This specifies that Java is a strongly-typed programming language
  4. Literals
    By literal we mean any number, text, or other information that represents a value. This means what you type is what you get. We will use literals in addition to variables in Java statement. While writing a source code as a character sequence, we can specify any value as a literal such as an integer.
  5. Arrays
    In this section you will be introduced to the concept of Arrays in Java Programming language. You will learn how the Array class in java  helps the programmer to organize the same type of data into easily manageable format. 
  6. Operators
    Operators are symbols that performs some operations on one or more then one operands. Once we declare and initialize variables, we can use operators to perform certain tasks like addition, subtraction etc.
  7. Controlling your program
    We all know that the execution of the statements in a program takes place from top to bottom. We will learn how the different kinds of statement have different effects in looping like decision-making statements (if-then, if-then-else, switch), the looping statements (for, while, do-while), and the branching statements (break, continue, return) in Java programming language.
  8. Java Classes
    In this section you will be introduced to some essential classes in Java like Exceptions, Basic I/O, Concurrency etc. 
  9. Class Inheritance
    To know the concept of inheritance clearly you must have the idea of class and its features like methods, data members, access controls, constructors, keywords this, super etc.
  10. Summary
    You have been introduced to the contents of Java language providing a great amount of information. Perhaps it would be a bit arduous to grasp the whole lot of things at one go. However, the implementation of these little basics will make you a substantial programmer. 

Related Java Tutorials/Articles

  1. Java Tutorial and articles
    Here you will find articles related to the Java Programming Language. Some of the articles are:
    Deadlocks in Java
    , Java GC, Java Compile Time Constants, Enum Inversion Problem, Head First Design Pattern, LinkedList vs. ArrayList, Java Break to Label Statement, Strategy Pattern of Hascode Equality, Object Adapter based on Dynamic Proxy, Making Enumerations Iterable, JTable in JDK, JDK 1.5 Performance Surprises ... Click Here to View all tutorials
  2. Java Tutorials - Complete Java Tutorial for Beginners and Advance Programmers
  3. Java Security Packages JCA/JCE
    In this tutorial, the author explains the cryptography-related concepts and packages in JDK, with code examples. Many of the concepts and technical terms thus learnt will be useful in understanding the Cryptography API in MFC also.

    Browser All Tutorials

Latest Java News

More Tutorials
  1. Java API
  2. Advanced Java Tutorials


Share on Google+Share on Google+

Java Example Codes and Tutorials

Posted on: January 18, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Java Example Codes and Tutorials   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
March 26, 2015

i have NEWLY installed JDK1.8.0 and netBeans 8.0.2version Problem:i have run below program getting run time error my coding below import java.sql.*; import*; public class jdbc { public static void main(String args[]) throws IOException { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:ba"); Statement select = con.createStatement(); ResultSet result = select.executeQuery("select * from test"); System.out.println("Got results:"); while( { // process results one row at a time String val = result.getString(2); System.out.println("User_Id = " + val); } select.close(); con.close(); } catch( Exception e ) { System.out.println("connecting error"); e.printStackTrace(); } } } set path:JAVA_HOME=C:\Program Files\Java\jdk1.8.0_40 PATH=C:\Program Files\Java\jdk1.8.0_40\bin; while running time error meg like below connecting error java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver at at java.lang.ClassLoader.loadClass( at sun.misc.Launcher$AppClassLoader.loadClass( at java.lang.ClassLoader.loadClass( at java.lang.Class.forName0(Native Method) at java.lang.Class.forName( at jdbc.main( please advise how run the above program please advise me
Abhishek hack
April 18, 2011
Java program for static method

public class staticc{ int i; static int j; public static void staticMethod(){ System.out.println("you can access a static method this way"); } public void nonStaticMethod(){ i=100; j=1000; System.out.println("Don't try to access a non static method"); } public static void main(String[] args) { //i=100; j=1000; //nonStaticMethod(); staticMethod(); } }
Archana K Prasad
June 15, 2011
source code for an ieee project

i need java source code for the ieee project "an energy efficient medium access control protocol for wireless sensor networks"
September 13, 2011
error in program SQLException

pls help me out
Tripti Singh
December 1, 2011
some help needed

i have previously saved riht programs,i have installed the jdk1.5 and set te path again and tried to run those programs by command was compiled successfully ,but on running it given an exception-exception in thread main-no classDefFounnd! ,plz guide me about it,the attempt of running it on netbeans has also failed.
December 5, 2011
GUI for car rental system

I'm not to sure on how to create a GUI's in java and i'm wondering if you could help also I tried to create two new classes but I can not get them to run properly no matter what i do here is my code: package carrental; import java.util.*; import java.util.Scanner; class Res { private String name; private int num; // private String make; // private String model; // private String regNo; private Car reservecar; private int deposit; private int rate; Res(String name, int num, String model, String regNo, int days, int cost) { } public String getName() { return name; } public int getNum() { return num; } } class Car { private String make; public String model; private String regNo; private int deposit; private int rate; public Car(String newMake, String newModel, String newRegNo, int newDeposit, int newRate) { make = newMake; model = newModel; regNo = newRegNo; deposit = newDeposit; rate = newRate; } public String getMake() { return make; } public String getModel() { return model; } public String getRegNo() { return regNo; } public int getDeposit() { return deposit; } public int getRate() { return rate; } } public class Main { public static void main(String[] args) { ArrayList<Res> reservelist = new ArrayList<Res>(); ArrayList<Car> carlist = new ArrayList<Car>(); Scanner input = new Scanner(; carlist.add(new Car("Toyota", "Altis", "SJC2456X", 100, 60)); carlist.add(new Car("Toyota", "Vios", "SJG9523B", 100, 50)); carlist.add(new Car("Nissan", "Latio", "SJB7412B", 100, 50)); carlist.add(new Car("Murano", "Nissan", "SJC8761M", 300, 150)); carlist.add(new Car("Honda", "Jazz", "SJB4875N", 100, 60)); carlist.add(new Car("Honda", "Civic", "SJD73269C", 120, 70)); carlist.add(new Car("Honda", "Stream", "SJL5169J", 120, 70)); carlist.add(new Car("Honda", "Odyssey", "SJB3468E", 200, 150)); carlist.add(new Car("Subaru", "WRX", "SJB8234L", 300, 200)); carlist.add(new Car("Subaru", "Imprezza", "SJE8234K", 150, 80)); int num; System.out.println(); do { System.out.println("\t1. Make Reservation. "); System.out.println("\t2. Delete Reservation."); System.out.println("\t3. Review Reservations."); System.out.println("\t4. Quit."); System.out.println(); num = input.nextInt(); switch(num) { case 1: Make(carlist, reservelist); break; case 2: Delete(carlist, reservelist); break; case 3: Review(carlist, reservelist); break; case 4:System.out.println("Thank you for using this program."); break; default: System.out.println(" Please follow directions\n" + " 1 Make Reservation. \n" + " 2 Delete Reservation.\n" + " 3 Review Reservations. \n" ); } }while(num != 4); } public static void Make(ArrayList<Car> carlist, ArrayList<Res> reservelist) { String name = null; int num = 0; Scanner input = new Scanner(; System.out.print("Enter model to rent: "); String model = input.nextLine(); for (Car s : carlist) { if (model.equals(s.getModel())) { System.out.println("Model " + model + " is available"); System.out.print("Enter number of days: "); int days = input.nextInt(); System.out.println("****Details****"); int cost = days * s.getRate() + s.getDeposit(); System.out.println("Deposit DailyRate Duration TotalCost"); System.out.println(s.getDeposit() + " " + s.getRate()+ " " + days + " " + cost); System.out.print("Proceed to rent?( y/n ): "); String dec =; if (dec.equals("y")) { System.out.println("Enter Customer Name: "); name =; System.out.println("Enter IC Number: "); num = input.nextInt(); System.out.println("***Receipt****"); System.out.println("Name ICNo Car RegNo Duration TCost"); System.out.println(name + " " + num + " " + model + " " + s.getRegNo() + " " + days + " "+cost); reservelist.add(new Res(name, num, model, s.getRegNo(), days, cost)); System.out.println("Serving Next Customer "); } else if (dec.equals("n")) { System.out.println("Serving Next Customer: "); } } /* if ( carlist.remove(s)) { System.out.println(" Car not available");*/ } } //Delete reservation made public static void Delete(ArrayList<Car> carlist, ArrayList<Res> reservelist) { Scanner input = new Scanner(; System.out.print("Enter name on reservation: "); String name = input.nextLine(); for(Res f : reservelist) { if(name.equals(f.getName())) { System.out.println(f); } } } //review list of reservations public static void Review(ArrayList<Car> carlist, ArrayList<Res> reservelist) { System.out.println(reservelist.size()); } }
January 15, 2012
i need help in this exersize

Write a program that creates a text file that contains a power of two table in HTML format. The file could be called "twoPowerTable.html". When it is viewed with a browser you will see something like: Power of 2 Value 0 1 1 2 2 4 3 8 4 16 5 32 6 64 7 128 8 256 9 512 10 1024 The file should start with something like: <html><head> <title>Powers of Two</title> </head> <body> <table border cellpadding=5> <tr><th>Power of 2</th><th>Value</th></tr> And end with: </table> </body></html> Each line of the table looks like: <tr><td>0</td><td>1</td></tr>
February 8, 2012

Richa Seth
July 2, 2013

I want that all threads will notify each other and kill the other threads once the thread search the path. package richa; import; class MyThread extends Thread { static int spc_count = -1; public MyThread(String s) { super(s); } public void run() { System.out.println("Run: " + getName()); File file = new File(this.getName()); System.out.println("Directory:" + file); Process(file); } public void Process(File aFile) { spc_count++; String spcs = ""; for (int i = 0; i < spc_count; i++) spcs += " "; if (aFile.isDirectory() && aFile.getName().equals("abcdefgh")) { System.out.println(spcs + "[REQUIRED DIREECTORY] " + aFile.getAbsolutePath()); } else if (aFile.isDirectory()) { // System.out.println(spcs + "[DIR] " + aFile.getName()); File[] listOfFiles = aFile.listFiles(); if (listOfFiles != null) { for (int i = 0; i < listOfFiles.length; i++) { Process(listOfFiles[i]); } } else { // System.out.println(spcs + " [ACCESS DENIED]"); } } spc_count--; } } class TestThread { public static void main(String arg[]) { File[] roots = File.listRoots(); System.out.println("Total Paths:" + roots.length); for (int i = 0; i < roots.length; i++) { MyThread temp = new MyThread("" + roots[i]); System.out.println(roots[i]); System.out.println("Started Thread:" + i); temp.start(); // while(true){ // // if(testFound==true){ // // for(Thread thread : threads) // // { // // thread.interrupt(); // // //thread.stop(); // // } // // break;//breaks from while loop // // } // // else{ // // try { // // t.sleep(1); // // } catch (InterruptedException e) { // // // TODO Auto-generated catch block // // e.printStackTrace(); // // } // // } // // } } } }