JAVA PROGRAMMING
WHAT IS JAVA?
Developed by Sun Microsystems (James Gosling).
A general-purpose object-oriented language.
Based on C/C++
Designed for easy Web/Internet aplications.
Widespread acceptance.
Java Disadvantages
Slowerthan compiled language such as C
an experiment ¡n 1999 showed that Java was 3 or4 times slower than C or C++
tille ofthe aiiicle: "Comnaríng Java vs. C/C++ Efficiencv Issues to Interpersonal íssues" (Lutz Prechelt)
adequate for all bul the most time-intensive programs
features
Simple
- Fixes some clumsy features of C++
no pointers
-automatic garbe collection
Subtopic
Object oriented
- Focus on the data (objects) and methods manipulating the data.
-all funtions are associated with objects.
-almost all data types are oblects (feles strings, etc)
-potentially better code organizations and reuse
Interpreted
- Java compiler generate byte-codes, not native machine code
-The compiled byte-codes are plattaform independent
-Java byte codes are translated on the fly to machine readable instrucions runtime (java virtual machine).
Multithreaded
múltiple concurrent threads of executions can run simultaneously utilizas a sophisticated set of synchronization primitivas (based on monitors and condition variables paradigm) to achieve this
Dynamic
java ¡s designed to adaptto evolving environment
librarles can freely add new methods and ¡nstance variables
without any effect on their clients
Language basics
Data types
8 primitive types:
boolean, byte, short, ¡nt, long, float, double, char Class types, either provided by Java, or made by programmers
String, Integer, Array, Frame, Object, Person, Animal, ...
Array types Variables
dataType identifier[ = Expression]:
Example variable declarations and initializations
Flow of control
switch
for, while, do-while
break
continué