Lecture 1 LPU CSE 310 Programming in Java

  • Slides: 26
Download presentation
Lecture 1 © LPU : : CSE 310 Programming in Java : : Sawal

Lecture 1 © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Outcome of the Lecture Upon completion of this lecture you will be able to

Outcome of the Lecture Upon completion of this lecture you will be able to understand ü Fundamentals and Characteristics of Java Language ü Basic Terminology – JVM, JRE, API, JDK, IDE, bytecode ü Writing, Compiling and Executing Java Program Lecture 1 © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Outline of the Presentation ü ü ü ü ü Lecture 1 Overview of Java

Outline of the Presentation ü ü ü ü ü Lecture 1 Overview of Java History of Java Standards Editions of Java JDK and IDE Characteristics of Java Sample Java Program Creating, Compiling and Executing Java Program Java Runtime Environment (JRE) and Java Virtual Machine (JVM) © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Overview of Java § A general-purpose Object-Oriented language § Developed by Sun Microsystems, later

Overview of Java § A general-purpose Object-Oriented language § Developed by Sun Microsystems, later acquired by Oracle Corporation § Java can be used to develop ü Stand alone applications ü Web applications. ü applications for hand-held devices such as Palm and cell phones Lecture 1 © LPU : : CSE 310 Programming in Java : : Sawal Tandon

History of Java § Developed by a team led by James Gosling at Sun

History of Java § Developed by a team led by James Gosling at Sun Microsystems in 1991 for use in embedded chips. § Originally called Oak. § In 1995 redesigned for developing Internet applications and renamed as Java § Hot. Java - The first Java-enabled Web browser (1995) § JDK Evolutions (in slide 9) Lecture 1 © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Java Standards Computer languages have strict rules of usage. Java standards are defined by

Java Standards Computer languages have strict rules of usage. Java standards are defined by • The Java language specification and • Java API The Java language specification is a technical definition of the language that includes the syntax and semantics of the Java programming language. The Application Program Interface (API) contains predefined classes and interfaces for developing Java programs. Java language specification is stable, but the API is still expanding Lecture 1 © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Editions of Java ü Java Standard Edition (SE) used to develop client-side standalone applications

Editions of Java ü Java Standard Edition (SE) used to develop client-side standalone applications or applets. ü Java Enterprise Edition (EE) used to develop server-side applications such as Java servlets and Java Server. Pages. ü Java Micro Edition (ME). used to develop applications for mobile devices such as cell phones. Java Card: A technology that allows small Java-based applications to be run securely on smart cards and similar small-memory devices. We will be using Java SE Lecture 1 © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Java Development Kit (JDK) JDK consists of a set of separate programs, each invoked

Java Development Kit (JDK) JDK consists of a set of separate programs, each invoked from a command line, for developing and testing Java programs. There are many versions of Java SE. JDK 1. 02 (1995) JDK 1. 1 (1996) Java 2 SDK v 1. 2 (JDK 1. 2, 1998) Java 2 SDK v 1. 3 (JDK 1. 3, 2000) Java 2 SDK v 1. 4 (JDK 1. 4, 2002) and so on… The latest is JDK 1. 8 Lecture 1 We will be using JDK 1. 7 © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Integrated Development Environment (IDE) ü Besides JDK, a Java development tool—software that provides an

Integrated Development Environment (IDE) ü Besides JDK, a Java development tool—software that provides an integrated development environment (IDE) for rapidly developing Java programs can be used. ü Editing, compiling, building, debugging, and online help are integrated in one graphical user interface. • • • Lecture 1 Borland Jbuilder Microsoft Visual J++ Net Beans Eclipse Blue. J We will be using plain text editor (preferably Notepad) © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Characteristics of Java • • • Lecture 1 Java Is Simple Java Is Object-Oriented

Characteristics of Java • • • Lecture 1 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 © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Characteristics of Java • • • Lecture 1 Java is partially modeled on C++,

Characteristics of Java • • • Lecture 1 Java is partially modeled on C++, but greatly Java Is Simple simplified and improved 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 © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Characteristics of Java • • • Lecture 1 Java Is Simple Java Is Object-Oriented

Characteristics of Java • • • Lecture 1 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 inherently object-oriented. Object-oriented programming provides great flexibility, modularity, clarity, and reusability through encapsulation, inheritance, and polymorphism © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Characteristics of Java • • • Lecture 1 Java Is Simple Java Is Object-Oriented

