Lecture 1: Introduction to Java

Similar documents
Chapter 1 Introduction to Java

Chapter 1 Introduction to Computers, Programs, and Java

Objectives. Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer?

Chapter 1 Introduction to Computers, Programs, and Java

Java Language. Programs. Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs.

Introduction to Java Programming CPIT 202. WEWwwbvxnvbxmnhsgfkdjfcn

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1 Introduction to Computers, Programs, and Java

Networks Programming Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000)

Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer? A Bit of History

Module 1: Introduction to Computers, Programs, and Java

Chapter 1: Introduction to Computers, Programs, and Java

Introduction to Java. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Chapter 1 Introduction to Computers, Programs, and Java

Lesson 01 Introduction

Introduction to Computers, Programs, and Java. CSE 114, Computer Science 1 Stony Brook University

II. Compiling and launching from Command-Line, IDE A simple JAVA program

Introduction. Introduction to OOP with Java. Lecture 01: Introduction to OOP with Java - AKF Sep AbuKhleiF -

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Getting Started. Chapter 1. Java Programming FROM THE BEGINNING. Chapter 1: Getting Started

History Introduction to Java Characteristics of Java Data types

Chapter 1 Introduction to Computers, Programs, and Java

Introduction to OOP Using Java Pearson Education, Inc. All rights reserved.

Introduction to JAVA Programming Language

Lecture 1: Introduction to Java

Eng. Mohammed S. Abdualal

Outline. Introduction to Java. What Is Java? History. Java 2 Platform. Java 2 Platform Standard Edition. Introduction Java 2 Platform

CHAPTER 1 INTRODUCTION TO COMPUTERS, PROGRAMS, AND JAVA. Objectives

CHAPTER 1. Introduction to JAVA Programming

Programming: detailed instructions which tell the computer hardware what to do aka software Computer Science: the study NOT of computers, but of what

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995

Chapter 1 Introduction to Computers, Programs, and Java

Introduction to Java. Lecture 1 COP 3252 Summer May 16, 2017

Introduction to Java Programming

IQTIDAR ALI Lecturer IBMS Agriculture University Peshawar

Learning objectives. The Java Environment. Java timeline (cont d) Java timeline. Understand the basic features of Java

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

This lecture will take you through simple and practical approach while learning Java Programming language.

Lecture 1: Overview of Java

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Elements of Computers and Programming Dr. William C. Bulko. What is a Computer?

1. Introduction. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

Java Programming Language Mr.Rungrote Phonkam

Certified Core Java Developer VS-1036

An Introduction to Software Engineering. David Greenstein Monta Vista High School

Introduction to Java

Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of

Object Oriented Concepts and Programming (CSC244) By Dr. Tabbasum Naz

The Computer System. Hardware = Physical Computer. Software = Computer Programs. People = End Users & Programmers. people

Supplement B. Creating, Compiling and Running Java Programs from the Command Window

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Getting Started With Java

Part I: Fundamentals of Programming

Index. Course Outline. Grading Policy. Lab Time Distribution. Important Instructions

Eng. Mohammed Alokshiya

Chapter 1. Introduction to Computers and Java Objects. Background information. » important regardless of programming language. Introduction to Java

CSE 421 Course Overview and Introduction to Java

Before you start with this tutorial, you need to know basic Java programming.

Introduction to Computers and Java

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Introduction to Computers and Java

Introduction Basic elements of Java

Introduction to Computers and Java

Getting Started with Java. Atul Prakash

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Programming with Java

9/11/08 (c) 2008 Matthew J. Rutherford Class (c) 2008 Matthew J. Rutherford Class

CT 229. CT229 Lecture Notes. Labs. Tutorials. Lecture Notes. Programming II CT229. Objectives for CT229. IT Department NUI Galway

C++ Spring Break Packet 11 The Java Programming Language

Lecture 1 Java SE Programming

Class List. Java Must Have. Class Goals. Class Goals. Schedule

Introduction to Java and OOP. Hendrik Speleers

B.V. Patel Institute of BMC & IT, UTU 2014

G51OOP. Object Oriented Programming Comp Sci University of Nottingham Unit 1 : Introduction

CS260 Intro to Java & Android 02.Java Technology

GETTING STARTED. The longest journey begins with a single step. In this chapter, you will learn about: Compiling and Running a Java Program Page 2

Advanced Object-Oriented Programming Introduction to OOP and Java

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Eclipse Tutorial. For Introduction to Java Programming By Y. Daniel Liang

Chapter 1: Introduction to Computers and Java

Course Outline. Introduction to java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

JDB - QUICK GUIDE JDB - INTRODUCTION

CHAPTER 1 Introduction to Computers and Java

Programming Languages FILS Andrei Vasilateanu

BASICS.

Core Java Syllabus. Overview

Computer Science. ESC 120 Introduction to Engineering Design

Computer Basics 1/24/13. Computer Organization. Computer systems consist of hardware and software.

TTh 9.25 AM AM Strain 322

Seminar report Java Submitted in partial fulfillment of the requirement for the award of degree Of CSE

COMP Computer Basics. Yi Hong May 13, 2015

Introduction to Java. Nihar Ranjan Roy.

