00 intro to java

18
Engr. Dheya Abdullah JAVA Overview

Transcript of 00 intro to java

Page 1: 00 intro to java

Engr. Dheya Abdullah

JAVA Overview

Page 2: 00 intro to java

What will this talk cover?

Outline Brief History How Java Work Java Virtual Machine JVM JVM Architecture OOP Concepts Java features Java Libraries What is Java good for Hello world program in Java Java Applet

Page 3: 00 intro to java

What is Java? History

Started in (1991) as a small language for consumer electronics (toasters, microwave ovens…etc.) by James Gosling with the name of OAK.

Java is developed by Sun Microsystems and officially released in 1995.

The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities.

Page 4: 00 intro to java

How does Java work? Java source code is compiled into

machine independent “bytecodes” The bytecodes can be run directly by

an interpreter The bytecodes can be converted to

machine code and executed (“Just in Time (JIT)” compilation).

An optimizing interpreter can dynamically identify program “hotspots” and create code optimized for the specific machine/environment.

Page 5: 00 intro to java

Java Virtual Machine JVM

•its just a program that runs in the host computer. It receives bytecodes and gives machine-code understandable to the host computer

•So its evident that we have a single Compiler but multiple JVMs (JVM for Windows, JVM for Unix, JVM for MacOS).

•Any new system that will appear in future, java will make a new JVM for it so java supports unknown future machines.

Page 6: 00 intro to java

JVM Architecture

•Class Loader : loads the java programs (bytecodes)

•Bytecodes verifier: verifies that bytecode has not been modified since it last compilation.

•Interpreter : this is the actual part that translates the bytecode into a code understandable/executable by the host machine.

•Other parts not shown in this figure are•Security manager•Library classes•JIT (Just in time compiler)

Page 7: 00 intro to java

Main OOP Concepts

OOP is a set of concepts for organizing and arranging the code in a program its not a programming language.

Main concepts of OOP: •Class ( a structure that contains variables and functions together ) •Object (an instance of a class)•Encapsulation.•Inheritance.•Polymorphism.

•Coming lectures will make these concepts more clear.

Page 8: 00 intro to java

Java Features

Simple Java in similar to C++ in its syntax, but it is simpler than C++ in

developing applications because its rich in its libraries (Java has a huge amount of ready made functions so programmer doesn't need to rewrite them)

Object Orientated Java implements OOP concepts more so than C++. In C++ programmer has the option to go for Procedural way of

programming or to Object Oriented way of programming its optional.

But in Java its purely OOP programmer have to follow OOP concepts to develop applications in Java no other option.

Distributed Distributed systems is an environment where single application

can run on multiple computers connected in a network. Java supports Internet protocols, URL’s, HTTP etc. Support for distributed objects, RMI, CORBA etc.

Robust Difficult to create memory leaks, go beyond the end of an array.

Page 9: 00 intro to java

Java Features Cont. Secure

Bytecodes “verifier”, checks the program before it is executed. Platform independent / Portable

JVM accepts only bytecodes and generates host’s machine-code. Interpreter / Compiler

Java default Translator is an interpreter. Java also has a compiler known as JIT Just In Time compiler.

High Performance With JIT compiler still several times slower than native C++. But

with Sun Optimizing Interpreter, java programs can run faster than C++ program.

Multithreaded Java has direct support for multithreading (c.f. subprocesses)

Dynamic Libraries can change without recompiling programs that use them.

Page 10: 00 intro to java

Java Libraries (API’s)

In addition to the core language, java has additional classes: AWT - Basic GUI (Forms, Buttons, Textbox, Dropdown-box,

Radio/Check) SWING - Enhanced GUI toolkit 2D – Drawings (lines, shapes such as circle, square…etc ),

Transformations, pattern fill, textures etc. JDBC - Standard Interface between Java and SQL databases ODMG binding - Standard Interface to Object databases RMI + CORBA - Remote procedure calls between

distributed Java applications, and between Java and other languages

BEANS - Java based components, plug commercial components into your applications.

Media (audio, video etc.), Share (e.g. whiteboards), Animation, Telephony, 3D (developed by SUN and SGI), cryptography, server.

Page 11: 00 intro to java

What is Java Good For?

Stand Alone Applications GUI based applications

Database programming SQL databases using JDBC Object databases using ODMG

binding Web Applets Java Servlets Distributed client-server applications

Using TCPIP + RMI + CORBA Graphics applications

2D and 3D

Page 12: 00 intro to java

Java Program TypesJava can make two type of program

1. Application (a full standalone program such C++ language programs that can run on any OS).

2. Applets (a light weight program that runs within Internet Browsers its usually a part of web pages)

Page 13: 00 intro to java

Hello World in Java

•This is how Java Application looks like

Page 14: 00 intro to java

Java Applets Java Applets: are programs

designed to run inside a web browser.

Applets loaded from the internet are run inside a “sandbox” which restricts what they can do: No Access to local filesystem Can only open network

connections with the site they came from

Problems (the need for applet)– Complex programs can be large and

hence slow to download

– Each browser has subtle differences.

Page 15: 00 intro to java

Assignment #1Objective: This Assignment will help students to compare two languages to understand

common concepts and unique features of each language.

You can compare any two languages, choose one of these titles and work on it. Java vs. VB.Net Java vs. C++

The comparison should contain at least six differences with three lines explanation of each difference.

Submission Timing:

the assignment should be submitted after one complete week (2nd lecture next week).These assignments are Marked assignment.

The Solution will look like

Java C++

Pure OOP language:Java is pure OOP language because it allow programmer to write code only in classes and objects.

Hybrid language:C++ allows programmer to write code in structural way using functions or OOP way using classes and objects (OOP is optional).

….. ……..Hint: use Google.com to get the material and then summarize it in

your words

Page 16: 00 intro to java

Evaluation, Rules & Instructions:

Evaluation: Final exam will be taken at end of semester with 35% weight. Mid semester exam will be taken at 6th week with 20% weight. Assignments, Class interaction, Lab performance and attendance

15% weight. Announced short Quizzes will be taken with 10% weight. Semester Project with 20% weight.

 Road map to pass JAVA course: Attend Classes regularly and Do lab work. Submit mini assignments. Don’t miss quizzes. Attend mid-exam and final exam.

Rules & Instructions: End of each week (2nd lecture of the week) a marked assignment

will be given and it will be collected next week 1st lecture. First lecture of the next week a short quiz will be taken from last

week topics and assignment.

Page 17: 00 intro to java

More Information

Web Sites http://www.javasoft.com

Sun’s home page for Java http://www.javasoft.com/books/Series/Tutorial/

index.html http://www.gamelan.com/

Huge library of Java applets and applications

http://www.javaworld.com

http://www.javareport.com JavaWorld/Java Report (magazines)

http://www.microsoft.com/visualj

Visual J++

BooksText Book:Java Software SoultionsFoundations of program design 6th

edition, Lewis & Loftus, Pearson.

Reference Book:John Zukowski, Mastering Java 2,

Sybex.

Page 18: 00 intro to java

Conclusion If you are still using:

Fortran, C, C++, Perl, CGI, SQLPlus, Rexx, IDA etc. you could save yourself a lot of time and effort by

switching to: