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

Similar documents
Chapter 1 Introduction to Computers, Programs, and Java

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

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

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Chapter 1 Introduction to Java

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

Lecture 1: Introduction to Java

Introduction to Java

Introduction to JAVA Programming Language

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

C++ Spring Break Packet 11 The Java Programming Language

CS 11 java track: lecture 1

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

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

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 Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

IQTIDAR ALI Lecturer IBMS Agriculture University Peshawar

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

Chapter 1 Introduction to Computers, Programs, and Java

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

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Objec+ves. Review. Basics of Java Syntax Java fundamentals. What are quali+es of good sooware? What is Java? How do you compile a Java program?

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

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

Chapter 1: Introduction to Computers and Java

CHAPTER 1 Introduction to Computers and Java

Java Programming Language Mr.Rungrote Phonkam

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

CompSci 125 Lecture 02

Programming. Syntax and Semantics

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

CHAPTER 1. Introduction to JAVA Programming

Pace University. Fundamental Concepts of CS121 1

Certified Core Java Developer VS-1036

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

Lecture 1: Overview of Java

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 Computers, Programs, and Java. What is a Computer?

CS11 Java. Fall Lecture 1

Getting Started with Java. Atul Prakash

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

Fundamentals of Programming. By Budditha Hettige

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

IT151: Introduction to Programming (java)

Section 2.2 Your First Program in Java: Printing a Line of Text

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

COT 3530: Data Structures. Giri Narasimhan. ECS 389; Phone: x3748

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

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

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

Full file at

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

Special Topics: Programming Languages

Programming Language Concepts: Lecture 2

Java Bytecode (binary file)

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

Introduction to Java. Nihar Ranjan Roy.

COE318 Lecture Notes Week 3 (Week of Sept 17, 2012)

The plan. Racket will return! Lecture will not recount every single feature of Java. Final project will be wri)ng a Racket interpreter in Java.

Introduction to Java

Chapter 1 Introduction to Computers, Programs, and Java

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

An overview of Java, Data types and variables

Chapter 1 Introduction to Computers, Programs, and Java

Introduction Basic elements of Java

Lesson 04: Our First Java Program (W01D4

Java language. Part 1. Java fundamentals. Yevhen Berkunskyi, NUoS

Program Fundamentals

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

Course information. Petr Hnětynka 2/2 Zk/Z

TTh 9.25 AM AM Strain 322

Programming with Java

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Introduction to Programming (Java) 2/12

Eng. Mohammed Alokshiya

CSE 421 Course Overview and Introduction to Java

CS335 Graphics and Multimedia

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

Code Ninjas: Introduction to Computer Science. Macomb Science Olympiad Presented by Swati Dharia

Eng. Mohammed S. Abdualal

The Java programming environment. The Java programming environment. Java: A tiny intro. Java features

CS101: Fundamentals of Computer Programming. Dr. Tejada www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++

Computer Programming, I. Laboratory Manual. Final Exam Solution

Section 2.2 Your First Program in Java: Printing a Line of Text

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Course information. Petr Hnětynka 2/2 Zk/Z

CS321 Languages and Compiler Design I. Winter 2012 Lecture 2

Project 1. Java Control Structures 1/17/2014. Project 1 and Java Intro. Project 1 (2) To familiarize with

Eclipse. JVM, main method and using Eclipse. Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

Assumptions. History

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

Introduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language

Getting Started With Java

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

Lesson 01 Introduction

Classes and objects. Chapter 2: Head First Java: 2 nd Edi4on, K. Sierra, B. Bates

Transcription:

Java Introduc)on

History of Java Java was originally developed by Sun Microsystems star:ng in 1991 James Gosling Patrick Naughton Chris Warth Ed Frank Mike Sheridan This language was ini:ally called Oak Renamed Java in 1995 2

What is Java A simple, object- oriented, distributed, interpreted, robust, secure, architecture neutral, portable, high- performance, mul:threaded, and dynamic language - - Sun Object- Oriented No free func:ons All code belong to some class Classes are in turn arranged in a hierarchy or package structure 3

