Java (programming language): Difference between revisions
imported>Jayvin Arora |
mNo edit summary |
||
Line 45: | Line 45: | ||
==References== | ==References== | ||
{{reflist}} | {{reflist}}[[Category:Suggestion Bot Tag]] |
Latest revision as of 11:00, 4 September 2024
Java is an object-oriented computer programming language now managed as open source software[1]. The Java source code compiler is part of the Java platform (a bundle of interdependent programs) originally specified and implemented by a team led by James Gosling (colloquially known as the "Father of Java")[2][3] while he worked at Sun in the early 1990's. Use of the Java programming language spread rapidly across the computer industry, and since 2003, Java has been the recommended teaching language for U. S. high schools for students planning to take the High School Advanced Placement exam[4] in Computer Science. See the Java release history.
Operating system independence
Java programs are able to run on many different types of operating systems without being compiled again. This is possible because an execution engine, also known as a virtual machine or runtime environment, has been implemented for most operating systems. The Java runtime environment makes all computers look alike so that Java programs can run identically on all of them. The direct result of having a virtual machine is that Java source code compiles initially down to an intermediate language, called Java bytecode. Java programs (.jar files) are binary files containing bytecode, and at runtime, the Java virtual machine (runtime environment) loads the bytecode and monitors its execution so that the program's behavior is identical regardless of which operation system is being used. For more about how this is accomplished, see the Java platform.
The Java programming language has access to extensive libraries containing reusable code. As well, there are numerous ways for Java applications to be deployed, including being embedded in a web page as an applet, on a desktop machine for a single user, on a web server as a servlet (returning "dynamic" information to web browsers), or on a web server as a web service endpoint (procedure callable across a network from any kind of platform).
In practice, certain kinds of Java programs require programmer effort to guarantee good cross-operating-system behavior. For example, graphical user interfaces on different operating systems tend to use different menu shortcuts, and text files on different systems have different line endings. So it is sometimes necessary for the programmer to write Java code which says "if I'm on this system, do this, but if I'm on that system, do something else." However, with appropriate care and testing, Java programs can be made to behave "perfectly" on all the major operating systems without being recompiled.
Classes and objects
Classes in the Java programming language are object-oriented, which means code is always bundled into one or more classes. A class may contain methods--the operations of the class (like functions or procedures in older languages). A class may also contain data--the fields of the class (like variables in older programming languages). The class is a recipe, written by a programmer, which tells the virtual machine how to create an object at runtime. Classes, and objects created using them, have been compared to structs in C or C++, but classes and objects (unlike structs) can be extended and modified without recompilation.
Java is not a fully object oriented language in the sense everything is not an object. Specifically, Java has primitive data types: int,long, short, boolean, double, float, and char. In a fully object-oriented language, like Scala, these are considered objects and can be treated as such.
A Java program consists of cooperating objects of different types. Some of the classes (types) are made from classes coded by the application programmer. Some types are pre-compiled, from the standard Java libraries (written by Sun programmers); other types may be libraries that the programmer has modified (extended).
Strong typing
Prior to Java, C++ was the dominant programming language in the computer industry. Compared with C++, Java code is typically more robust because the Java platform prevents direct pointer manipulation and performs strong type checking at both compile- and run-time. These safety features in Java make it less likely that one ill-behaving program will harm other users or programs on a shared computer. These restrictions also limit the power of the Java programmer somewhat. Java is considered a "higher-level" language than C or C++.
This is also known as static typing.
The Java Class Libraries
Also called the Base Class Library, these libraries ("packages") are available to every program written in Java, regardless of operating system. They consist of ~2500 or more reusable classes, providing networking, file IO, graphic environment, cross-computer interoperability and many other features, normally making direct access to the operating system layer unnecessary. Apart the original Sun version, currently there are at least two completely different implementations of this library (GNU Classpath and Apache Harmony).
Object references
Some people say that "java does not have pointers". This is arguable because array and object variables are treated as references. For instance, if a and b are arrays, the sentences { b[0] = 1; a[0] = 17; b = a } will result b[0] obtaining the value 17 as well. This feature allows to work with data structures like graphs or linked lists that are usually built using pointers.
Unlike in C, arrays and objects that are no longer used need not be explicitly discarded. Java garbage collector eliminates the unused object automatically, freeing the memory it uses. This eliminates the whole group of difficult to find bugs but increases the memory usage.
Speed
First Java versions deep in the past only had interpreter to run the bytecode. This created Java a reputation of the slow language. The recent implementations usually compile the bytecode before running hence for majority of the algorithms the speed is comparable to the one of the compiled code. Garbage collector has been criticized as a slowing factor but the usual C heap management is also complex and may take a notable part of the processor time.
Java native interface
Java standard library cannot exist as "world in itself"; as some point it is necessary to call the underlying operating system to perform the requested functions. This is done via Java native interface (JNI) that allows to call C code from Java. Usually this is done from the system library and the ordinary programmer never needs to write or even call the native code directly. However in cases like connecting the big existing library or accessing some low level resources it is possible for the user to mix Java and C code using JNI. Native code is also rewritten during porting Java to the new operating system.
References
- ↑ Open-Source Java Project Overview. Retrieved on 2007-04-08.
- ↑ The Java Language Specification. Retrieved on 2007-10-06.
- ↑ FATHER OF JAVA, JAMES GOSLING, CELEBRATES "INNOVATION EVERYWHERE" WITH JAVA TECHNOLOGY. Retrieved on 2007-10-06.
- ↑ "Subjects" High School Advanced Placement. The College Board (2007). Retrieved on 2007-05-17.