1
Discussion about???

Why need to navigate to   Java code life cycle
JAVA?                     Data types.
Goals of JAVA.            Wrapper Classes.
Features of JAVA.         Operators.
C++ Vs JAVA.




                                                 2
Why ‘JAVA’ the programming
         language?
The ultimate aim to develop the JAVA programming language
is to implement the words “write once; run anywhere, any time,
forever”.

This is the problem the people meet at that time. The wanted
to have the language that can be run for any platform(Operating
System). This led to the development of JAVA as initial name
Oak. Then JAVA COFFEE, finally renamed as JAVA.


                                                               3
cntd.....




        The application needed to be platform independent in some
        places. Assume the situation the application is going to be run on
        networked systems.

            In network many kind of system specification and OS may be
            there. In this case the application must be a Platform
            independent. Here, JAVA will help us.




                                                                        4
Goal of JAVA
It should use the object-oriented programming methodology.

It should allow the same program to be executed on multiple
operating systems.

It should contain built-in support for using computer networks.

It should be designed to execute code from remote sources
securely.

It should be easy to use by selecting what was considered the
good parts of other object-oriented languages.

                                                                  5
Features of JAVA

Simple              Architecture-neutral

Secure              Interpreted

Portable            High performance

Object-oriented     Automatic Garbage Collection

Robust

Multithreaded



                                               6
Automatic Garbage Collection

The memory management(allocation and de-allocation) of an
allocated object is done automatically.

If the reference for the object is not available in program, then
the JVM automatically de-allocates the memory for that object.

If this is not done automatically, the programmer must do the
code to manage the memory(allocate and de-allocate).

If not de-allocated by the programmer, then the memory
fragmentation is difficult. Memory leak will occur.
                                                                    7
Example code
public static int main(String[] a)
{
  System.out.println(“n”+4+34);
  return 0;
}

Output???

Error: Main method not found in class sample, please define the main method as:
        public static void main(String[] args)




                                                                                  8
eg: cntd

 public static void main(String[] a)
 {
    System.out.println(“n”+4+34);
    System.out.println(34+2+"n");
    return 0;
 }
 Output ??? 434
               36



   public static void main(String[] a)
   {
            System.out.println(4+34);
            return 0;
   }
         Output ???     38

                                         9
C++ Vs
                 C++                                     JAVA

Not a full-fledged object oriented      The pure Object oriented language.
language. Because, we can write the
complete program without using
class.


We can write an error free program,     Here, we can not complete the
with class and without having any       execution without having code within
code within the main(). The program     the main().
can be correctly executed completely.


Multiple inheritance is supported.      Multiple inheritance is removed.

Operator overloading is available.      Not available.

                                                            cntd….             10
Virtual functions is available.           Indirectly method overriding having
                                          the working of virtual function.

Pointers, references available.           References only available.

Platform dependent.                       Platform independent.

Abstract class avail.                     Abstract class may be mapped to Interface.



Automatic garbage collection not avail.   Available.

Not a strongly typed language.            Strongly typed language.

Unicode not supported.                    Unicode support provided.

Destructor available.                     finalize() method available instead
                                          destructor.

const                                     final

                                                                                  11
Function prototype

In C++ the function prototype is ??
     return_type function_name(argument_list)

In java for the function prototype concentration on 4 things.
return_type function_name(argument_list) Exception




                                                                12
Code Life cycle




                  13
Data Types
All the data types available in C++ available in JAVA. But some
more additions upgraded.
The data width of int and char are upgraded as follows.,
The extra data types are also introduced.
              Data type              Size(bits)
    long                     64
    int                      32
    short                    16
    char                     16
                          New
    byte                     8
    boolean                  1
                                                              14
Wrapper Classes
Wrapper classes are special type of classes those bind with the simple
types(Built-in data types).

The Number class is an abstract class that defines a super class that is
implemented by the classes that wrap the numeric types(byte, int,
float, double, long, short).

The class name starts with the uppercase., like Integer, Float.

Each and every wrapper class defines its own methods and constant
data members. The constant data members declared with the names
full of uppercases. eg., Integer.MIN_VALUE.

                                                                       15
for example


