CHAPTER 1 Introduction to JAVA Programming
What java is Java is high level You can use java to write computer applications that computes number,process words,play games,store data, etc.
History of Java. History Sun Microsystems ( Green Project by James Gosling) Platform independent Oak to Java HotJava is the first java-eneble Web browser
Characteristics of Java Java is simple Java is object-oriented Java is platform Independent Java is safe Java is multi-thread Java is garbage collected
Java is simple Java was designed to make it much easier to write bug free code. Java is easy to read and write Java dose not need users to do memory allocation and deallocation Java is easy to learn
Java is Object-Oriented Simpler and easier to read program More efficient reuse of code Faster time to market More robust and error-free code
Java is Platform Independent A Java program never really executes natively on the host machine Rather a special native program called Java interpreter read the byte code and executes the corresponding native machine instructions You don t even need to recompile
Java is Safe Java implements a robust exception handling mechanism to deal with both expected and unexpected errors
Java is Multi-Threaded A single Java program can have many different processes executing independently continuously
Java is Garbage Collected Objects are created by Java s new operator, and memory for new objects is allocated on the heap at run time Garbage collection is the process automatically freeing objects that are no longer referenced by the program This frees the programmer from having to keep track of when to free allocated memory,thereby preventing many potential bugs and headaches.
Java Platform Java SE(Java Standard Edition) can be use to develop client-side standalone application or applet Java Development Kit(JDK) Java Runtime Environment(JRE) JDK JRE JVM
Java Platform Java EE(Java Enterprise Edition) can be use to develop server-side applications such as Java servlets,java Server Pages,Enterprise Java Beans and Web Services. Java2ME(Java Micro Edition) can be use to develop application for mobile devices such as cellphone.
Java Virtual Machine(JVM) JVM is a platform-independent execution environment that converts Java bytecode into machine language and executes it. Most programming languages compile source code directly into machine code that is designed to run on a specific microprocessor architecture or operating system, such as Windows or UNIX.
Java Virtual Machine(JVM)
Java Develop Tools JDK Compiler Debugger Editor Notepad Editplus Eclipse NetBeans Documentation
The Background
Type of Java Program. Java Application Standalone not use webbrowser for processing and can be run every devices with JRE installed. Java Applet Server-side and Run on web browser
Type of Error Syntax Error Logical Error
Object Oriented Programming Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which are data structures that contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods.
What is class A class is a blueprint or prototype from which objects are created. This section defines a class that models the state and behavior of a real-world object. It intentionally focuses on the basics, showing how even a simple class can cleanly model state and behavior.
What is Object An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life. This lesson explains how state and behavior are represented within an object, introduces the concept of data encapsulation, and explains the benefits of designing your software in this manner.
What is Method A method (or message) in object-oriented programming (OOP) is a procedure associated with an object class. An object is made up of behavior and data. Data is represented as properties of the object and behavior as methods. Methods are also the interface an object presents to the outside world. For example a window object would have methods such as open and close.
A part of class Attribute name : type Method Student -idno : String -name : String +department : String -gpa : double +register() +getname() +getgpa() Class Name Modifier
Installing Java Go to http://www.google.com Type j2se download Choose Java Se with the latest version
Developing Your First Java Program Use text editor to write a file HelloWorld.java public class HelloWorld{ public static void main(string[] args){ System.out.println( Hello World ); } }
Compiling and Running Program To compile a Java program Use command javac <filename.java> Example: javac HelloWorld.java To run a Java program Use command java <filename> Example: java HelloWorld