210 likes | 216 Views
Introduction To JAVA. By Ihtesham Ul Haq. Course Objectives. Upon completing the course, you will understand Create, compile, and run Java programs Primitive data types Java control flow Methods Arrays (for teaching Java in two semesters, this could be the end)
E N D
Introduction To JAVA By Ihtesham Ul Haq
Course Objectives • Upon completing the course, you will understand • Create, compile, and run Java programs • Primitive data types • Java control flow • Methods • Arrays (for teaching Java in two semesters, this could be the end) • Object-oriented programming • Core Java classes (Swing, exception, internationalization, multithreading, multimedia, I/O, networking, Java Collections Framework)
Course Objectives, cont. • You will be able to • Write simple programs using primitive data types, control statements, methods, and arrays. • Create and use methods • Develop a GUI interface and Java applets • Write interesting projects • Establish a firm foundation on Java concepts
History Of Java • In January of 1991, Bill Joy, James Gosling, Mike Sheradin, Patrick Naughton and several other individuals met in Aspen, Colorado for the first time to discuss the ideas for the Stealth Project. The goal of the Stealth Project was to do research in the area of application of computers in the consumer electronics market. The vision of the project was to develop "smart" consumer electronic devices that could all be centrally controlled and programmed from a handheld-remote-control-like device. According to Gosling, "the goal was ... to build a system that would let us do a large, distributed, heterogeneous network of consumer electronic devices all talking to each other." With this goal in mind, the stealth group began work
History cont. • Gosling thought that the C++ programming language used at that time was inadequate for this kind of a project. • His extensions and modifications to C++ were the first steps towards the development of an independent language that would fit the project objectives.
The Name • Gosling named the language "Oak" while staring at an oak tree outside his office window! The name "Oak" was later dismissed. • Finally, inspiration struck one day during a trip to the local coffee shop". • Others have speculated that the name Java came from several individuals involved in the project: James gosling, Arthur Van hoff, Andy bechtolsheim. [McCarthy]
Why Choose Java? • Java is simple • Java is object-oriented • Java is distributed • Java is interpreted • Java is robust • Java is secure • Java is architecture-neutral • Java is portable • Java’s performance • Java is multithreaded • Java is dynamic
Java is Architecture Neutral! • The most important of the advantages of java over others is that the Language is Architecture Neutral. • This means that a Program written in java can be run by “Any Machine” having “Any operating System”.
Anatomy of a Java Program • Comments • Package • Reserved words • Modifiers • Statements • Blocks • Classes • Methods • The main method
Comments In Java, comments are preceded by two slashes (//) in a line, or enclosed between /* and */ in one or multiple lines. When the compiler sees //, it ignores all text after // in the same line. When it sees /*, it scans for the next */ and ignores any text between /* and */.
Package The second line in the program (package chapter1;) specifies a package name, chapter1, for the class Welcome. Packages are Groups of classes Located in a directory, child directory, and so on…. It is important to note that in a program we may include a package name or a sub package name.
Reserved Words Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used for other purposes in the program. For example, when the compiler sees the word class, it understands that the word after class is the name for the class. Other reserved words are public, static, and void.
Modifiers Java uses certain reserved words called modifiers that specify the properties of the data, methods, and classes and how they can be used. Examples of modifiers are public and static. Other modifiers are private, final, abstract, and protected. A public datum, method, or class can be accessed by other programs. A private datum or method cannot be accessed by other programs.
Statements A statement represents an action or a sequence of actions. The statement System.out.println("Welcome to Java!") in the program in Example 1.1 is a statement to display the greeting "Welcome to Java!" Every statement in Java ends with a semicolon (;).
Blocks A pair of braces in a program forms a block that groups components of a program.
Classes The class is the essential Java construct. A class is a template or blueprint for objects. To program in Java, you must understand classes and be able to write and use them. The mystery of the class will continue to be unveiled throughout Java. For now, though, understand that a program is defined by using one or more classes.
Methods What is System.out.println? It is a method: a collection of statements that performs a sequence of operations to display a message on the console. It can be used even without fully understanding the details of how it works. It is used by invoking a statement with a string argument. The string argument is enclosed within parentheses. In this case, the argument is "Welcome to Java!" You can call the same println method with a different argument to print a different message.
main Method The main method provides the control of program flow. The Java interpreter executes the application by invoking the main method. The main method looks like this: public static void main(String[] args) { // Statements; }
What tools to Use? • JDK 6 • The Java Development Kit Version 6 • Can be downloaded from http://www.sun.java.com/ • TEXTPAD • IDE for Java Development • Can be downloaded from http://www.textpad.com/
Recommended Books • Java 2 • Ivor Horton • Java • Dietel and Dietel