Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1 FOUNDATIONS OF JAVA

Similar presentations


Presentation on theme: "Chapter 1 FOUNDATIONS OF JAVA"— Presentation transcript:

1 Chapter 1 FOUNDATIONS OF JAVA
Java Programming Chapter 1 FOUNDATIONS OF JAVA

2 Agenda 1.1 Computer Systems 1.2 Programming Languages
1.3 Stage for Java 1.4 Origin of Java 1.5 Challenges of Java 1.6 Java Features 1.7 Java Program Development 1.8 Object-oriented Programming

3 1.1 Computer Systems A computer is an electronic machine that accepts data in a variety of formats, as input The basic components of computers are Internal memory Processor Storage devisés Peripheral devices Communication devices

4 Computer Systems (Contd.)

5 Computer Systems (Contd.)
The Internal Memory represented by Random Access Memory (RAM) is used to store instructions and data. The Processor, earlier known as Central Processing Unit (CPU), is capable of controlling the entire computer system. The instructions stored in the internal memory are fetched, decoded and executed by the processor.

6 Computer Systems (Contd.)
Calculations and comparisons are done in the ALU. Peripheral devices, also called input/output devices, communicate between the user and the processor. Storage devices are termed non-volatile or stable memory, and are used to store instructions and data. Communication devices connect the computer to other machines using LAN/WAN. A computer may be connected to the Internet easily via a modem using a telephone line.

7 1.2 Programming Languages
A program is a collection of instructions executed by a computer to perform a specific job. Programs stored in the computer’s internal storage are executed in the processor and the result is displayed in the output device. Programming is the process of taking an algorithm and encoding it into a notation using a programming language. It provides language constructs to solve the problem and offers data types to handle data.

8 Programming Languages (Contd.)
Programming languages are classified into various types Machine Level Language (MLL) Assembly Level Language (ALL) High Level Language (HLL) Computers can understand 0 and 1 and MLL is also written using 0 and 1. Hence the processor can understand only MLL.

9 Programming Languages (Contd.)
ALL - the instructions are represented as two parts, but the operation part is written in symbolic operation code such as ADD, SUB, etc. The data part is accessed symbolically from the processor registers or memory. HL languages are called procedural languages. Compiler, which is software that translates HLL programs into MLL programs.

10 Programming Languages (Contd.)
Two leading approaches to programming, or programming paradigms Procedural Programming Object-Oriented Programming (OOP) Procedural approach gives a sequence of organized steps and processes within its programming context to build a program. OOP solves a problem using objects. An object is a component that knows how to perform certain tasks and how to interact with other parts of the program.

11 1.3 Stage for Java The main reasons for the popularity of Java are the platform independence and the vibrant and interactive web environment it provides. Java derives its syntax from C and object-orientation from C++. Similarities and differences – C/C++ and Java C++ is platform dependent while Java is platform independent. C++ was used mainly for systems programming, but Java is used for application programs. C++ uses the goto statement, while Java does not support the goto statement.

12 Stage for Java (Contd.) Similarities and differences – C/C++ and Java
C++ supports multiple inheritances, but Java does not support multiple inheritances C++ supports operator overloading, while Java does not support operator overloading. C++ supports pointers, but Java supports pointers implicitly. C++ programs are only compiled but in Java, the programs are first compiled and then interpreted. C++ support call by value and call by reference, but Java supports only call by value.

13 Stage for Java (Contd.) Similarities and differences – C/C++ and Java
In C++ there is no provision for threads but Java provides built-in support for thread handling Memory de-allocation in C++ is done by calling its destructors. In Java, that is taken care of by Garbage Collection. A few features of C++ are not supported by Java for security purposes, because the language is for the Internet.

14 1.4 Origin of Java The Internet is a collection of various computers on different platforms and thus the need was felt for a language to handle communication between computers across platforms. Java was developed by a team from Sun Microsystems in 1991, led by James Gosling. Java was initially designed for programming home appliances such as washing machines, microwave ovens, televisions, etc.

15 Origin of Java (Contd.) C ++ was taken as the model for designing a new language, which was called “Oak”. There were two challenges facing the development team. The first was that the appliances were controlled by various types of processors chip and there was need for a common language to work on these processors. The second was that the compiler to be used in the home appliances needed a huge investment. The programs developed for these machines were to be executed with the help of a compiler and executed to control the appliances.

16 Origin of Java (Contd.) The development team adopted a two-step process. The first step was to translate the programs written for the appliances to an intermediate code, which was the same for all appliances. The second step was to execute the intermediate code in a step-by-step manner for a particular appliance. Programs written for one computer may not work on another computer. In that context, portability is a great asset for programming. Writing a program for one computer and executing it on another is called portability.