public static void main(String[] arg)
{
  Integer g;
  g=45;
  System.out.println("ng : “+g);
}



Output
  45




                                        16
Operators

The operators used in C++ all supported in JAVA too.

The I/O stream operators is not possible in java(<<,>>). But
these operators used as a bitwise operators.

Operator overloading can not be done by the user. But in
JAVA, there are some implemented provisions those using the
pre-defined operators with the class.

The arithmetic, relational operators used with the String class
objects.
                                                                  17
example…..

public static void main(String[] arg)
{
  String fg=“PSG",gh=“Psg";
  if((fg+=gh)==fg)
         System.out.println("same....n");
  else
         System.out.println(“Not same....n");
}

        Output:
                        same....




                                                 18
Example
public static void main(String[] arr)
{
  int i1=45;
  int i2=34;
  System.out.println(“Ans is : “+i1+i2);
}

Output???
          Ans is : 4534




                                           19
General example
public static void main(String[] arg)
{
  DataInputStream inp=new DataInputStream(System.in);
  String mine=inp.readLine();
}

output???
            Error: Un handled Exception IOException




                                                        20
Revised

public static void main(String[] arg) throws IOEception
{
  DataInputStream inp=new DataInputStream(System.in);
  String mine=inp.readLine();
  System.out.println(“nString is : ”+mine);
  float h=Float.parseFloat(inp.readLine());
  System.out.println(“n Float values is : ” +h);
}




                                                          21
22
23

14.jun.2012

  • 1.
  • 2.
    Discussion about??? Why needto navigate to Java code life cycle JAVA? Data types. Goals of JAVA. Wrapper Classes. Features of JAVA. Operators. C++ Vs JAVA. 2
  • 3.
    Why ‘JAVA’ theprogramming language? The ultimate aim to develop the JAVA programming language is to implement the words “write once; run anywhere, any time, forever”. This is the problem the people meet at that time. The wanted to have the language that can be run for any platform(Operating System). This led to the development of JAVA as initial name Oak. Then JAVA COFFEE, finally renamed as JAVA. 3
  • 4.
    cntd..... The application needed to be platform independent in some places. Assume the situation the application is going to be run on networked systems. In network many kind of system specification and OS may be there. In this case the application must be a Platform independent. Here, JAVA will help us. 4
  • 5.
    Goal of JAVA Itshould use the object-oriented programming methodology. It should allow the same program to be executed on multiple operating systems. It should contain built-in support for using computer networks. It should be designed to execute code from remote sources securely. It should be easy to use by selecting what was considered the good parts of other object-oriented languages. 5
  • 6.
    Features of JAVA Simple Architecture-neutral Secure Interpreted Portable High performance Object-oriented Automatic Garbage Collection Robust Multithreaded 6
  • 7.
    Automatic Garbage Collection Thememory management(allocation and de-allocation) of an allocated object is done automatically. If the reference for the object is not available in program, then the JVM automatically de-allocates the memory for that object. If this is not done automatically, the programmer must do the code to manage the memory(allocate and de-allocate). If not de-allocated by the programmer, then the memory fragmentation is difficult. Memory leak will occur. 7
  • 8.
    Example code public staticint main(String[] a) { System.out.println(“n”+4+34); return 0; } Output??? Error: Main method not found in class sample, please define the main method as: public static void main(String[] args) 8
  • 9.
    eg: cntd publicstatic void main(String[] a) { System.out.println(“n”+4+34); System.out.println(34+2+"n"); return 0; } Output ??? 434 36 public static void main(String[] a) { System.out.println(4+34); return 0; } Output ??? 38 9
  • 10.
    C++ Vs C++ JAVA Not a full-fledged object oriented The pure Object oriented language. language. Because, we can write the complete program without using class. We can write an error free program, Here, we can not complete the with class and without having any execution without having code within code within the main(). The program the main(). can be correctly executed completely. Multiple inheritance is supported. Multiple inheritance is removed. Operator overloading is available. Not available. cntd…. 10
  • 11.
    Virtual functions isavailable. Indirectly method overriding having the working of virtual function. Pointers, references available. References only available. Platform dependent. Platform independent. Abstract class avail. Abstract class may be mapped to Interface. Automatic garbage collection not avail. Available. Not a strongly typed language. Strongly typed language. Unicode not supported. Unicode support provided. Destructor available. finalize() method available instead destructor. const final 11
  • 12.
    Function prototype In C++the function prototype is ?? return_type function_name(argument_list) In java for the function prototype concentration on 4 things. return_type function_name(argument_list) Exception 12
  • 13.
  • 14.
    Data Types All thedata types available in C++ available in JAVA. But some more additions upgraded. The data width of int and char are upgraded as follows., The extra data types are also introduced. Data type Size(bits) long 64 int 32 short 16 char 16 New byte 8 boolean 1 14
  • 15.
    Wrapper Classes Wrapper classesare special type of classes those bind with the simple types(Built-in data types). The Number class is an abstract class that defines a super class that is implemented by the classes that wrap the numeric types(byte, int, float, double, long, short). The class name starts with the uppercase., like Integer, Float. Each and every wrapper class defines its own methods and constant data members. The constant data members declared with the names full of uppercases. eg., Integer.MIN_VALUE. 15
  • 16.
    for example public staticvoid main(String[] arg) { Integer g; g=45; System.out.println("ng : “+g); } Output 45 16
  • 17.
    Operators The operators usedin C++ all supported in JAVA too. The I/O stream operators is not possible in java(<<,>>). But these operators used as a bitwise operators. Operator overloading can not be done by the user. But in JAVA, there are some implemented provisions those using the pre-defined operators with the class. The arithmetic, relational operators used with the String class objects. 17
  • 18.
    example….. public static voidmain(String[] arg) { String fg=“PSG",gh=“Psg"; if((fg+=gh)==fg) System.out.println("same....n"); else System.out.println(“Not same....n"); } Output: same.... 18
  • 19.
    Example public static voidmain(String[] arr) { int i1=45; int i2=34; System.out.println(“Ans is : “+i1+i2); } Output??? Ans is : 4534 19
  • 20.
    General example public staticvoid main(String[] arg) { DataInputStream inp=new DataInputStream(System.in); String mine=inp.readLine(); } output??? Error: Un handled Exception IOException 20
  • 21.
    Revised public static voidmain(String[] arg) throws IOEception { DataInputStream inp=new DataInputStream(System.in); String mine=inp.readLine(); System.out.println(“nString is : ”+mine); float h=Float.parseFloat(inp.readLine()); System.out.println(“n Float values is : ” +h); } 21
  • 22.
  • 23.