Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Creating Your First Java Classes Chapter 1 COBOL (COmmon Business Oriented Language) FORTRAN (FORmula TRANslation) BASIC (Beginner All-purpose Symbolic Instructional Code) Pascal (structured programming) Ada (multi purpose language) C (whose developer designed B first) Visual Basic (Basic-like visual language developed by Microsoft) Delphi (Pascal-like visual language developed by Borland) C++ (an object-oriented language, based on C) C# (a Java-like language developed by Microsoft) Java 2 Created by Sun Microsystems team led by James Gosling (1991) Originally designed for programming home appliances Difficult task because appliances are controlled by a wide variety of computer processors Team developed a two-step translation process to simplify the task of compiler writing for each class of appliances Initially called “Oak” programs Unfortunately, the concept was much too advanced for appliance technology at the time Fortunately, it was just right for the Internet, which was just starting to take off In 1995, the team announced that the Netscape Navigator Internet browser would incorporate Java technology Today, Java not only permeates the Internet, but also is the invisible force behind many of the applications and devices that power our day-today lives. mobile phones handheld devices games navigation systems e-business solutions Java is everywhere! Java Is Simple Java is partially modeled on C++, but greatly simplified and improved. Some people refer to Java as "C++--" because it is like C++ but with more functionality and fewer negative aspects. Java Is Simple Java Is Object-Oriented Java is inherently object-oriented. Although many object-oriented languages began strictly as procedural languages, Java was designed from the start to be object-oriented. Objectoriented programming (OOP) is a popular programming approach that is replacing traditional procedural programming techniques. One of the central issues in software development is how to reuse code. Object-oriented programming provides great flexibility, modularity, clarity, and reusability through encapsulation, inheritance, and polymorphism. Java Is Simple Java Is Object-Oriented Java Is Distributed Distributed computing involves several computers working together on a network. Java is designed to make distributed computing easy. Since networking capability is inherently integrated into Java, writing network programs is like sending and receiving data to and from a file. Java Is Simple Java Is Object-Oriented Java Is Distributed Java Is Interpreted You need an interpreter to run Java programs. The programs are compiled into the Java Virtual Machine code called bytecode. The bytecode is machineindependent and can run on any machine that has a Java interpreter, which is part of the Java Virtual Machine (JVM). Java Is Simple Java Is Object-Oriented Java Is Distributed Java Is Interpreted Java Is Robust Java compilers can detect many problems that would first show up at execution time in other languages. Java has eliminated certain types of error-prone programming constructs found in other languages. Java has a runtime exception-handling feature to provide programming support for robustness. Java Is Simple Java Is Object-Oriented Java Is Distributed Java Is Interpreted Java Is Robust Java Is Secure Java implements several security mechanisms to protect your system against harm caused by stray programs. Java Is Simple Java Is Object-Oriented Java Is Distributed Java Is Interpreted Java Is Robust Java Is Secure Java Is ArchitectureNeutral Write once, run anywhere With a Java Virtual Machine (JVM), you can write one program that will run on any platform. Java Is Simple Java Is Object-Oriented Java Is Distributed Java Is Interpreted Java Is Robust Java Is Secure Java Is ArchitectureNeutral Java Is Portable Because Java is architecture neutral, Java programs are portable. They can be run on any platform without being recompiled. Java Is Simple Java Is Object-Oriented Java Is Distributed Java Is Interpreted Java Is Robust Java Is Secure Java Is ArchitectureNeutral Java Is Portable Java's Performance Java’s performance Because Java is architecture neutral, Java programs are portable. They can be run on any platform without being recompiled. Java Is Simple Java Is Object-Oriented Java Is Distributed Java Is Interpreted Java Is Robust Java Is Secure Java Is ArchitectureNeutral Java Is Portable Java's Performance Java Is Multithreaded Multithread programming is smoothly integrated in Java, whereas in other languages you have to call procedures specific to the operating system to enable multithreading. Java Is Simple Java Is Object-Oriented Java Is Distributed Java Is Interpreted Java Is Robust Java Is Secure Java Is ArchitectureNeutral Java Is Portable Java's Performance Java Is Multithreaded Java Is Dynamic Java was designed to adapt to an evolving environment. New code can be loaded on the fly without recompilation. There is no need for developers to create, and for users to install, major new software versions. New features can be incorporated transparently as needed. Java is an object-oriented programming (OOP) language Programming methodology that views a program as consisting of objects that interact with one another by means of actions (called methods) Objects of the same kind are said to have the same type or be in the same class Most high-level languages have constructs called procedures, methods, functions, and/or subprograms These types of constructs are called methods in Java All programming constructs in Java, including methods, are part of a class High-level language: A language that people can read, write, and understand A program written in a high-level language must be translated into a language that can be understood by a computer before it can be run Machine language: A language that a computer can understand Low-level language: Machine language or any language similar to machine language Compiler: A program that translates a high-level language program into an equivalent low-level language program This translation process is called compiling The compilers for most programming languages translate high-level programs directly into the machine language for a particular computer Since different computers have different machine languages, a different compiler is needed for each one In contrast, the Java compiler translates Java programs into byte-code, a machine language for a fictitious computer called the Java Virtual Machine Once compiled to byte-code, a Java program can be used on any computer, making it very portable When you create and save the Java code for an application, the code is saved as a java file Filename . java When the java file is compiled, it creates a class file which can run the application Filename . class There are three primary components of a Java program Class { Main { Class Main method Java code code goes here } } One of the first Java classes written to welcome Java to the internet (Hello World) class HelloWorld { public static void main(String[ ] args) { System.out.println("Hello World!"); } } Let’s examine the code line by line: class HelloWorld This line declares a new class, called "HelloWorld”. A class is composed of data variables (members), and functions (methods). public static void main(String args[ ]) class HelloWorld { public static void main(String[ ] args) { System.out.println("Hello World!"); } } All applications written in Java share at least one thing in common - they all have a main method. You must declare a public static main method that accepts command line parameters (args), for your application to run. System.out.println ("Hello world!"); This is where our application writes a message to the user. System.out is an object that allows us to write to "standard output", which is the user's console. Copy this code to create a box import javax.swing.*; public class HelloWorldBox{ public static void main(String[ ] args){ JFrame frame = new JFrame("HelloWorldBox"); final JLabel label = new JLabel("Hello World!"); frame.getContentPane( ).add(label); frame.setSize(200, 100); frame.setVisible(true); } frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } Steps involved in developing a Java program