What is Java Distributed Fully supports IPv4, with structures to support IPv6 Includes support for Applets: small programs embedded in HTML documents Interpreted The program are compiled into Java Virtual Machine (JVM) code called bytecode Each bytecode instruc:on is translated into machine code at the :me of execu:on 4

What is Java Robust Java is simple no pointers/stack concerns Excep:on handling try/catch/finally series allows for simplified error recovery Strongly typed language many errors caught during compila:on 5

Java The Most Popular 6

Java The Most Controversial 7

Java Edi:ons Java 2 Pla^orm, Standard Edi:on (J2SE) Used for developing Desktop based applica:on and networking applica:ons Java 2 Pla^orm, Enterprise Edi:on (J2EE) Used for developing large- scale, distributed networking applica:ons and Web- based applica:ons Java 2 Pla^orm, Micro Edi:on (J2ME) Used for developing applica:ons for small memory- constrained devices, such as cell phones, pagers and PDAs 8

Java pla^orm Compile javac HelloWorld.java 2387D47803 A96C16A484 54B646F541 06515EE464 public class HelloWorld { public static void main( String [] args ) { System.out.println( hello ); } } Java Interpreter Java Bytecode Windows NT Java Program ( Class File ) Java API Java Virtual Machine Hardware-Based Platform Java Platform HelloWorld.class Java Interpreter Power Macintosh 9

Java Development Environment Edit Create/edit the source code Compile Compile the source code Load Load the compiled code Verify Check against security restric:ons Execute Execute the compiled 10

Phase 1: Crea:ng a Program Any text editor or Java IDE (Integrated Development Environment) can be used to develop Java programs Java source- code file names must end with the.java extension Some popular Java IDEs are NetBeans Eclipse JCreator IntelliJ 11

Phase 2: Compiling a Java Program javac Welcome.java Searches the file in the current directory Compiles the source file Transforms the Java source code into bytecodes Places the bytecodes in a file named Welcome.class 12

Bytecodes They are not machine language binary code They are independent of any par:cular microprocessor or hardware pla^orm They are pla^orm- independent instruc:ons Another en:ty (interpreter) is required to convert the bytecodes into machine codes that the underlying microprocessor understands This is the job of the JVM (Java Virtual Machine) 13

JVM (Java Virtual Machine) It is a part of the JDK and the founda:on of the Java pla^orm It can be installed separately or with JDK A virtual machine (VM) is a soeware applica:on that simulates a computer, but hides the underlying opera:ng system and hardware from the programs that interact with the VM It is the JVM that makes Java a portable language 14

JVM (Java Virtual Machine) The same bytecodes can be executed on any pla^orm containing a compa:ble JVM The JVM is invoked by the java command java Welcome It searches the class Welcome in the current directory and executes the main method of class Welcome It issues an error if it cannot find the class Welcome or if class Welcome does not contain a method called main with proper signature 15

Phase 3: Loading a Program One of the components of the JVM is the class loader The class loader takes the.class files containing the programs bytecodes and transfers them to RAM The class loader also loads any of the.class files provided by Java that our program uses 16

Phase 4: Bytecode Verifica:on Another component of the JVM is the bytecode verifier Its job is to ensure that bytecodes are valid and do not violate Java s security restric:ons This feature helps to prevent Java programs arriving over the network from damaging our system 17

Phase 5: Execu:on Now the actual execu:on of the program begins Bytecodes are converted to machine language suitable for the underlying OS and hardware Java programs actually go through two compila:on phases Source code - > Bytecodes Bytecodes - > Machine language 18

Edi:ng a Java Program 19

Examining Welcome.java A Java source file can contain mul:ple classes, but only one class can be a public class Typically Java classes are grouped into packages (similar to namespaces in C++) A public class is accessible across packages The source file name must match the name of the public class defined in the file with the.java extension 20

Examining Welcome.java In Java, there is no provision to declare a class, and then define the member func:ons outside the class Body of every member func:on of a class (called method in Java) must be wrijen when the method is declared Java methods can be wrijen in any order in the source file A method defined earlier in the source file can call a method defined later 21

