Java Programing laungage

Core Java Tutorial

Introduction of Core Java

How To Install JDk and Set of Path

Syntax of java Program

Difference between Java and C/C++

Advantage and Disadvantage of Java

What is Java

Why Java is not Pure Object Oriented Language

Java has Following Features/Characteristics

Limitation of Java Language and Java Internet

Common Misconception about Java

Simple Program of Java

Integrated Development Environment in java

Compile and Run Java Program

Applet and Comments in Java

Tokens in Java

Keywords in Java

Identifier and Variables in Java


Data Type in Java

Assignments and Initialization in Java

Operators in Java

Rule of Precedence in Java

Operator on Integer and Separators in Java Programming

Java Control Flow of Statements

If and If-else Selection Statement

Nested If-else and If-else-If Selection Statement

switch case and conditional operator Selection Statement

for and while Loop

do..while and for each Loop

break and labeled break statement

continue and labeled continue statement

return Statement and exit() Method

Escape Sequence for Special Characters and Unicode Code

Constants and Block or Scope

Statement in Java

Conversions between Numeric Types in Java

Import Statement in Java

User Input in Java using Scanner Class

User Input in Java using Console Class

Array in Java

One Dimensional Array

Two Dimensional Array

Two Dimensional Array Program

Command Line Argument in Java

String args Types in Java

Uneven/Jagged array in java

Math Class Function and Constant

Math Class all Function used in a program

Enumerated Types in Java

Object Oriented Programming v/s Procedural Programming

Object Oriented Programming Concepts in Java

Introduction to Class,Object and Method in Java

Class Declaration in Java

Class & Objects in java

Encapsulation in Java

Modifiers/Visibility for a Class or Interrface or member of a Class

Polymorphism in Java

Runtime polymorphism (dynamic binding or method overriding)

jdk1.5 new features with example
Previous Home Next
  1. Generics: provides compile-time (static) type safety for collections and eliminates the need for most typecasts (type conversion).


    • Collection element types
    • Cannot be checked at compile time
    • Assignment must use cast
    • Can cause runtime errors ( ClassCastException)
    • Tell the compiler what type your collection is
    • Compiler can fill in casts for you
    • Guaranteed to succeed.

    Generics Example

    Old code:-
     List l = new LinkedList();
    l.add(new Integer(0));
    Integer i = (Integer);
    New code:-
     List<Integer> l = new LinkedList<Integer>();
    l.add(new Integer(0));
    Integer i =;

    Generics are NOT templates

    • No code size increase
    • No hideous complexity
    • No “template metaprogramming”
  2. Enhanced for each loop: the for loop syntax is extended with special syntax for iterating over each member of either an array or any iterable, such as the standard collection classesfix the previously broken semantics of the java memory model, which defines how threads interact through memory.


    • Iterating over collections is tricky
    • Often, iterator only used to get an element
    • Iterator is error prone (Occurs three times in a for loop)
    • Can produce subtle runtime errors


    • Let the compiler do it
    • New for loop syntax
    • for (variable : collection)

    Enhanced for loop example

     Old code:-
     void cancelAll(Collection c) {
    for (Iterator i = c.iterator(); i.hasNext(); ) {
    TimerTask task = (TimerTask);
    task.cancel(); } }
     New Code:-
     void cancelAll(Collection<TimerTask> c) {
    for (TimerTask task : c)
     Also works for arrays
  3. Metadata: also called annotations; allows language constructs such as classes and methods to be tagged with additional data, which can then be processed by metadata-aware utilities.


    Some APIs require lots of standard code

    How to indicate this to a tool


    Annotated source code

    e.g. @remote getPrice(Product p)

  4. Auto boxing/unboxing: Automatic conversions between primitive types (such as int) and primitive wrapper classes (such as integer).


    Conversion between primitive types and

    wrapper objects (and vice-versa)

    Needed when adding primitives to a collection


    Let the compiler do it
    Integer intObj = 22; // Boxing conversion
    int i = (int)intObj // Unboxing conversion
    ArrayList al = new ArrayList();
    al.add(22); // Boxing conversion
  5. Enumerations: the enum keyword creates a typesafe, ordered list of values (such as day.monday, day.tuesday, etc.). Previously this could only be achieved by non-typesafe constant integers or manually constructed classes (typesafe enum pattern).

    Typesafe Enumerations


    Variable needs to hold limited set of values

    e.g. Card suit can only be Spade, Diamond, Club, Heart


    New type of class declaration

    enum type has public, self-typed members for

    each enum constant

    new keyword, enum

    works with switch statement

    Enumeration Examples

    public enum Coin {
    penny(1), nickel(5), dime(10), quarter(25);
    Coin(int value) { this.value = value; }
    private final int value;
    public int value() { return value; }
  6. Var args: the last parameter of a method can now be declared using a type name followed by three dots (e.g. Void drawtext(string... Lines)). In the calling code any number of parameters of that type can be used and they are then placed in an array to be passed to the method, or alternatively the calling code can pass an array of that type.


    To have a method that takes a variable number of parameters

    Can be done with an array, but not nice Look at java.text.MessageFormat

    Solution: Let the compiler do it for you

    New syntax:

    public static String format(String fmt,Object... args);
     Java gets printf !!!
  7. Static imports


    Having to fully qualify every static

    Referenced from external classes


    New import syntax

    import static TypeName . Identifier ;

    import static Typename . * ;

    Also works for static methods and enums

    e.g Math.sin(x) becomes sin(x)

  8. Concurrency Utilities

    Goal: Beat C performance in high end

    server side applications

    New framework for locks to provide greater

    flexibility over synchronized

    No more threads, use Executors

    Use anExecutor.execute(aRunnable)

    Not new Thread(aRunnable).start();

    Runnable and Callable

    Callable for things that return values and/or exceptions

Previous Home Next