Characteristics of Java • • • Lecture 1 Java Is Simple Java Is Object-Oriented Java Is Distributed computing involves several computers working together on a network. Java is designed to Java Is Interpreted make distributed computing easy. Java Is Robust Java Is Secure Java Is Architecture-Neutral Java Is Portable Java's Performance Java Is Multithreaded Java Is Dynamic © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Characteristics of Java • • • Lecture 1 Java Is Simple Java Is Object-Oriented

Characteristics of Java • • • Lecture 1 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 You need an interpreter to run Java programs. The programs are compiled into the Java Virtual Machine code called bytecode. The bytecode is machine-independent and can run on any machine that has a Java interpreter, which is part of the Java Virtual Machine (JVM). © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Characteristics of Java • • • Lecture 1 Java Is Simple Java Is Object-Oriented

Characteristics of Java • • • Lecture 1 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 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. © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Characteristics of Java • • • Lecture 1 Java Is Simple Java Is Object-Oriented

Characteristics of Java • • • Lecture 1 Java Is Simple Java Is Object-Oriented Java Is Distributed Java Is Interpreted Java Is Robust Java implements several security mechanisms to Java Is Secure Java Is Architecture-Neutral protect your system against harm caused by stray programs. Java Is Portable Java's Performance Java Is Multithreaded Java Is Dynamic © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Characteristics of Java • • • Lecture 1 Java Is Simple Java Is Object-Oriented

Characteristics of Java • • • Lecture 1 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 Write once, run anywhere With a Java Virtual Machine (JVM), you can write one program that will run on any platform. © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Characteristics of Java • • • Lecture 1 Java Is Simple Java Is Object-Oriented

Characteristics of Java • • • Lecture 1 Java Is Simple Java Is Object-Oriented Java Is Distributed Java Is Interpreted Java Is Robust Java Is Secure Java Is Architecture-Neutral Because Java is architecture neutral, Java programs Java Is Portable are portable. They can be run on any platform Java's Performance without being recompiled. Java Is Multithreaded Java Is Dynamic © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Characteristics of Java • • • Lecture 1 Java Is Simple Java Is Object-Oriented

Characteristics of Java • • • Lecture 1 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 Because Java is architecture Java's Performance neutral, Java programs are portable. They can be Java Is Multithreaded run on any platform without being recompiled. Java Is Dynamic © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Characteristics of Java • • • Lecture 1 Java Is Simple Java Is Object-Oriented

Characteristics of Java • • • Lecture 1 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 Multithread programming is smoothly integrated Java Is Multithreaded in Java, whereas in other languages you have to Java Is Dynamic call procedures specific to the operating system to enable multithreading. © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Characteristics of Java • • • Lecture 1 Java Is Simple Java Is Object-Oriented

Characteristics of Java • • • Lecture 1 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 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. © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Sample Java Program package sample; import java. lang. *; // Optional public class Welcome

Sample Java Program package sample; import java. lang. *; // Optional public class Welcome { public static void main(String[] args) { System. out. println("Welcome to Java!"); } } Lecture 1 © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Creating, Compiling and Executing Java Program • Use any text editor or IDE to

Creating, Compiling and Executing Java Program • Use any text editor or IDE to create and edit a Java source-code file • The source file must end with the extension. java and must have exactly the same name as the public class name Welcome. java • Compile the. java file into java byte code file (Java bytecode is the instruction set of the Java virtual machine) javac Welcome. java If there are no syntax errors, the compiler generates a bytecode file with. class extension • Run the byte code - java Welcome Lecture 1 © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Creating, Compiling and Executing Java Program Lecture 1 © LPU : : CSE 310

Creating, Compiling and Executing Java Program Lecture 1 © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Java Runtime Environment (JRE) and Java Virtual Machine (JVM) JDK The JDK includes the

Java Runtime Environment (JRE) and Java Virtual Machine (JVM) JDK The JDK includes the JRE plus command-line development tools such as compilers and debuggers that are necessary or useful for developing applets and applications JRE The JRE provides the libraries, Java virtual machine, and other components necessary for you to run applets and applications written in the Java programming language JVM The Java virtual machine is an abstract computing machine that has an instruction set and manipulates memory at run time. The Java virtual machine is ported to different platforms to provide hardware- and operating system-independence. Lecture 1 © LPU : : CSE 310 Programming in Java : : Sawal Tandon

Java Runtime Environment (JRE) and Java Virtual Machine (JVM) Java Development Kit (JDK) Java

Java Runtime Environment (JRE) and Java Virtual Machine (JVM) Java Development Kit (JDK) Java Language Development Tools and APIs java, javac, Javadoc Java Runtime Environment (JRE) Deployment Technology User Interface Toolkits - AWT, Swing Libraries Java Virtual Machine (JVM) Lecture 1 © LPU : : CSE 310 Programming in Java : : Sawal Tandon