Introduction. Overview of the Course on Java. Overview of Part 1 of the Course

Lecture 1 - Introduction (Class Notes)

1. What is Jav a? simple

Computer Basics 1/6/16. Computer Organization. Computer systems consist of hardware and software.

CS335 Graphics and Multimedia

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

Transcription:

Lecture 1: Introduction to Java 1

Programs Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs. Without programs, a computer is an empty machine. Computers do not understand human languages, so you need to use computer languages to communicate with them. Programs are written using programming languages. 2

Programming Languages Machine Language Assembly Language High Level Language Machine language g is a set of primitive instructions built into every computer. The instructions are in the form of binary code, so you have to enter binary codes for various instructions. Program with native machine language is a tedious process. Moreover the programs are highly difficult to read and modify. For example, to add two numbers, you might write an instruction in binary like this: 1101101010011010 3

Programming Languages Machine Language Assembly Language High Level Language Assembly languages g were developed to make programming easy. Since the computer cannot understand assembly language, however, a program called assembler is used to convert assembly language programs into machine code. For example, to add two numbers, you might write an instruction in assembly code like this: ADDF3 R1, R2, R3 Assembly Source File Machine Code File ADDF3 R1, R2, R3 Assembler 1101101010011010 4

Programming Languages Machine Language Assembly Language High Level Language The high level languages are English likelike and easy to learn and program. For example, the following is a high level language statement that computes the area of a circle with radius 5: area = 5 * 5 * 3.1415; 5

Popular High Level Languages COBOL (COmmon Business Oriented Language) FORTRAN (FORmula TRANslation) BASIC (Beginner All purpose Symbolic Instructional Code) Pascal (named for Blaise Pascal) Ada (named for Ada Lovelace) C (whose developer designed B first) Visual Basic (Basic like visual language developed by Microsoft) Delphi (Pascal like like visual language developed by Borland) C++ (an object oriented language, based on C) C# (a Java like language developed by Microsoft) Java (We will studying in this course) 6

Compiling Source Code A program written in a high level language is called a source program. Since a computer cannot understand a source program. Program called a compiler is used to translate t the source program into a machine language program called an object program. The object program is often then linked with other supporting library code before the object can be executed on the machine. Source File Compiler Machine-language File Linker Executable File Library Code 7

Why Java? The answer is that Java enables users to develop and deploy applications on the Internet for servers, desktop computers, and small hand held devices. The future of computing is being profoundly influenced by the Internet, and Java promises to remain a big part of that future. Java is a general purpose p programming glanguage. g Java is the Internet programming language. 8

Java, Web, and Beyond Java can be used to develop Web applications. Java Applets Java Web Applications Java can also be used to develop applications for hand held devices such as Palm and cell phones 9

Examples of Java s Versatility (Applets) 10

PDA and Cell Phone 11

Characteristics of 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 www.cs.armstrong.edu/liang/intro8e/javacharacteristics.pdf Is Dynamic 12

Characteristics of Java Java Is Simple Java is partially modeled on C++, but greatly 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 simplified and improved. Some people refer to Java as "C++ " because it is like C++ but with more functionality and fewer negative aspects. 13

Characteristics of Java Java Is Simple Java is inherently object oriented. Alth h bj t i t d l Java Is Object Oriented Java Is Distributed Java Is Interpreted t object oriented. oriented Object oriented programming (OOP) is a popular Java Is Robust Java Is Secure Java Is Architecture Neutral techniques. Java Is Portable Java's Performance Java Is Multithreaded Java Is Dynamic Although many object oriented languages began strictly as procedural languages, Java was designed from the start to be programming approach that is replacing traditional procedural programming 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. 14

Characteristics of Java Java Is Simple Distributed computing involves several Java Is Object Oriented computers working together on a network. Java is designed to make Java Is Distributed distributed computing easy. Since Java Is Interpreted t networking capability is inherently Java Is Robust integrated into Java, writing network programs is like sending and receiving Java Is Secure data to and from a file. Java Is Architecture Neutral Java Is Portable Java's Performance Java Is Multithreaded Java Is Dynamic 15

Characteristics of Java Java Is Simple You need an interpreter to run Java Java Is Object Oriented Th Java Is Distributed Java Is Interpreted t Java Is Robust Java Is Secure Java Is Architecture Neutral Java Is Portable Java's Performance Java Is Multithreaded Java Is Dynamic programs. The programs are compiled into the Java Virtual Machine code called bytecode. The bytecode is machine independent d and can run on any machine that has a Java interpreter, which is part of the Java Virtual Machine (JVM). 16

JAVA Code Life Cycle 17

ByteCode & JVM ByteCode ByteCode: Unlike C/C++, which is compiled into machine language for a specific hardware platform, Java programs are compiled into an intermediate bytecode language. The bytecode is then compiled into machine language by a runtime program called the "Java Virtual Machine" (JVM) "Java Virtual Machine" (JVM):The JVM essentially runs between the computer and the java program. Java is designed so that any java program can run on any machine. This is because the JVM will interpret the Operating System independent java code and execute the commands needed for the particular Operating System you are trying to run the program on at the time. Java Program Execute some command JVM Translate the command for this computer Computer For NOW: Lets assume that JVM and JRE Java Runtime Environment are same. Later we will discus the difference between JVM and JRE as well. 18

