1 / 71

GENESIS OF JAVA & AN OVERVIEW

GENESIS OF JAVA & AN OVERVIEW. SHASHI BHUSHAN SOCIS, IGNOU. TODAY’S AGENDA. GENESIS OF JAVA AN OVERVIEW OF JAVA. GENESIS OF JAVA. SOFTWARE DEVELOPMENT BURDEN THE WEB REVOLUTION NEW ORDER OF COMPUTING PHILOSOPHY OF JAVA AND DESIGN GOALS JAVA BUZZWORDS. GENESIS OF JAVA (CONTD..).

Télécharger la présentation

GENESIS OF JAVA & AN OVERVIEW

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GENESIS OF JAVA & AN OVERVIEW SHASHI BHUSHANSOCIS, IGNOU

  2. TODAY’S AGENDA • GENESIS OF JAVA • AN OVERVIEW OF JAVA

  3. GENESIS OF JAVA • SOFTWARE DEVELOPMENT BURDEN • THE WEB REVOLUTION • NEW ORDER OF COMPUTING • PHILOSOPHY OF JAVA AND DESIGN GOALS • JAVA BUZZWORDS

  4. GENESIS OF JAVA (CONTD..) • MULTIPLE INCOMPATIBLE HARDWARE ARCHITECTURE • MULTIPLE INCOMPATIBLE OPEARATING SYSTEM • INCOMPATIBLE GUI SOFTWARE DEVELOPMENT BURDEN:

  5. GENESIS OF JAVA(CONTD..) • GROWTH OF INTERNET, WWW AND ELECTRONIC COMMERCE • THE WEB RESOLUTION WHOSE KEYPOWER IS “WRITE ONCE AND RUN ANYWHERE” MODEL REQUIRED A NEW PARADIGM

  6. GENESIS OF JAVA (CONTD..) • DATA ONLY • INFORMATION IS STATIC • HTML IS NOT FLEXIBLE • LARGE NUMBER OF COMPUTING PROTOCOLS AND STANDARDS LIMITATIONS OF WEB TECHNOLOGY:

  7. GENESIS OF JAVA (CONTD..) • JAVA PHILOSOPHY AND DESIGN GOALS “WRITE ONCE, RUN ANYWHERE ON ANY PLATEFORM”. THE NETWORK BECOMES THE DISTRIBUTION VEHICLE FOR S/W APPLICATION. IT MUST ENABLE THE DEVELOPMENT OF SECURE HIGH PERFORMANCE AND HIGHLY ROBUST APPLICATION ON MULTIPLE PLATFORM IN HETEROGENEOUS & DISTRIBUTED NETWORKS. • SUPPORT OF DYNAMIC ACTIVE PROGRAMS (APPLETS) FOR TRANSMISSION BETWEEN CLIENTS AND SERVERSATTATCHED TO INTERNET.

  8. GENESIS OF JAVA (CONTD..) APPLETS AND APPLICATIONS: • AN APPLICATION IS A PROGRAM WHICH RUNS ON ANY COMPUTER UNDER THE OPERATING SYSTEM OF THAT COMPUTER. IT IS SIMILAR TO ANY APPLICATION PROGRAM CREATED BY C OR C++. • AN APPLET IS AN APPLICATION DESIGN TO BE TRANSMITTED OVER THE INTERNET AND EXECUTED BY JAVA COMPATIBLE BROWSERS. AN APPLET IS LIKE TINY JAVA PROGRAM DYNAMICALLY LOADED ACROSS THE NETWORK JUST LIKE AN IMAGE , SOUND FILE OR VIDEOCLIP.

  9. AN OVERVIEW OF JAVA JAVA BUZZWORDS: • SIMPLE, FAMILIAR AND OBJECT ORIENTED • ROBUST • HIGH SECURITY • ARCHITECTURE NEUTRAL AND PORTABLE • MULTITHREADED • HIGH PERFORMANCE • DISTRIBUTED AND DYNAMIC

  10. AN OVERVIEW OF JAVA (CONTD..) JAVA API AND CORE LANGUAGE FUCTIONS: • JAVA.LANG • JAVA.IO • JAVA.AWT • JAVA.APPLET • JAVA.SQL • JAVA.NET • JAVA.UTIL

  11. AN OVERVIEW OF JAVA (CONTD..) FETURES REMOVED FROM C & C++ • NO MORE TYPEDEFS, OR PREPROCESSOR • NO MORE STRUCTURE OR UNIONS • NO MORE MULTIPLE INHERITANCE • NO MORE GOTO STSTEMENTS • NO MORE AUTOMATIC COERSIONS • NO MORE POINTERS • NO MORE POINTER ARITHMETICS

  12. AN OVERVIEW OF JAVA (CONTD..) /*Using a text editor create a file named HelloWorld. java with the java code shown below*/ THE FIRST SAMPLE PROGRAM: class HelloWorld {public static void main (String[ ] args) {System.out.println (“HelloWorld”); //display the string }}

  13. AN OVERVIEW OF JAVA (CONTD..) • Javac HelloWorld.java • The compiler creates a file named HelloWorld. Class in the same directory as the java source file HelloWorld.java. The class file contains platform independent java bytecodes. Compiling the source file using the JDK • Run the application • java HelloWorld

  14. Member of the Java.lang package provides access to the system functionality such as standard I/O, copying arrays, getting the current date and time provides access to externally defined properties, means of loading files and libraries. • System.out is a class variable that is a reference to an object implementing the standard output stream. AN OVERVIEW OF JAVA (CONTD..) The System Class

  15. System.in is a class variable that is a reference to an object implementing standard input stream. • System.err implements the standard error system. • System class can not be instantiated. AN OVERVIEW OF JAVA (CONTD..) The System Class

  16. AN OVERVIEW OF JAVA CONTD.. MAIN FEATURES OF THE JAVA LANGUAGE: • NUMERIC DATA TYPES & CHARACTER DATA TYPES • BOOLEAN TYPES • ARRAYS JAVA FOLLOWS C & C++ FAIRLY CLOSELY IN ITS SET OF BASIC DATA TYPES. THERE ARE ONLY THREE GROUPS OF PRIMITIVE DATA TYPES, NAMELY:

  17. AN OVERVIEW OF JAVA CONTD.. NUMERIC DATA TYPES: • BYTE - 8 BIT SIGNED QUANTITY • SHORT - 16 BIT SIGNED QUANTITY • INT - 32 BIT SIGNED QUANTITY • FLOAT - 32 BIT IEEE 754 SPECIFICATION • LONG - 64 BIT SIGNED QUANTITY • CHARACTER DATA TYPE - 16 BIT UNICODE CHAR

  18. AN OVERVIEW OF JAVA CONTD.. BOOLEAN DATA TYPES AND ARITHMETIC & RELATIONAL OPEARTORS: A JAVA BOOLEAN IS A DISTINCT DATA TYPE (TRUE OR FALSE) UNLIKE COMMON ‘C’ PRACTICE. A JAVA BOOLEAN TYPE CANNOT BE CONVERTED TO ANY NUMERIC TYPE 1 OR 0.

  19. BOOLEAN DATA TYPES AND ARITHMETIC & RELATIONAL OPEARTORS (CONTD..) : ARITHMETIC & RELATIONAL OPEARTORS ARE : • SIMILAR TO ‘C’ OR ‘C++’ • >>> INDICATES UNSIGNED (LOGICAL) RIGHT • + IS USED TO COMBINE TWO SHIFTS STRINGS • System.out.println (“THERE ARE” + num + “CHARS IN A FILE”)

  20. AN OVERVIEW OF JAVA (CONTD...) ARRAYS : • Syntax in Java is much the same as in C. • Arrays are (references to) objects • new operator is used to create an array • Indexed with any integer type primitive // a single dimension array of ints • int numbers[ ] = new int[10]; • int [ ] numbers = new int[10]; • Array’s size can not be changed after it is created • For dynamically sized array, java.util.Vector class is used

  21. AN OVERVIEW OF JAVA (CONTD...) ARRAYS : All arrays have instance variable length which hold the size of the array. class Length { public static void main(String[ ] args){ int a1[ ] = new int [10]; int a2[ ] = {3, 5, 7, 1, 8, 99, 44}; System.out.println (“length of a1 is” + a1.length) System.out.println (“length of a2 is” + a2.length); } }

  22. AN OVERVIEW OF JAVA (CONTD...) ARRAYS OF OBJECTS : Arrays can contain any legal java data types including reference types such as object or other arrays. For example, the following declares an array of ten String objects. String[ ] arrayofStrings = new String[10];

  23. AN OVERVIEW OF JAVA (CONTD...) ARRAYS OF OBJECTS (Contd...): The element in this array are reference types that is, each element contains a reference to a String object. At this point, enough memory has been allocated to contain String references but no memory has been allocated for the String objects themselves. If you attempt to access one of the array of Strings elements at this point, you will get NullpointerException because the array is empty and contains no String objects.

  24. AN OVERVIEW OF JAVA (CONTD...) ARRAYS (Command line arguments explained): Explanation: This simple application displays each of its command line arguments on a line by itself. class Echo{ public static void main (String[ ] args) { for (int i = 0; i<args.length; i++) System.out.println (args [i] ); } }

  25. AN OVERVIEW OF JAVA (CONTD...) STRING: A sequence of char data is called a string and is implementd in the java environment by the String class (a member of the java.lang package). The following statement explicitly declares an array named args that contains String objects. The empty bracket indicates that the lenght of the array is unknown at compilation time because the array is passed in at run time. (String[ ] args) //declared with the main( ) “IGNOU” // literal strings “IGNOU”+ ”Conducts” + ”Java” + “Seminar”

  26. AN OVERVIEW OF JAVA (CONTD..) : STRINGS: • STRING CLASS IS A JAVA CLASS. AN INSTANCE OF A STRING CLASS IS OF COURSE AN OBJECT. IN JAVA EACH AND EVERY STRING IS AN OBJECT. • STRINGS ARE NOT ARRAY OF CHARACTERS IN JAVA AS C-LANGUAGE.

  27. AN OVERVIEW OF JAVA (CONTD...) STRING: String class methods: booleans equals (String object) int length ( ) char charAt(int index)

  28. AN OVERVIEW OF JAVA (CONTD...) STRING: EXAMPLE 1: String methods class Stringmethods{ public static void main ( String[ ] args){ string strobj1 = “first string”; string strobj2 = “second string”; string strobj3 = strobj1; System.out.println (“Length of Strobj1:” + Strobj1.length( )); System.out.println (“Char at index 3 in strolbj1:”+strobj1.charAt (3)); If (strobj1.equals (strobj2)) System.out.println (“strobj1 == strobj2”); else System.out.println (“strobj1!= strobj2”); } }

  29. AN OVERVIEW OF JAVA (CONTD...) STRING: EXAMPLE :Character counting program class CountChar{ public static void main(String[ ] args) { throws java.io.IOException { int count = 0; while(System.in.read( )!= -1) count++; System.out.println(“Input has”+counts+”chars”); } }

  30. AN OVERVIEW OF JAVA (CONTD...) EXPLANATION : Throws java.io.exception • This statement specifies that the main method can throw an exception called java.io.IOException. An exception is an event that occurs during the execution of a program that prevents the continuation of the normal flow of instructions. • Main method does not throw any exception directly. But it can throw a java.io.IOException indirectly throgh its call to System.in.read.

  31. AN OVERVIEW OF JAVA (CONTD...) System.in.read This method reads a single char and returns either the char that was read or, if there are no more characters to be read, -1.

  32. AN OVERVIEW OF JAVA (CONTD...) FLOW CONTROL STATEMENTS SWITCH SYNTAX • SWITCH STATEMENT IS IDENTICAL TO 'C' Switch (expression) { case value1: statement(s); break; case value2: statement(s); break; default: statement(s); break; }

  33. AN OVERVIEW OF JAVA (CONTD...) FLOW CONTROL STATEMENTS (Contd. …) Breaking out of Loops • Break • Continue • Break & Continue with Label • Without the Label, they are the same as C or C++

  34. OBJECT ORIENTED PROGRAMMING IN JAVA Creating, Declaring & Instantiating an object: Date tomorrow = new Date( ); This single statement actually performs three functions: Declaration : Instantiation: Initialisation

  35. OBJECT ORIENTED PROGRAMMING IN JAVA (Contd....) Declaration of an object: Date tomorrow; Instantiation of an object: The new operator instantiates a class by allocating memory for a new object of that type. The new requires a single argument: a call to a constructor method.

  36. OBJECT ORIENTED PROGRAMMING IN JAVA (Contd...) Declaration of an object: Constructor methods are special methods provided by each Java class that are responsible for initializing new objects of that type. The new operator creates the object and the constructor initializes it. The Date( ) Constructor used in Date tomorrow = new Date( ) does not take any argument.

  37. OBJECT ORIENTED PROGRAMMING IN JAVA (Contd...) A constructor that takes no argument is called default constructor. Like Date( ), most classes have at least one default constructor. If a class has multiple constructors, they all have the same name but different number or types of arguments. Date class type provides with another constructor that initialises the new Date with a year, month & day. Date HisBirthday = new(1971, 6, 30);

  38. AN OVERVIEW OF JAVA (Contd...) OOP : GARBAGE COLLECTOR • No need of keeping track of objects for destroying. • The Java runtime environment has a garbage collector that frees the memory used by objects that are no longer needed.

  39. AN OVERVIEW OF JAVA (Contd...) OOP : GARBAGE COLLECTOR • An object is eligible for garbage collection when there are no more references to objects. • The garbage collector run in a low-priority thread and runs both synchronously and asynchronously depending on the situation and the system on which Java is running.

  40. AN OVERVIEW OF JAVA (Contd...) OOP : CLASS DECLARATION A class declaration looks like this: [modifiers] class ClassName [extends SuperClassName] [implements Interface Names]{ -------- } The items between the square are optional. • modifiers declares whether the class is public, abstract or final. • extends is used to specify a single inheritance mechanism. • Implements is used to specify multiple inheritance.

  41. AN OVERVIEW OF JAVA (Contd...) OOP : Declaring a class’s superclass • In Java, every class has a superclass. If you don’t specify a superclass for your class it is assumed to be the Object class (declared in Java.lang). • The keyword extends is used to specify the superclass. Class NameOfClass extends SuperClassName { ---------- ---------- }

  42. AN OVERVIEW OF JAVA (Contd...) OOP : Public, Abstract and Final Class • The Public modifier declares that the class can be used by objects outside the current package. • The abstract modifiers declares that the abstract class may contain methods (without any implementation). These classes are intended to be sub-classed and can not be instantiated.

  43. AN OVERVIEW OF JAVA (Contd...) OOP : Public, Abstract and Final Class (Contd...) • The Final modifier declares that this class can not be sub-classed for security reasons & design reasons. • It does not make sense for a class to be both final and abstract.

  44. AN OVERVIEW OF JAVA (CONTD...) Object Oriented Program Package: • A package is a container of related classes and interfaces • Used to access related classes as well as to hide the internals of a package • Package is declared using package keyword • Package my-package; • Package java.awt.image; • All of Java built-in classes are put under the Java package. Six sub packages are defined under the Java package • Java.lang, Java.awt, Java.io, Java.net, Java.applet, Java.util

  45. AN OVERVIEW OF JAVA (CONTD...) Object Oriented Feature (Contd. …) • The Import Statement • The Import statement loads existing classes for using their definition and methods Example: • Importing the class from the package: import Java.awt.Graphics; • Importing the entire package that the class belongs to: Import Java.awt.*.

  46. JAVA OVERVIEW(CONTD…) OOP : Access control mechanism: • PRIVATE • PROTECTED • PUBLIC • STATIC • FINAL • ABSTRACT

  47. JAVA OVERVIEW (CONTD…) OOP : Access control mechanism:PRIVATE: • A PRIVATE MEMBER AND METHOD ARE ACCESSIBLE ONLY TO THE CLASS IN WHICH IT IS DEFINED. EXAMPLE: class Alpha { private int privateX; private void privateMethod( ){ System.out.println(“PrivateMethod”); } } Contd. ...

  48. JAVA OVERVIEW (CONTD…) OOP : Access control mechanism:PRIVATE: Class Beta { void accessMethod ( ) { Alpha a = new Alpha ( ) ; a.privateX = 15; // illegal a.privateMethod ( ) ; // illegal } } Beta class cannot access private variable and private methods on an object of type Alpha because Beta is not the type of Alpha.

  49. JAVA OVERVIEW (CONTD…) OOP : Access control mechanism:PRIVATE: objects of same type can access to one another’s private members This is because access restriction apply at the class or type level rather than at the object level. example: class Alpha { private int privateX ; boolean isEqualTo (Alpha anotherAlpha) { if (this.privateX= =anotherAlpha.privateX) //legal return true; else return false; } } this is a java language keyword that refers to the current object.

  50. JAVA OVERVIEW (CONTD…) Protected • It allows the class itself, subclasses anc all classes in the same package to access the members. Package Greek ; Class Alpha { //declared in a Greek package protected int protectX ; protected void protectedMethods ( ) { system.out.println(“protectedMethods” ) } } Contd. ...

More Related