Examining Welcome.java public sta)c void main(string[] args) main is the star:ng point of every Java applica:on public is used to make the method accessible by all sta6c is used to make main a sta:c method of class Welcome. Sta:c methods can be called without using any object; just using the class name. JVM call main using the ClassName.methodName nota:on void means main does not return anything String args[ ] represents an array of String objects that holds the command line arguments passed to the applica:on. Where is the length of args array? 22

Examining Welcome.java Think of JVM as a outside Java en:ty who tries to access the main method of class Welcome main must be declared as a public member of class Welcome JVM wants to access main without crea:ng an object of class Welcome main must be declared as sta:c JVM wants to pass an array of String objects containing the command line arguments main must take an array of String as parameter 23

Examining Welcome.java System.out.println() Used to print a line of text followed by a new line System is a class inside the Java API out is a public sta:c member of class System out is an object of another class of the Java API out represents the standard output (similar to stdout or cout) println is a public method of the class of which out is an object 24

Examining Welcome.java System.out.print() is similar to System.out.println(), but does not print a new line automa:cally System.out.prinC() is used to print formajed output like prin^() in C In Java, characters enclosed by double quotes ( ) represents a String object, where String is a class of the Java API We can use the plus operator (+) to concatenate mul:ple String objects and create a new String object 25

Compiling a Java Program Place the.java file in the bin directory of your Java installa:on C:\Program Files\Java\jdk1.8.0_51\bin Open a command prompt window and go to the bin directory Execute the following command javac Welcome.java If the source code is ok, then javac (the Java compiler) will produce a file called Welcome.class in the current directory 26

Compiling a Java Program If the source file contains mul:ple classes then javac will produce separate.class files for each class Every compiled class in Java will have their own.class file.class files contain the bytecodes of each class So, a.class file in Java contains the bytecodes of a single class only 27

Execu:ng a Java Program Aeer successful compila:on execute the following command java Welcome Note that we have omi5ed the.class extension here The JVM will look for the class file Welcome.class and search for a public sta=c void main(string args[ ]) method inside the class If the JVM finds the above two, it will execute the body of the main method, otherwise it will generate an error and will exit immediately 28

Another Java Program 29

Examining A.java The variable of a class type is called a reference ob is a reference to A object Declaring a class reference is not enough, we have to use new to create an object Every Java object has to be instan:ated using keyword new We access a public member of a class using the dot operator (.) Dot (.) is the only member access operator in Java. Java does not have ::, - >, & and * 30

Primi:ve (built- in) Data types Integers byte 8- bit integer (new) short 16- bit integer int 32- bit signed integer long 64- bit signed integer Real Numbers float 32- bit floa:ng- point number double 64- bit floa:ng- point number Other types char 16- bit, Unicode 2.1 character boolean true or false, false is not 0 in Java 31

Boolean Type 32

Non- primi:ve Data types The non- primi:ve data types in java are Objects Array Non- primi:ve types are also called reference types 33

Primi:ve vs. Non- primi:ve type Primi:ve types are handled by value the actual primi:ve values are stored in variable and passed to methods int x = 10; public MyPrimi)ve(int x) { } Non- primi:ve data types (objects and arrays) are handled by reference the reference is stored in variable and passed to methods Box b = new Box(1,2,3); public MyNonPrimi)ve(Box x) { } 34

Java References Java references are used to point to Java objects created by new Java objects are always passed by reference to other func:ons, never by value Java references act as pointers but does not allow pointer arithme:c We cannot read the value of a reference and hence cannot find the address of a Java object We cannot take the address of a Java reference 35

Java References We can make a Java reference point to a new object By copying one reference to another ClassName ref2 = ref1; // Here ref1 is declared earlier By crea:ng a new object and assign it to the reference ClassName ref1 = new ClassName(); We cannot place arbitrary values to a reference except the special value null which means that the reference is poin:ng to nothing ClassName ref1 = 100; // compiler error ClassName ref2 = null; // no problem 36

Java References 37

Textbook We will follow Java 8 Java: The Complete Reference, 9th Edi:on by Herbert Schildt Web: hjp://teacher.buet.ac.bd/rifat/cse201.html hjp://cse.buet.ac.bd/moodle/course/view.php?id=88 38