Characteristics of Java Java Is Simple Java Is Object Oriented Java Is Distributed Java Is Interpreted t Java Is Robust Java Is Secure Java Is Architecture Neutral Java Is Portable 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 errorprone programming constructs found in other languages. Java has a runtime exception handling feature to provide programming support for robustness. 19

Characteristics of Java Java Is Simple Java Is Object Oriented Java Is Distributed Java Is Interpreted t Java Is Robust Java Is Secure Java Is Architecture Neutral Java Is Portable Java Is Multithreaded Java Is Dynamic Java implements several security mechanisms to protect your system against harm caused by stray programs. 20

Characteristics of Java Java Is Simple Write once, run anywhere Java Is Object Oriented Java Is Distributed Java Is Interpreted t Java Is Robust Java Is Secure Java Is Architecture Neutral Java Is Portable Java Is Multithreaded Java Is Dynamic With a Java Virtual Machine (JVM), you can write one program that will run on any platform. 21

Java Is Architecture Neutral 22

OS Independence 23

Characteristics of Java Java Is Simple Java Is Object Oriented Java Is Distributed Java Is Interpreted t Java Is Robust Java Is Secure Java Is Architecture Neutral Java Is Portable Java Is Multithreaded Java Is Dynamic Because Java is architecture neutral, Java programs are portable. They can be run on any platform without being recompiled. 24

Characteristics of Java Java Is Simple Java Is Object Oriented Java Is Distributed Java Is Interpreted t Java Is Robust Java Is Secure Java Is Architecture Neutral Java Is Portable Java Is Multithreaded Java Is Dynamic Multithread programming is smoothly integrated in Java, whereas in other languages you have to call procedures specific to the operating system to enable multithreading. 25

Characteristics of Java Java Is Simple Java Is Object Oriented Java Is Distributed Java Is Interpreted t Java Is Robust Java Is Secure Java Is Architecture Neutral Java Is Portable Java was designed to adapt to an evolving Java Is Multithreaded Java Is Dynamic environment. New code can be loaded d 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. 26

JDK Versions JDK 1.02 (1995) JDK 1.1 (1996) JDK 1.2 (1998) JDK 1.3 (2000) JDK 1.4 (2002) JDK 1.5 (2004) a. k. a. JDK 5 or Java 5 JDK 1.6 (2006) a. k. a. JDK 6 or Java 6 JDK 1.7 (possibly 2010) a. k. a. JDK 7 or Java 7 27

JDK Editions Java Standard Edition (J2SE) J2SE can be used to develop client side standalone applications or applets. Java Enterprise Edition i (J2EE) J2EE can be used to develop server side applications such as Java servlets and Java ServerPages. Java Micro Edition (J2ME). J2ME can be used to develop applications for mobile devices such as cell phones. This Course uses J2SE to introduce Java programming. 28

Popular Java IDEs NetBeans Open Source by Sun Eclipse Open Source by IBM JEdit JCreator Or Plain old Notepad 29

A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } } 30

Creating and Editing Using NotePad To use NotePad, type notepad Welcome.java from the DOS prompt. p

Creating and Editing Using WordPad To use WordPad, type write Welcome.java from the DOS prompt. p 32

Creating, Compiling, and Running Programs Create/Modify Source Code Source code (developed by the programmer) public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } } Saved on the disk Source Code Byte code (generated by the compiler for JVM to read and interpret, not for you to understand) Method Welcome() 0 aload_0 Method void main(java.lang.string[]) 0 getstatic #2 3 ldc #3 <String "Welcome to Java!"> 5 invokevirtual #4 8return Compile Source Code i.e., javac Welcome.java stored on the disk Bytecode Run Byteode i.e., java Welcome If compilation errors Result If runtime errors or incorrect result 33

animation Trace a Program Execution Enter main method //This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } } 34

animation Trace a Program Execution Execute statement //This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } } 35

animation Trace a Program Execution //This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } } print a message to the console 36

Java Program Structure System.out is known as standard output object. The System.out.println displays its arguments in the command window Aj java program typically consists of one or more classes Usually a separate class in separate file Each file is named after the class that is defined in it Et Extension of ffilename.java Introduction to Java 37

Two More Simple Examples Wl Welcome1 ComputeExpression p 38

Compiling and Running Java from the Command Window Set path to JDK bin directory set path=c:\program Files\java\jdk1.6.0\bin Set classpath to include the current directory set classpath=. Compile javac Welcome.java Run java Welcome 39

Compiling Java Source Code You can port a source program to any machine with appropriate compilers. The source program must be recompiled, however, because the object program can only run on a specific machine. Nowadays computers are networked to work together. Java Bytecode Java Virtual Machine Any Computer Java was designed to run object programs on any platform. With Java, you write the program once, and compile the source program into a special type of object code, known as bt bytecode. The bytecodecan then run on any computer with a Java Virtual Machine, as shown below. Java Virtual Machine is a software that interprets Java bytecode. 40