Chapter 25: An Overview of Java


Java is a powerful object-oriented programming language, developed at Sun Microsystems in the mid 1990s. One of its primary strengths is that it enables you to develop programs that are platform independent, meaning that they can be run on any system that supports Java. This includes Microsoft Windows, Mac OS X, all major versions of UNIX (including Linux, Solaris, and FreeBSD), and various other systems. At the time of this writing, Sun has recently announced plans to make Java open source. This is likely to encourage more system distributions to include Java components by default, making Java even more easily portable.

In general, Java is very similar to C++, but it is easier to use, sometimes at the cost of performance. Java has a much larger set of built-in standard libraries than C++. It is suitable for large-scale development projects as well as small applets that can be run in a web browsers. Java uses automatic garbage collection for memory management. This is a convenient feature of the language that reduces bugs and speeds development; however, it can be slower than the C/C++ style of memory management. Java also replaces some of the most complex and obscure features of C++, such as pointers, again for the purpose of making Java programs less prone to bugs. One of the biggest differences between Java and C++ is that Java programs are compiled to bytecode, which is run in a virtual machine. This makes it much more portable than C++, but again, it slows performance.

This chapter provides a brief introduction to some of the basics of the Java language and its associated class libraries.

Object-Oriented Programming

Java is an object-oriented programming language. You are probably familiar with procedural programming languages in which statements are executed in order, line by line, and may be grouped into procedures that are called from the main body of code. Object-oriented programming is a new way of thinking about the structure of your program. Instead of just grouping statements into procedures, statements and procedures (called methods) are grouped into classes. To use a class, you create an instance of the class called an object. A class is like a type definition for an object.

For example, suppose you are writing a system to keep track of students enrolled at a university You might create a class called StudentFile. It would include variables such as name and IDnum. It would also include methods such as SetStudentData and GetStudentID.

When you wanted to add a new student to the system, you would create a new StudentFile object. You would use the SetStudentData method of this object to save the student’s name and ID number in the appropriate variables, and the GetStudentID method to retrieve the ID number when you needed it.




UNIX. The Complete Reference
UNIX: The Complete Reference, Second Edition (Complete Reference Series)
ISBN: 0072263369
EAN: 2147483647
Year: 2006
Pages: 316

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net