O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Unit1 introduction to Java

Carregando em…3

Confira estes a seguir

1 de 49 Anúncio

Mais Conteúdo rRelacionado

Diapositivos para si (20)

Semelhante a Unit1 introduction to Java (20)


Mais de DevaKumari Vijay (20)

Mais recentes (20)


Unit1 introduction to Java

  1. 1. Introduction to Java
  2. 2.  Java is one of the world's most important and widely used computer languages, and it has held this distinction for many years.  Java is Object oriented programming language.  Helps to create modular programs and reusable code.  Java is free to access and can run on all platforms.  Java was developed by James Gosling, Patrick Naughton, Mike Sheridan at Sun Microsystems Inc. in 1991.  The initial name was Oak but it was renamed to Java in 1995 as OAK was a registered trademark of another Tech company. Overview Of Java
  3. 3.  Java was initially launched as Java 1.0 but soon after its initial release, Java 1.1 was launched. Java 1.1 redefined event handling, new library elements were added.  In Java 1.2 Swing and Collection framework was added and suspend(), resume() and stop()methods were deprecated from Thread class  JAVA EDITIONS.  J2SE(Java 2 Standard Edition) - to develop client-side standalone applications or applets.  J2ME(Java 2 Micro Edition ) - to develop applications for mobile devices such as cell phones.  J2EE(Java 2 Enterprise Edition ) - to develop server-side applications such as Java servlets and Java ServerPages. Evolution Of Java
  4. 4. .  Java is widely used in every corner of world and of human life  Java is not only used in softwares but is also widely used in designing hardware controlling software components.  Banking: To deal with transaction management.  Retail: Billing applications that you see in a store/restaurant are completely written in Java.  Information Technology: Java is designed to solve implementation dependencies.  Android: Applications are either written in Java or use Java API. Financial services: It is used in server-side applications.  Stock market: To write algorithms as to which company they should invest in.  Big Data: Hadoop MapReduce framework is written using Java.  Scientific and Research Community. Application of Java
  5. 5.  Developing Desktop Applications  Web Applications like Linkedin.com, Snapdeal.com etc  Mobile Operating System like Android  Embedded Systems  Robotics and games etc. Cont..
  6. 6. Features Of Java
  7. 7.  Java is easy to learn and its syntax is quite simple, clean and easy to understand.  The confusing and ambiguous concepts of C++ are either left out in Java or they have been re-implemented in a cleaner way.  It is an evolving language  Does not have complex features as other programming languages like  Operator overloading,  Multiple inheritance through classes, pointers and  Explicit memory allocation. Simple
  8. 8.  In java everything is Object which has some state and behaviour.  Java can be easily extended as it is based on Object Model.  Object oriented programming is a methododoly in which programs are organized as collection of objects, each of which represents an instance of a class Object Oriented
  9. 9.  Two main problems which cause program failures i.e memory management mistakes and mishandled runtime errors can be overcome.  Memory management mistakes can be overcome by garbage collection. Garbage collection is automatic de- allocation of objects which are no longer needed.  Mishandled runtime errors are resolved by Exception Handling procedures.  Java eliminates error prone codes by checking the code at compile time and runtime . Robust
  10. 10. Portable  Unlike other programming languages such as C, C++ etc which are compiled into platform specific machines.  Java is write-once, run-anywhere language- compiled version of class can run on any platform. Platform Independent
  11. 11.  When it comes to security, Java is always the first choice. With java secure features it enable us to develop virus free, temper free system.  Java program always runs in Java virtual machine environment with almost null interaction with system OS, hence it is more secure.  Provides a virtual firewall between the application and the computer.  Java codes are confined within Java Runtime Environment (JRE).  No use of explicit pointers. Secure
  12. 12.  Java multithreading feature makes it possible to write program that can do many tasks simultaneously. Benefit of multithreading is that it utilizes same memory and other resources to execute multiple threads at the same time, like While typing, grammatical errors are checked along. Multi Threading
  13. 13.  Compiler generates bytecodes, which have nothing to do with a particular computer architecture, hence a Java program is easy to intrepret on any machine.  Once compiled Java class file can run on any platform Architectural Neutral
  14. 14. JAVA COMPILER JAVA BYTE CODE JAVA INTERPRETER Macintosh Solaris Windows Vista (translator) (same for all platforms) (one for each different system) Windows 7
  15. 15.  Java Byte code can be carried to any platform. No implementation dependent features.  Everything related to storage is predefined, example: size of primitive data types  Byte codes are interpeted by JVM Portable
  16. 16.  Java is an interpreted language, so it will never be as fast as a compiled language like C or C++. But, Java enables high performance with the use of just-in-time compiler. High Performance
  17. 17.  C is a structured language and Java is an object oriented language and has mechanism to define classes and objects.  Java does not support an explicit pointer type  Java does not have preprocessor, so we cant use #define, #include and #ifdef statements.  Java does not include structures, unions and enum data types.  Java does not include keywords like goto, sizeof and typedef.  Java adds labeled break and continue statements. C Language and Java Compared
  18. 18.  Java does not support operator over loading.  Java does not perform automatic type conversions that result in loss of precision.  Java does not support global variables. Every method and variable is declared within a class and forms part of that class.  Java does not allow default arguments.  Java does not support inheritance of multiple super classes by a sub class (i.e., multiple inheritance). This is accomplished by using “interface” concept.  It is not possible to declare unsigned integers in java.  In java objects are passed by reference only. In C++ objects may be passed by value or reference. C++ and Java Compared
  19. 19.  Multithreading, that allows two or more pieces of the same program to execute concurrently.  C++ has a set of library functions that use a common header file. But java replaces it with its own set of API classes.  It adds packages and interfaces.  Java supports automatic garbage collection.  break and continue statements have been enhanced in java to accept labels as targets.  The use of unicode characters ensures portability. NEW FEATURES ADDED IN JAVA
  20. 20. Java Runtime Environment  JRE : The Java Runtime Environment (JRE) provides the libraries, the Java Virtual Machine, and other components to run applets and applications written in the Java programming language.  JRE does not contain tools and utilities such as compilers or debuggers for developing applets and applications.  JRM=JVM+ set of libraries+ other additional fies
  21. 21. JRE
  22. 22. Java Development Kit  JDK : The JDK also called Java Development Kit is a superset of the JRE, and contains everything that is in the JRE, plus tools such as the compilers and debuggers necessary for developing applets and applications.  JDK=JRE+ Development tools
  23. 23. JDK
  24. 24.  Java virtual Machine(JVM) is a virtual Machine that provides runtime environment to execute java byte code.  The JVM doesn't understand Java pogram, that's why you compile your *.java files to obtain *.class files that contain the bytecodes understandable by the JVM.  JVM control execution of every Java program. It enables features such as automated exception handling, Garbage-collected heap. What is JVM?
  25. 25. JVM Architecture
  26. 26.  Class Loader : Class loader loads the Class for execution.  Method area : Stores pre-class structure as constant pool.  Heap : Heap is in which objects are allocated.  Stack : Local variables and partial results are store here. Each thread has a private JVM stack created when the thread is created.  Program register : Program register holds the address of JVM instruction currently being executed. Conti..
  27. 27.  Native method stack : It contains all native used in application.  Executive Engine : Execution engine controls the execute of instructions contained in the methods of the classes.  Native Method Interface : Native method interface gives an interface between java code and native code during execution.  Native Method Libraries : Native Libraries consist of files required for the execution of native code. Conti..
  28. 28.  Object  Class  Inheritance  Polymorphism  Abstraction  Encapulation Object Oriented Concepts
  29. 29.  Abstraction  Denotes the extraction of essential characteristics of an object that distinguish from all other kinds of objects.  Encapsulation  Hiding the implementation details of a class.  Forces the user to use an interface to access the data.  Inheritance  Process by which one class acquires the properties and functionalities of the other.  Polymorphism  Means the ability of methods to exist in several different forms Object Oriented Programming
  30. 30. Object 31  Objects are the basic run time entities in an object oriented system. They may represent a person, a place, a bank account, a table of data or any item that the program has to handle.  Objects have two characteristics: They have states and behaviors.  Object: Car State: Color, Brand, Model Behavior: Accelerate, Slow Down, Gear change. What is the state and behavior of this bulb?
  31. 31. A bulb: 1. It’s a real-world thing. 2. Can be switched on to generate light and switched off. 3. It has real features like the glass covering, filament and holder. 4. It also has conceptual features like power. 5. A bulb manufacturing factory produces many bulbs based on a basic description / pattern of what a bulb is. object methods member variables class Putting it together 32
  32. 32. Class 33  A class is a construct created in object-oriented programming languages that enables creation of objects.  Also sometimes called blueprint or template or prototype from which objects are created.  It defines members (variables and methods).  Characteristics of an object are represented in a class as Properties/state/variables. The actions that can be performed by objects become functions of the class and is referred to as Methods/behaviour.  A class is an abstraction.
  33. 33. class <ClassName> { attributes/variables; Constructors(); methods(); } Class syntax
  34. 34. Abstraction 35  Abstraction refers to the act of representing essential features without including the background details or explanations.  Example  For a Doctor you are a Patient  Name, Age, Old medical records  For a Teacher you are a Student  Name, Roll Number/RegNo, Education background  For HR Staff you are ______________  ___________,_____________,___________ Abstraction denotes essential characteristics of an object that distinguish it from all other kinds of objects and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer. -Grady Booch
  35. 35. Encapsulation 36  Encapsulation is binding data and operations that work on data together in a construct.  Encapsulation involves Data and Implementation Hiding. Would you like it if your CPU is given to you like this? What are the problems if it were given to you like this? Encapsulation is the process of compartmentalizing the elements of abstraction that constitute its structure and behavior; encapsulation serves to separate the contractual interface of an abstraction and its implementation. - Grady Booch
  36. 36. Class and Encapsulation Student •-roll: long • -name: String • + display(): void • + read(): boolean Rectangle • -length: int • -width:int • +area(): int LinkedList •-Node •+ addFirst(Node n) •+ remove(Node n) •+ add(Node n, int pos) - : private + : public
  37. 37. Reuse in Object Oriented Programming 38  Object Oriented programming also implements reuse in the same way that we do in real life.  Using  has-a  is-a  Has-a or composition relationship is implemented by having a class having another class as its member, or rather an object having another object as its member.  Car has a Stereo  College has Teachers and Students  Is-a is implemented through what we call inheritance relationship
  38. 38. Inheritance  Inheritance allows to reuse classes by deriving a new class from an existing one  The existing class is called the parent class, or superclass, or base class  The derived class is called the child class or subclass. The child class inherits characteristics of the parent class(i.e the child class inherits the methods and data defined for the parent class  Defines IS-A relationship between classes  Cat IS-A Animal  Car IS-A Vehicle  Rose IS-A Flower
  39. 39. Inheritance hierarchy 40 Animal legs tail run() Dog bark() Tiger growl() CatFamily paddedClaws whiskers Cat meow() Single -level Multi-level
  40. 40.  Many Object-orientated language does not support this type of inheritance.  Java, C# are the examples of object-oriented language that does not support multiple inheritance through classes. Mammal Bird Bat Multiple inheritance
  41. 41. { {Super class Subclass 42  Fruit  Library  Cat  Bird  Parrot  Music  Tiger  Books  Apple  Mango
  42. 42. Activity  Given the following classes. Can you form inheritance hierarchy?  Person  Teacher  Student  HOD  Typist  Clerk  What are the common members shared ?
  43. 43. Polymorphism A concept in type theory, according to which a name (such as a variable declaration) may denote objects of many different classes that are related by some common superclass; thus, any object denoted by this name is able to respond to some common set of operations in different ways. - Grady Booch
  44. 44. Polymorphism example Flower fragrance() Rose fragrance() Sunflower fragrance() FlowerVase Flower f[] smell()
  45. 45.  You pick a rose from the vase and smell it?  What fragrance do you expect? Flower fragrance() Rose fragrance() Sunflower fragrance() FlowerVase Flower f[] smell() f[0]= rose; f[1]= sunflower; …. f[0]. fragrance(); f[1]. fragrance(); …
  46. 46. Benefits of OOP 1. Emphasis is on data rather than procedure. 2. Programs are divided into objects. 3. Methods are reused. 4. Methods that operate on the data of an object are tied together in the data structure. 5. Data is hidden and can not be accessed by external functions. 6. Objects may communicate with each other through . 7. Good control over data, data of an object can be accessed by methods associated with the object. 8. Easy to test, upgrade and debug.
  47. 47.  Client-Server Systems(OCSI)  Object-Oriented Databases(ODBMS)  Real-Time System Design  Office Automation Systems  CAD/CAM Systems Applications of OOPs
  48. 48.  Object-oriented programming is a method of implementation in which programs are organized as cooperative collections of objects.  The object’s state is determined by the value of its properties and its behavior is determined by the operations that it provides.  Abstraction is the process of taking only a set of essential characteristics from something.  Encapsulation is binding data and operations that work on data together in a construct.  Inheritance defines relationship among classes, wherein one class share structure or behavior defined in one or more classes.  Polymorphism is using a function in many forms. Poly means ‘many’, Morphism means ‘forms’. Summary