PROGRAMMING LANGUAGE Prepared By Ddamba AbdulKarim Programming in Java BBC – II, Semester II – 2019/2020 Makerere University Business School Chapter Outline 1. Computer programming language paradigms 2. Procedural vs. object-oriented programming paradigm 3. Definition of the Java programming language 4. How Java works? 5. Origin and development of Java 6. Why Java? 7. The capabilities of Java programming language 8. Contrast between Java and JavaScript
2020 Ddamba AK The Java Programming Language BBC II-MUBS 2
Introduction to Programming • Computers solve many problems pertaining to various domains, e.g., banking, commerce, etc. • To solve a given problem by using a computer, you need to write a program for it, this is known as computer programming • Computer programming is the craft of writing, maintainable, & extensible source code which can be interpreted or compiled by a computing system to perform a meaningful task.
• A computer program is a set of step-by-step instructions that
directs and tells the computer to do the particular tasks and produce the results you want order to solve a problem.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 3
Introduction to Programming • A computer program is made up of three components; i.e. • Programming language, • Data structure and • Algorithms.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 4
Introduction to Programming • Components of a computer program • Algorithm • A set of step-by- step procedures or instructions for solving a computational problem. • Data structure • It is a way of collecting, organizing and holding program data in such a way that we can perform operations on these data in an effective way. • Programming language • A language used to write a set of instructions which are converted into machine language given to a computer for execution to perform specified tasks
2020 Ddamba AK The Java Programming Language BBC II-MUBS 5
Computer Programming Paradigms • Where do paradigms come from? • Paradigms emerge as the result of social processes in which people develop ideas and create principles and practices that embody those ideas • Programming paradigms • Style, principles and practices for using a particular programming language to writing computer programs needed to solve computational problems • Most computer languages are designed to facilitate certain operations and not others: for example; numerical computation, or text manipulation, or i/o.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 6
Types of programming paradigms • There are a number of alternative approaches to the programming process and these include; • Imperative / procedural • Logic • Functional / applicative • Scripting • Object-oriented • Declarative • Concurrent • Two of the most important programming approaches are; • Procedural paradigm and the • Object-oriented paradigm.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 7
Procedural vs Object-oriented • Procedural-oriented programming, also known as “imperative programming” is where; • A computer program is divided into small parts called procedures or functions or set of subroutines. • These are groups of logically related program instructions or algorithms for a computer to follow to accomplish a particular task in a step-by-step order.
• These procedures (functions) are called repeatedly in a
program to execute tasks performed by them to produce a given result.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 8
Procedural vs Object-oriented • Procedural-oriented programming, • For example, a program may involve; • Collecting data from user (reading), • Performing some kind of calculations on the collected data (Calculation), and • Finally displaying the result to the user when requested (printing). • All the 3 tasks of reading, calculating and printing can be written in a program with the help of 3 different functions which performs these 3 different tasks.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 9
Procedural vs Object-oriented • Procedural-oriented programming,
2020 Ddamba AK The Java Programming Language BBC II-MUBS 10
Procedural vs Object-oriented • Procedural-oriented programming,
• In a multi-function program, some important data is
placed as global data, so that they may be accessed by all the functions. • Each function may have its own data
2020 Ddamba AK The Java Programming Language BBC II-MUBS 11
Procedural vs Object-oriented • Features of Procedural-oriented programming, • Emphasis is placed on doing things, i.e. process (algorithms), rather than the data • Large programs are divided into smaller programs known as functions/ procedures/ sub-routines • Most of the functions share global data • Data move freely and openly around the system from function to function • Functions transform data from one form to another • Employs a top-down approach in program design
2020 Ddamba AK The Java Programming Language BBC II-MUBS 12
Procedural vs Object-oriented • Examples of Procedural-oriented programming,
2020 Ddamba AK The Java Programming Language BBC II-MUBS 13
Procedural vs Object-oriented • Limitations of Procedural-oriented programming, • Importance is given to the procedures on data rather than the data being used by functions. That is, the data is defined independently of the procedures. • Data is exposed to whole program at once, so there is no security of data available. Any function can modify the data and it may be hard to identify which function is using what kind of data • Procedures are often hard to reuse, because, the function is likely to reference the global variables and other functions.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 14
Procedural vs Object-oriented • Limitations of Procedural-oriented programming, • Programs are often hard to extend, maintain (update). • In the cases of large and more complex, program changes becomes more difficult and time consuming • For example; if a change is required to the program, the developer has to change every line of code that links to the main function. • Programs are often hard to debug • In case one function accidentally changes the global data, it will be too difficult to debug & identify which function is causing the problem if the program is really big. 2020 Ddamba AK The Java Programming Language BBC II-MUBS 15 Procedural vs Object-oriented • Limitations of Procedural-oriented programming, • It doesn’t model the real-world problems very well • It is because functions are action-oriented and do not really correspond to elements of the problem • It is therefore difficult to design because the components function and data structure do not model the real world. • It is difficult to create new data types • The ability to create the new data type of its own is called extensibility. • Procedure programming languages are not extensible
2020 Ddamba AK The Java Programming Language BBC II-MUBS 16
Procedural vs Object-oriented • Object-oriented programming, • The major motivating factor in the invention of object- oriented approach is to remove some of the flaws encountered in the procedural approach • OOP treats data as a critical element in a program development and doesn’t allow it to flow freely around the system • It ties/ encapsulates data more closely to the functions (methods) that operate on it, and protects it from accidental modification from outside functions • OOP decomposes a program into entities called Objects and then builds data and functions around these objects
2020 Ddamba AK The Java Programming Language BBC II-MUBS 17
Procedural vs Object-oriented • Object-oriented programming, • The data of an object can be accessed only by the functions associated with the object. • However functions of one object can access functions of other objects 2020 Ddamba AK The Java Programming Language BBC II-MUBS 18 Procedural vs Object-oriented • Characteristics of OO programming, • Emphasis is placed on the data rather than the procedures • Program is divided into objects • Designed data structures characterize objects • Functions that operate on the data of an object are tied together in the data structure • Data is hidden & cannot accessed by external functions • New data and functions can easily be added • Follows bottom-up approach in program design 2020 Ddamba AK The Java Programming Language BBC II-MUBS 19 Procedural vs Object-oriented • Characteristics of OO programming, • The OOP relies on the following concepts and principles that are used extensively in program design; • Objects • Classes • Methods • Message passing • Constructors • Data abstraction • Encapsulation • Polymorphism and inheritance
2020 Ddamba AK The Java Programming Language BBC II-MUBS 20
Procedural vs Object-oriented • Examples of Object-oriented programming, • Two examples of popular object-oriented programming languages are Java and C++. • Some other well-known object-oriented programming languages include;
2020 Ddamba AK The Java Programming Language BBC II-MUBS 21
Procedural vs Object-oriented • Advantages of Object-oriented programming, • Data control and Security • Data can’t freely move from one method to another. • Access and sharing of the internal object data by external functions is restricted in OOP using access specifiers, such as public, private, and protected etc. • This feature of data hiding is called as "data encapsulation". • This principle of data hiding helps the programmer to build a secure program that cannot be invaded by code in other part of the program
2020 Ddamba AK The Java Programming Language BBC II-MUBS 22
Procedural vs Object-oriented • Advantages of Object-oriented programming, • Ease of modification and maintainability • New objects can be created with small differences to existing ones. • Still, new data and methods can easily be added with little strain to programmers. • Ease in software design • Software objects model real-world objects, so the complexity is reduced and the program structure is very clear • This enables easy analysis of the user requirements.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 23
Procedural vs Object-oriented • Advantages of Object-oriented programming, • Code reusability • With the help of inheritance, the existing classes can be re-used to derive a new class such that the redundant code is eliminated and the use of existing class is extended. This saves time and cost of program. • Program modularity • It provides modular structure for programs in which each object forms a separate entity whose internal workings are decoupled from other parts of the system. • This makes it good for defining abstract datatypes in which implementation details are hidden
2020 Ddamba AK The Java Programming Language BBC II-MUBS 24
Procedural vs Object-oriented • Advantages of Object-oriented programming, • Faster development • Reuse also enables faster development. Object-oriented programming languages come with rich libraries of objects, and code developed during projects is also reusable in future projects. • Program extensibility • Adding new features or responding to changing operating environments can be solved by introducing a few new objects and modifying some existing ones
2020 Ddamba AK The Java Programming Language BBC II-MUBS 25
The Java Programming Language • Java was developed by James Gosling from Sun Microsystems in 1995 as an Object-oriented language. • It is used for programming general-purpose business applications and for interactive, web-based internet applications. • Today java programming language is one of the most popular programming language which is used in critical applications like stock market trading system on BSE, banking systems or android mobile application.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 26
What is Java? • Java is a programming language and a platform • Java as a Programming Language • It is one of today’s most popular software development languages
• It is a high-level, general-purpose, and object-oriented
language that is expressly used to write computer programs for use in a cross-platform computing environment
• Java is not only used for developing distributed web
applications, but also for developing standalone applications across platforms on webservers, desktops, embedded devices and mobile devices, even control the robotic devices.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 27
What is Java? • Java is a programming language and a platform • Java as a Computing Platform • A platform is any hardware or software environment in which a program runs. • Java is a platform because it has its own set of programs, i.e. Java runtime environment (JRE) and API that help develop and run programs written in the Java programming language. • Java platform includes an execution engine, a compiler, and a set of libraries. • JAVA is platform-independent language, that is, it is not specific to any processor (CPU) or operating system.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 28
How Java Programs Works? • Before we look at how Java works, lets first examine how conventional languages work. • In other conventional programming languages • The source code is directly translated (compiled or interpreted) to native (machine) code, at runtime for execution by the computer.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 29
How Java Programs Works? • HOWEVER…in Java…. • A computer program (source code) written in java is not directly translated (compiled or interpreted) into the machine codes, rather into an intermediate program codes called bytecode. • These bytecodes are translated (executed or run) by the Java Virtual Machine (JVM) into machine codes for the respective machine. • They are not executed on and by the hardware itself • This JVM is included in the JDK/JRE (Java software) package which you download and install on your computer
2020 Ddamba AK The Java Programming Language BBC II-MUBS 30
How Java Programs Works? • HOWEVER…in Java….
2020 Ddamba AK The Java Programming Language BBC II-MUBS 31
How Java Programs Works? • HOWEVER…in Java…. • Java code needs to be translated twice in order to be executed: • First translation – Java programs need to be compiled to bytecode.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 32
How Java Programs Works? • HOWEVER…in Java…. • Java code needs to be compiled twice in order to be executed: • Second translation – When the bytecode is run, it needs to be converted to machine code.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 33
Origin and Development of Java • 1990: • Java started as an internal research project in 1990 at Sun Microsystems Inc., named the Green Project. • The Green Project team of 13 software engineers including Patrick Naughton , Mike Sheridan was led by James Gosling. • They wanted a language that would be easy to port to all different types of micro-controlled consumer electronic computer devices such as; video game- consoles, TV set-top boxes, VCRS, toasters, microwaves etc.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 34
Origin and Development of Java • James Arthur Gosling • A Canadian computer scientist • The founder and lead designer behind the Java programming language
2020 Ddamba AK The Java Programming Language BBC II-MUBS 35
Origin and Development of Java • 1990: • Initially created for micro-controlled computer devices
2020 Ddamba AK The Java Programming Language BBC II-MUBS 36
Origin and Development of Java • 1990: • Primary goals for Java development 1. To use the object-oriented programming methodology. 2. To allow the same program to be executed on multiple operating systems. 3. To contain built-in support for using computer networks. 4. To execute code from remote sources securely. 5. To be easy to use by selecting what was considered the easy parts of other OO languages. • It was too motivated by the frustrations caused by C, and C++, e.g.; Platform dependence, complexity etc.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 37
Origin and Development of Java • 1991: language named OAK • Gosling attempted to modify and extend C++ but he ends up with many problems • He quickly abandoned this approach in favor of creating an entirely new language. • The new language took 18 months to finish. By the fall of 1992, the team was able to present their new language. • Gosling called it oak, in honor of an oak tree that could be seen from his office window.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 38
Origin and Development of Java • 1992: The Green Project becomes First-person Inc. • The Green project evolved into another company known as First-person Inc., which was still under Sun Microsystems Inc. • The OAK language was directed toward building highly interactive applications for set-top devices for Time Warner company, a Cable TV industry.
• 1993: Oak becomes Unsuccessful
• The idea of building highly interactive devices for the cable TV industry failed to materialize because the OAK was too advanced for digital micro devices 2020 Ddamba AK The Java Programming Language BBC II-MUBS 39 Origin and Development of Java • 1994: OAK is Re-targeted for the Internet • The team redirected the OAK towards creating the same embeddable technology to be used in web- based Internet applications at that time.
• 1995: OAK is renamed to Java
• The green team met at a local coffee shop to come up with another name, the team-members suggested names like silk, DNA, ruby, WRL, revolutionary, jolt, dynamic and java • OAK was renamed Java after a trademark search revealed that OAK was used by OAK technology. 2020 Ddamba AK The Java Programming Language BBC II-MUBS 40 Origin and Development of Java • 1994: OAK is Re-targeted for the Internet • A small browser called HotJava was written
2020 Ddamba AK The Java Programming Language BBC II-MUBS 41
Origin and Development of Java • 1995: Oak renamed to Java • Java is just a name not an acronym, it is an island of Indonesia where first coffee was produced (called Java coffee). This also tells the story behind the logo of Java.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 42
Origin and Development of Java • 1995: Java is publicly released • Java would see its first public launch at the Sunworld conference event on May 23, 1995. • 1996: The first JDK was released • The first java development kit, JDK 1.0, was unveiled in January 23 1996. • The Java language has undergone several changes. The Java community process (JCP) has governed the overall evolution of the language. • The JCP uses java specification requests to specify any additions or changes to the platform.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 43
Origin and Development of Java • Oracle acquires Sun Microsystems Inc. in 2009 • In 2009, Oracle Corporation acquired Sun Microsystems Inc. and took ownership of java.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 44
Origin and Development of Java • Java as of Today. • Today, Java is one of the most popular programming languages in use • It is an invisible force behind many of the applications and devices that power our day-to-day lives, particularly; • Client-server web applications, • Mobile applications for handheld devices, • Games • Navigation systems, • Embedded systems etc. 2020 Ddamba AK The Java Programming Language BBC II-MUBS 45 Features of Java Language
2020 Ddamba AK The Java Programming Language BBC II-MUBS 46
Features of Java Language • Java is Simple and User-friendly • Java is partially modeled on C++, but greatly simplified and improved • Some programmers refer to Java as “C++”, because it is like C++, but with more functionality and fewer complicated features which were removed like explicit pointer, multiple inheritance etc. • If you are familiar with C++, learning Java will be particularly easy for you, because you have most of the foundation already.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 47
Features of Java Language • Java is Object-oriented • Computer programs are organized as a combination of different types of objects that incorporates both data and behavior. • Object-oriented programming provides great flexibility, modularity, clarity, and code-reusability through; classes and objects, data abstraction, encapsulation, inheritance, and polymorphism.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 48
Features of Java Language • Java is Distributed • Distributed computing involves several computers working together on a network. • Since networking capability is inherently integrated into Java, it can be used to develop client-server network applications e.g. Web-based applications that execute remotely from the server on client computer. • Java has in-built support for socket programming, remote method invocation (RMI), Java beans (EJB) and JavaEE (Java Enterprise Edition) to develop enterprise-class distributed application in java.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 49
Features of Java Language • Java is Architecture Neutral • Java can run on any of the processor or CPU under different environments irrespective of their architectural and vendor for which there’s java installed (java run-time system). • The Java compiler generates byte codes, which have nothing to do with a particular CPU architecture. • Therefore Java programs can be executed on any CPU machine, e.g. , those found in micro cards, servers, personal computers, super computers, embedded devices, video gaming consoles, etc
2020 Ddamba AK The Java Programming Language BBC II-MUBS 50
Features of Java Language • Java is Interpreted • You need an interpreter to run Java programs. • The programs are compiled into the Java Virtual Machine code called bytecode. • The bytecode is machine-independent and can run on any machine that has a java interpreter, which is part of the Java Virtual Machine (JVM). • Java is Portable • Because Java is architecture neutral, Java programs are portable. They can be run on any platform without being recompiled
2020 Ddamba AK The Java Programming Language BBC II-MUBS 51
Features of Java Language • Java is Portable • Java achieves portability because of Bytecodes • Byte code is a highly optimized set of instructions only executed by Java Run-time System, which is called the Java Virtual Machine (JVM). • JVM converts byte code of Java into machine language to execute on any microprocessor of an operating system without being recompiled • The JVM is platform dependent and java byte code is platform independent.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 52
Features of Java Language • Java is Platform-independent • A platform is the hardware or software environment in which a program runs. • There are two types of platforms software-based and hardware-based. Java provides software-based platform. • The Java platform differs from most other platforms in the sense that it is a software-based platform that runs on the top of other hardware-based platforms. • It has two components: e.g. Runtime Environment (JVM) and API (Application Programming Interface) 2020 Ddamba AK The Java Programming Language BBC II-MUBS 53 Features of Java Language • Java is Platform-independent • Java is not tied to a specific software platform (OS) unlike other programming languages such C, VB etc. • Java source code is compiled into the Bytecode that can be run on multiple platforms e.g. Windows, Linux, Sun, Solaris, and Mac OS etc. for which Java Virtual Machine is installed • The Java compiler does not produce machine code for a particular machine like a VB compiler does. Instead it produces a special format called byte code written in hexadecimal, byte by byte
2020 Ddamba AK The Java Programming Language BBC II-MUBS 54
Features of Java Language • Java is Platform-independent • Illustrating Java’s Platform-independence • Java is Write Once and Run Anywhere (WORA). • Any machine with Java Runtime Environment can run Java Programs.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 55
Features of Java Language • Java is a Secure Language • Java is a secure language because; • Use of access specifiers/ modifiers, e.g. Private, Protected and Public to limit access to memory locations (variables) without proper authorization • Java uses a Bytecode Verifier to ensure that no viruses are communicated with its programs. The Bytecode verifier is part of the JVM responsible to verify all the Java bytecodes before they are loaded into memory. • Java’s security manager determines what resource a class can access such as reading and writing to the local disk. 2020 Ddamba AK The Java Programming Language BBC II-MUBS 56 Features of Java Language • Java is a Secure Language • Java is a secure language because; • Program run inside Virtual Machine Sandbox without direct interaction with a computer’s to prevent any untrusted codes.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 57
Features of Java Language • Java is a Robust Language • Java provides the following safe grounds to ensure writing of reliable and error-free code that must execute reliably in a variety of systems. • Java is strongly typed language. It has a strict compile-time error checking and elimination mechanism for data types in program during the execution. • Java has a Runtime Exception-handling System that tracks down bugs that often turn up in run-time or execution situations. • Java uses strong and better memory management system (garbage collector) that automatically allocates and de- allocates memory to objects
2020 Ddamba AK The Java Programming Language BBC II-MUBS 58
Features of Java Language • Java is Dynamic • Java was designed to adapt to an evolving environment. • New code can be loaded on the fly without recompilation. • There is no need for developers to create, and for users to install, major new software versions. • New features can be incorporated transparently as needed.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 59
Features of Java Language • Java is Multithreaded • A thread is like a separate program, executing concurrently. • Java programs can be written to deal with many processes at once by defining multiple threads resulting in highly interactive and responsive applications with real-time behaviour • The main advantage of multi-threading is that it doesn't occupy memory for each thread. It shares a common memory area. • Threads are important for multi-media, web applications etc.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 60
Features of Java Language • Java is High Performant • Java uses bytecode which is more faster than ordinary pointer code so performance of this language is high. • It uses a garbage collector, to collect the unused memory space and improve the performance of application. • It has no pointers so that using this language we can develop an application very easily. • It supports multithreading, because of this time consuming process can be reduced to execute the program. 2020 Ddamba AK The Java Programming Language BBC II-MUBS 61 Features of Java Language • Java is High Performant • Java uses a Java interpreter that, translates the bytecodes line by line into underlying machine code for execution by any computing system that implements the Java virtual machine (JVM) without the need for a re-compilation. • To achieve higher performance, Java uses two kinds special interpreters knows as; • Just-in-time (JIT) Compiler and • Ahead-of-time Compiler.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 62
Features of Java Language • Java is High Performant • The just-in-time (JIT) compiler is special type of interpreter that comes with the Java virtual machine • It is directly and immediately translates the bytecodes into machine code when it is needed (just-in-time), not before runtime. • It caches (stores) and reuses the instructions that have been previously interpreted to machine code, and reuses them on the successive execution, thus saving time & resources by not having to re-interpret statements
2020 Ddamba AK The Java Programming Language BBC II-MUBS 63
Features of Java Language • Java is High Performant • How the JIT works?
• However the use of JIT is optional, but sun microsystems
suggest that it is quite efficient to use JIT especially if there exists a repeated code in the program.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 64
Types of Java Programs • Java is therefore used to build a wide range of software programs which are categorized into; • Stand-alone Applications • Console-based programs and • Graphical-user-Interface based programs • Web Applications • Client-side applications (Applets) • Server-side applications (Servlets) • Mobile Applications
2020 Ddamba AK The Java Programming Language BBC II-MUBS 65
Stand-alone Java Programs • Also known application programs • They stand and reside on their own on the client computer system on which they are deployed • They are executed on a stand-alone local computer with Java software (JVM) installed • They are run directly by the Java interpreter. • They are not embedded within HTML • They are executed without the browsers (Internet connectivity).
2020 Ddamba AK The Java Programming Language BBC II-MUBS 66
Types of Stand-alone Programs • Console Applications • They are used via a text-only computer interface, such as a text terminal, the command line interface of some operating system • They take input and display output at a command line console in a text format • All interaction with the program is through keyboard and text output. • The mouse, and any use of multiple windows is not supported.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 67
Types of Stand-alone Programs • Illustrating Console applications
2020 Ddamba AK The Java Programming Language BBC II-MUBS 68
Types of Stand-alone Programs • Applications of Console Applications • Suited for use in background applications. These applications execute automated tasks, often for a long period of time, without user interaction, e.g. Anti- virus scanners, etc. • Used in Business Data processing tasks where large amounts of data are used/ loaded as inputs or outputs that the user doesn't need to view, etc. Such as server- based applications, backup jobs, which run on a scheduled basis. • Where a GUI would consume too much CPU power
2020 Ddamba AK The Java Programming Language BBC II-MUBS 69
Graphical-user Interface Programs • They are known as Windows Applications • They run on a stand-alone desktop computer with graphical elements and icons, e.g. Window, text box, button, checkbox, menus for the user to interact with • GUIs generally provide users with immediate, visual feedback about the effect of each action. • GUI allows multiple programs and/or instances to be displayed simultaneously.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 70
2020 Ddamba AK The Java Programming Language BBC II-MUBS 71
Web Applications • These programs stored on a remote server and delivered over the internet, accessed and executed through a Web browser interface. • They rely on the internet and require a web browser for execution. • They either execute on the client’s computer within a browser of hosted on web server. • In Java, they include; • Java Applet programs and • Java Servlets and Java Server Pages.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 72
Java Applets – Client-side Program • Web-based small client-side programs inserted in a Web page and executed in Java-based web browser on a client’s local computer • They can too, be run as standalone applications with the AppletViewer command (part of the JRE). • Historically, in the early days of the Web, applets were used to deliver the kind of rich browser functionality now done via Flash, JavaScript, or HTML5. • They perform tasks and interact with users on their browser's webpages, e.g. Animations, online games, visual graphic effects such as, scrolling text etc. 2020 Ddamba AK The Java Programming Language BBC II-MUBS 73 Java Applets – Client-side Program • Illustrating Java Applets
2020 Ddamba AK The Java Programming Language BBC II-MUBS 74
Servlet Applications – Server-side • A servlet is a Java class (code) which is used to extend the capabilities of Web servers create dynamic Web pages by means of a request- response model. • Unlike Applets, Servlets execute inside of a Web server, in this case a Servlet container, e.g. Apache Tomcat • They act as a middle layer between a request coming from a Web browser and database application on the HTTP server, and after send back the request/ results to web clients, i.e. browsers.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 75
Servlet Applications – Server-side • Execution of Servlets involves six basic steps; 1. The client’s Web browser send the request to the Java web server. 2. The web server receives the request. 3. The web server passes the request to the corresponding servlet. 4. The servlet processes the request and generates the response in the form of output. 5. The servlet sends the response back to the web server. 6. The web server sends the response back to the client and the client browser displays it on the screen.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 76
Servlet Applications – Server-side • Execution of Servlets involves six basic steps
2020 Ddamba AK The Java Programming Language BBC II-MUBS 77
JSP – Server-side • Java Server Pages is a Java-based server-side technology based on Servlets for developing Web pages that support dynamic content • JSP is an HTML Web page or text document with embedded Java code using special JSP tags, that execute on the Web server, such as Tomcat • JSP Web pages is similar to PHP and ASP, but it uses the Java programming language • It is based on Servlets technology, that is, JSP pages are compiled into a servlet code, and later response is sent back to the user in the Web browser
2020 Ddamba AK The Java Programming Language BBC II-MUBS 78
JSP – Server-side • Illustrating JSP vs, Servlets • Using JSP servlets, you can; • Collect input from users through web page forms, • Present records from a database or another source, and • Create web pages dynamically.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 79
Why Java? • Java has been tested, refined, extended, and proven by a dedicated community of java developers, architects and enthusiasts. • Simple grammar – Java has a very simple grammar familiar to anyone with experience in C and C++ • Portability – It runs well on all the popular platforms • Speed – JIT compilers approach the speed of C/C++ code, and in some memory allocation intensive circumstances, exceed it. • Garbage collection – the programmer doesn’t have to worry about memory (most of the time) • Huge library and developer community support available on internet. 2020 Ddamba AK The Java Programming Language BBC II-MUBS 80 Why Choose Java Language?
2020 Ddamba AK The Java Programming Language BBC II-MUBS 81
Where is Java Used and Applied? • According to sun, 3 billion devices run Java. There are many devices where java is currently used. Some of them are as follows: • Desktop applications such as Acrobat Reader, Media player, antivirus, Eclipse, OpenOffice etc. • Web applications, e.g. Gmail, Murex, Twitter, GoogleMaps, GoogleDocs, Netflix etc. • Enterprise applications such as banking applications, e.g. URA’s ASYCUDA portal • Mobile applications, 99% of all mobile applications running on the Android platform are built in Java
2020 Ddamba AK The Java Programming Language BBC II-MUBS 82
Where is Java Used and Applied? • Some of them are as follows: • Scientific systems, such as NASA wind • E-Commerce Websites such as Amazon, eBay and Wayfair • Embedded system, e.g. all Blueray DVD players OS and applications are entirely built in Java • Games, e.g. all Yahoo Online games, MineCraft, etc. • Smart card • Robotics • ETC…..ETC
2020 Ddamba AK The Java Programming Language BBC II-MUBS 83
How is Java Different from JavaScript?
JAVA JAVA SCRIPT
Initially called Oak, then later Initially called Mocha, then named Java, created by LiveScript, and later to its James Gosling at Sun- JavaScript, developed by microsystems that was later Brendan Eich at Netscape acquired by Oracle that was later acquired by Mozilla. A general-purpose object- A client-side scripting oriented programming language that only executes language used to create in web browsers applications that execute on multiple platforms
2020 Ddamba AK The Java Programming Language BBC II-MUBS 84
How is Java Different from JavaScript?
JAVA JAVA SCRIPT
Used to create and develop It is STRICYLY used to create any type of software client-side web applications application It is statically typed language, Dynamically typed. It doesn’t i.e. variables must declared require explicit data type and associated with a given declaration of all variables, data type before they are parameters and return values used in a program. before they are used
Also, it does a lot of compile- Variable data types are
time checking of the source instead checked while code before it is compiled executing the JavaScript code.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 85
How is Java Different from JavaScript?
JAVA JAVA SCRIPT
Java code is compiled into JavaScript code is loaded, bytecode, interpreted and distributed & interpreted in executed within the Java Web pages as human- virtual machine (JVM) or Java- readable text code. capable web browser for the case of HTML embedded It is not compiled into applet codes. machine language To compile and run Java To write JavaScript code, it programs you need Java requires a text editor, e.g. software (JDK+JRE) set up in NotePad, and to run your computer (interpret) JS code, you need a Web browser where the web page will be loaded.
2020 Ddamba AK The Java Programming Language BBC II-MUBS 86