17 Origin of Java (Contd.) The two-step process was adopted for programming. The first step is that the program written is translated by a Java compiler into standardized machine language called bytecode which is the same for all computers. The bytecode is a machine-independent intermediate code. The second step is to translate this bytecode into machine language using an interpreter for a particular computer. The bytecode is interpreted and executed on any platform having a Java Virtual Machine (JVM).

18 Origin of Java (Contd.) To run the bytecode, it needs a JVM that serves as a language interpreter. The JVM reads the bytecode instructions and translates, instruction by instruction, into machine language codes that are executed by a particular computer. Java programs are translated by the compiler into bytecode, which is common to all types of computers. The JVM for Windows interprets the bytecode for Windows.

19 Origin of Java (Contd.)

20 Origin of Java (Contd.) “Oak” had already been claimed and they changed the name to Java. Java is now owned by Oracle Corporation. In 1994, Patrick Naughton and Jonathan Payne developed HotJava, which is a web browser to execute Java programs in the Internet. That is why Java is known as the programming language for the Internet.

21 Origin of Java (Contd.) There are two types of programs in Java, namely, applications and applets. The standalone program written for any common problem is called an application and it does not need a browser to run. The program executed in a browser is called an applet. An applet is a program designed to be executed within a Java compatible browser or applet viewer.

22 1.5 Challenges of Java Security Portability
The applet executed by the JVM will not allow access to authorized parts of the computer. Hence, an applet will not harm the computer and the fact that security is not broken is an important feature of Java. Portability Portability means being able to write a program once and run it anywhere. It facilitates programs being executed on any platform without making changes to the code. Java is portable, which makes its applications run on any platform.

23 Challenges of Java (Contd.)
Platform Independence Java is not compiled into a platform-specific code; rather, it results in platform independent bytecode. The bytecode is supported by any computer which has JVM installed, which makes Java a platform independent language.

24 1.6 Java Features Java Simple Object-oriented Compiled
Architectural neutral Multi-threaded Garbage collection Robust Extensible language

25 1.7 Java Program Development
JDK is an open source and can be installed from the url But to begin learning Java, it may be better to use JDK from Oracle with a simple text editor like Notepad. After learning Java to implement application or applet use NetBeans IDE, which can be downloaded from

26 Java Program Development (Contd.)

27 Object-oriented Programming
Object is a concept or abstract or thing with boundaries and gives meaning to the problem. Objects have two purposes: to promote understanding of the real world to provide practical basics for implementation. An object contains data and methods which manipulate this data. The class provides a template for the objects.

28 Object-oriented Programming (Contd.)

29 Object-oriented Programming (Contd.)

30 Object-oriented Programming (Contd.)

31 Object-oriented Programming (Contd.)
In OOP, the data is protected and can be accessed only by the intended users, that is, an unauthorized user cannot use the data in an object. OOP involves three main concepts that are the backbone of OOP: Encapsulation Inheritance Polymorphism

32 Encapsulation Encapsulation allows the programmer to hide inside the object both the data and the methods that act on that data. Encapsulation is the concept of binding data and methods together and it prevents unauthorized access. To access the data, developers use controlled access through the method which acts as an interface.

33 Inheritance Inheritance provides reusability by defining a new class from an already defined class. It allows creating a class that is similar to a previously defined class; the new class can also have its own data members and methods. The new class inherits its characteristics from the defined base class and the new class also has its own members. In OOP, a base class is seen as a parent and a derived class as a child.

34 Polymorphism Polymorphism is the ability of an object to take on many forms. Polymorphism is derived from two Greek words: poly and morphs. The word “poly” means many and “morphs” means forms. So polymorphism means many forms. Polymorphism principle is implemented with method overriding concept of java.

35 Polymorphism (Contd.) Polymorphism principle is divided into two sub-principles. They are: Static polymorphism Dynamic polymorphism Static binding is also called as early binding or compiler time binding. Overloading is compile time polymorphism where more than one methods share the same name with different parameters or signature and different return type.

36 Polymorphism (Contd.) Dynamic binding is also called as late binding or run-time binding. Dynamic polymorphism is the polymorphism that exists at run-time. Here, Java compiler does not understand which method is called at compilation time. Only JVM decides which method is called at run-time. Method overloading and method overriding using instance methods are the examples for dynamic polymorphism.


Download ppt "Chapter 1 FOUNDATIONS OF JAVA"

Similar presentations


Ads by Google