190 likes | 365 Views
Java. Unit 1: Java and Eclipse. Java. Java is an object-oriented programming language. Java is important to us because Android programming uses Java. However, Java is much more than just the language for Android. Questions??.
E N D
Java Unit 1: Java and Eclipse
Java • Java is an object-oriented programming language. • Java is important to us because Android programming uses Java. • However, Java is much more than just the language for Android.
Questions?? • What are some of Java’s characteristics that distinguish it from other programming languages? • What features does it have that might make it useful in situations where other languages would not be as suitable?
Program Compilation • Before we look at Java, we should understand how programs are run on machines. • When program code is written, it doesn’t run it as the code you write it in. Instead, it has to be ‘compiled’ into a language that the machine itself can understand. • When you run the program after compilation, it’s running a set of instructions built specifically for its system. • However, different system architectures have different ways of reading that code, so the compiled machine code will only run on that specific architecture.
Interpreting Java • From a technical point of view, Java has one fundamental characteristic which all other important characteristics stem from. • Java is a language which is interpreted on a simulated hardware architecture. • Most languages aren’t directly understood by a machine. They have to be converted (compiled) into proper machine code first. But, Java finds a half-way point to full machine code, by ‘simulating’ the language. • It is possible to design hardware that runs Java code directly, but in common computing environments like Windows and Unix, installation of Java means that a simulation has been installed.
Interpreting Java • For most languages like C or C++, compilation of a program results in an executable target file (*.exe) which consists of machine code for the architecture which it was designed. • This presents a portability problem, as the compiled program would only work on that specific architecture. • For Java, the process is still referred to as compilation, but it is not literal compilation. When Java source code is compiled, the result is “byte code”, which is code which runs on the simulated Java machine.
Interpreting Java • In such a design, the programming language is merely a layer in a system’s software architecture and it is not dependent on the underlying hardware architecture of the machine. • As a result, Java is (in theory) a “universal” programming language. • Versions of Java exist for various hardware architectures. These implementations differ internally.
Interpreting Java • The intent of this is for the Java code generated for the different environments to be exactly the same. • Thus, Java programs should be freely portable between them. • So if a program is written in one environment, no changes to the source code should be necessary in order for its byte code to be directly run in a different environment.
Interpreting Java • “Write once, run everywhere” • This applies to desktop computers. • Even in this case, the reality is that subtle differences in implementations of the Java machine lead to problems. • “Write once, debug everywhere.”
Java and Android • For us, it’s important to realize that Java as used in Android does differ from Android as used in other environments. • The basic syntax is the same, but the overall structure of the Android apps is different from the structure of apps in a desktop environment. • An Android app will only run on an Android device. It will not run anywhere else.
Java and The World • As with all system and software design decisions, the nature of Java involves trade-offs. • One of the driving forces behind Java was the World Wide Web. • Java “applets”, which will be covered later. • If a “universal” programming language exists, then programs can be downloaded and run on users’ machines regardless of the hardware involved. • Now Java has been adapted to accomplish something similar in the cell phone environment.
Java Cons • There is a big trade-off in using Java. • Since a simulated machine interprets Java’s “half-way code”, it makes it slower than running fully-compiled code. It could be up to 10 times slower. • But, since hardware nowadays have become much faster, and because the Web and cell phones are a preferred means of distributing programs, the trade-off of speed for portability has been well worth it.
Java Safety • Some languages, such as C and C++, allow the programmer to directly access memory addresses in a machine’s hardware, through the use of pointers. • Java cannot do this. • However, direct access to memory can be harmful to a system, intentionally or not. • Since Java can’t do this, users can be assured that Java programs won’t do anything. destructive as a result of direct memory access. • Thus, Java supports both portability and safety of programs.
Object-Oriented Java • Java is object-oriented, and is designed to support event-driven programming. • With this in mind, we can create programs with graphical user interfaces which support point-and-click actions. • In addition to many advanced features within the language itself, it comes with libraries of complete code components which an experienced programmer can use instead of writing components from scratch.
Java Syntax • Java also has basic syntactic features found in structured programming languages, namely sequential execution of blocks of code, conditional execution (if statements), and iterative execution (loops). • All of this, along with object-oriented concepts, will be covered later on.
Learning Java • Java was not designed for teaching or learning purposes. • It was designed for building complex applications. • It won’t be possible to learn all of Java within a single course. There is simply too much. • But, after being introduced to the basics of Java and Android development, it should be simple to do your own research to solidify your understanding.
Summary • The Java language is interpreted on a simulated machine architecture. • This makes Java source and target code highly portable. • This also makes it possible to download Java code from the World Wide Web. • The interpretation of Java code makes running it slower. • Java programs do not support direct memory access, which makes downloaded programs safer.
Summary • Java is an object-oriented language containing the features needed in order to write graphical applications with point-and-click interfaces. • Java was designed as a production language, not a teaching language. It contains many features and comes with many libraries. • It is possible to do things in Java that cannot be done in other languages.