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.
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.
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.
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
JIT (Just in time compiler)
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)
Coming lectures will make these concepts more clear.
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)
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 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.
Difficult to create memory leaks, go beyond the end of an array.
Java Features Cont.
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.
With JIT compiler still several times slower than native C++. But with Sun Optimizing Interpreter, java programs can run faster than C++ program.
Java has direct support for multithreading (c.f. subprocesses)
Libraries can change without recompiling programs that use them.
Java Libraries (API’s)
In addition to the core language, java has additional classes:
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 .
What is Java Good For?
Stand Alone Applications
GUI based applications
SQL databases using JDBC
Object databases using ODMG binding
Distributed client-server applications
Using TCPIP + RMI + CORBA
2D and 3D
Java Program Types
Java can make two type of program
Application (a full standalone program such C++ language programs that can run on any OS).
Applets (a light weight program that runs within Internet Browsers its usually a part of web pages)
Hello World in Java
This is how Java Application looks like
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.
Objective : 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.
the assignment should be submitted after one complete week (2 nd lecture next week).
These assignments are Marked assignment.
The Solution will look like
Hint: use Google.com to get the material and then summarize it in your words 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). … .. …… ..
Evaluation, Rules & Instructions:
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 (2 nd lecture of the week) a marked assignment will be given and it will be collected next week 1 st lecture.
First lecture of the next week a short quiz will be taken from last week topics and assignment.