Introduction to Java Presented by Daniel Rosenthal Friday, November 16 th, 2007.

Slides:



Advertisements
Similar presentations
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Advertisements

Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
NetBeans IDE Tal Maoz Na’ama Zahavi.
Introduction to Java Programming, 4E
Introduction to Java ISYS 350. A Brief History Sun Microsystems released this language in 1996 – Versions: 1.0 – 1.6 Java Development Kit, JDK – Standard.
For more Lectures and Notes Visit
Lab 1 Instructor: Jolanta Soltis.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
L EC. 01: J AVA FUNDAMENTALS Fall Java Programming.
01 Introduction to Java Technology. 2 Contents History of Java What is Java? Java Platforms Java Virtual Machine (JVM) Java Development Kit (JDK) Benefits.
LESSON 1 INTRODUCTION Compiled By: Edwin O. Okech [Tutor, Amoud University] JAVA PROGRAMMING.
NetBeans IDE Vishnuvardhan.M Dept. of Computer Science - SSBN.
CMSC 202 Computer Science II for Majors Fall 2009 Introduction.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps.
BASIC JAVA PROGRAMMING TUTORIAL. History  James Gosling and Sun Microsystems  Oak  Java, May 20, 1995, Sun World  Hot Java –The first Java-enabled.
CSC 142 A 1 CSC 142 Introduction to Java [Reading: chapter 0]
S.W. Ma/CIM/LWL41211/2 Prog. IIA Page 1 HKIVE (Lee Wai Lee Campus) Department of CIM Course : Year 2 Module : Programming IIA Textbook : Introduction.
M1G Introduction to Programming 2 4. Enhancing a class:Room.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Java Beserkers Group 4. Start of Java Development began on June of 1991 by a group of computer scientist at the Sun Mircrosystems Company Development.
CMSC 202 Computer Science II for Majors Object-Oriented Programming.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Programming Languages Machine.
Java Introduction Lecture 1. Java Powerful, object-oriented language Free SDK and many resources at
1.  At the end of this slide, student can:  Explore tools, features, properties and interface of the Textpad.  Creating a new project.  Open and run.
Sadegh Aliakbary Sharif University of Technology Fall 2012.
The Basics of Javadoc Presented By: Wes Toland. Outline  Overview  Background  Environment  Features Javadoc Comment Format Javadoc Program HTML API.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Java ACO101: Introduction to Computer Science. The History of Java Started out as a research project at Sun Microsystems in 1991 Code named “Green” Based.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Chapter 1: Introduction to Programs, and Java 1. Objectives To review programs (§ ). To understand the relationship between Java and the World Wide.
POS 406 Java Technology And Beginning Java Code
Introduction to Java Programming with Forte Y. Daniel Liang.
Java Programming Presented by Daniel Rosenthal Friday, November 30 th, 2007.
The Joy of Programming (also known as) Introduction to Object-Oriented Programming.
Introduction to Java Programming. Introduction Course Objectives Organization of the Book.
Session 1 Introduction to Java. Objectives Java Simplified / Session 1 / 2 of 32 Explain the history of Java Explain Java in brief List the types of Java.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
Application Architecture Using Java Hong Li. Introduction Developed by a team led by James Gosling at Sun Microsystem. Originally called Oak, designed.
Lecture 02. Java Virtual Machine(JVM) –set of computer software programs and data structures that use a virtual machine model for the execution of other.
Introduction Mehdi Einali Advanced Programming in Java 1.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Introduction to Java Programming. 2 Chapter 1 Introduction to Java and Forte F What Is Java? F Getting Started With Java Programming –Create, Compile.
introductory lecture on java programming
การเขียนโปรแกรมภาษา จาวา Java Programming อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 1.
ITP 109 Week 2 Trina Gregory Introduction to Java.
Introduction to Programming 1 1 2Introduction to Java.
Introduction to JAVA Programming
Introduction to Java Programming, 4E Y. Daniel Liang.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Fundamental of Java Programming (630002) Unit – 1 Introduction to Java.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
Introduction CMSC 202 Fall Instructors Mr. Ryan Bergeron – Lecture Section 01 Tues/Thu 1:00 – 2:15 am, Sondheim 111 – Lecture Section 04 Tues/Thu.
Object Oriented Programming in
Chapter 1 Introduction to Computers, Programs, and Java
Introduction to Advanced Java Programming
Introduction Enosis Learning.
Introduction Enosis Learning.
آشنایی با جاوا Introduction to Java
Advanced Programming Fall 2017.
(Computer fundamental Lab)
Java History, Editions, Version Features
Review of Previous Lesson
Outcome of the Lecture Upon completion of this lecture you will be able to understand Fundamentals and Characteristics of Java Language Basic Terminology.
from Lutz Dietrich and Hans Kluge
Presentation transcript:

Introduction to Java Presented by Daniel Rosenthal Friday, November 16 th, 2007

What is Java? Java is a cross platform, object-oriented programming language. It was created by Sun Microsystems and first made publicly available in January 1996.

Java History (1 of 2) Java was designed and implemented by James Gosling. The Java language is specified by the book The Java Language Specification, Third Edition by James Gosling, Bill Joy, Guy Steele, and Gilad Bracha (ISBN: ). It started in 1991 as a project, code-named “Green”, to develop a platform for consumer devices, such as cable tv switchboxes. Only later when the world wide web caught on in 1995 was the project refocused towards creating a general purpose programming language.

Java History (2 of 2) Java was originally called Oak, because of a tree outside of the window of James Gosling’s office at Sun, and was later renamed to Java when it was discovered a language named Oak already existed. The name “Java” was chosen because the creators of the language often discussed ideas for the language at a local coffee shop.

What makes Java unique? Java is run inside a piece of software known as a Java Virtual Machine. In many languages, such as C and C++, the source code (.c and.cpp files) is portable. What makes Java unique is that Java’s executable code is also portable (.class files). This means that the same application can be run without modification on any system that has a Java Virtual Machine without being recompiled.

What makes Java unique? (cont.) Java programs require a Java Virtual Machine to run. The Java Virtual Machine is written in C and C++, and has been ported to many platforms, including desktop computers running Windows and Mac OS X, to high-end servers running Solaris and Linux, to mobile phones and PDA’s.

Advantages of Java Available on almost all platforms Standardized (by Sun) Well documented Makes many traditionally difficult tasks very easy, including networking, multithreading, and cross-platform GUI programming (GUI stands for graphical user interface) Very large API Most skills learned while using Java apply elsewhere

Java Terminology Java Virtual Machine (JVM) – An abstract machine architecture specified by the Java Virtual Machine Specification, Second Edition by Tim Lindholm and Frank Yellin (ISBN: ). Java Runtime Environment (JRE) – A runtime environment which implements Java Virtual Machine, and provides all class libraries and other facilities (such as JNI) necessary to execute Java programs. This is the software on your computer that actually runs Java programs. Note: These two terms (JVM and JRE) are often used interchangeably, but it should be noted that they are not technically the same thing.

More Java Terminology Java Development Kit (JDK) – The basic tools necessary to compile, document, and package Java programs (javac, javadoc, and jar, respectively). The JDK includes a complete JRE.

Java Platforms There are three main platforms for Java: Java SE (short for Standard Edition) – runs on desktops and laptops Java ME (short for Micro Edition) – runs on mobile devices such as cell phones Java EE (short for Enterprise Edition) – runs on servers

Java and Blu-ray Blu-ray – Sony’s high definition disc format (built-in support on PlayStation 3). Holds 25 GB per side. The Blu-ray standard specifies that a Java Runtime Environment must be present in all Blu-ray Disc players. The name of the Java platform on Blu-ray Disc players is called BD-J.

Java Versions Sun has a history of choosing poor version numbering schemes, and for renumbering a version after it has been publicly released. The names of the platforms have also been changed after being publicly released.

Java Version History Java 1.0 (JDK 1.0) – Released January 1996 Java 1.1 (JDK 1.1) – Released in February 1997 Java 1.2 (JDK 1.2) / J2SE 1.2 (J2SE SDK 1.2) – Released in December 1998 Development Kit initially named JDK 1.2 but renamed three days after release to J2SE SDK 1.2 (short for Java 2 Standard Edition) Java 2 Micro Edition (J2ME) and Java 2 Enterprise Edition (J2EE) released Java 2 Standard Edition 1.3 (J2SE SDK 1.3) – Released in May 2000 Java 2 Standard Edition 1.4 (J2SE SDK 1.4) – Released in February 2002 Java 2 Standard Edition 5.0 (J2SE SDK 5.0) – Released in September 2004 Originally named 1.5 – many official documents still refer to this as version Java SE 6 (Java SE SDK) – Released in December 2006 J2SE SDK renamed back to Java SE SDK

Current Java Versions The most current versions of the respective releases of Java are: Java SE 6 Java EE 5 Java ME 1.1 (depends on configuration)

Writing Programs in Java Tools required to write Java programs: Java Development Kit 6 (JDK 6). This can be obtained from java.sun.com. Specifically: After downloading and installing the most recent JDK, you must set your CLASSPATH and JAVA_HOME environment variables. JAVA_HOME should be the location of your JDK installation. If you want to use Java from the command line, you must also add the jdk/bin directory to your PATH variable.

Java Development Kit (JDK) Comes with all tools necessary to compile and run Java programs, including a complete Java Runtime Environment (JRE) (located in the jdk/jre directory). Get the most recent version from:

The Class Path The class path is a list of locations (folders) that are searched for classes when the Java Virtual Machine attempts to locate a referenced class. The CLASSPATH variable is an environment variable that specifies the class path on a given system. The CLASSPATH must be set and must include the current directory in order to run Java programs from the command line with the java command.

Setting the Class Path The CLASSPATH variables simply contains a list of absolute directories, separated by a system dependent separator. On Windows a semicolon “;” is used to separate directories, on Linux, Unix, Mac OS X, and Solaris, a colon “:” is used to separate directories. The reason for the discrepancy between Windows and Unix flavored operating systems is that absolute file paths in Windows can contain colons “:”, for example “C:\Program Files”, so colons can not be used to identify a boundary between path entries as it can be in Unix. This is the same reason why the PATH separator is different in Windows and Unix.

About Class Paths The class path must contain the current directory “.” or the Java interpreter (the java command) will be unable to find compiled class files and you will get an error similar to: Exception in thread "main" java.lang.NoClassDefFoundError: SomeClass/java The Java compiler (the javac command) automatically looks in the current directory when compiling files, but the Java interpreter only looks in the current directory if the class path is undefined. You would then be able to compile classes, but be unable to run them.

More About Class Paths The standard Java SE class libraries are located in jre/lib/rt.jar Any class libraries (.jar files) located in the jre/lib/ext directory are also available to Java programs. You don’t need to worry about adding jre/lib/rt.jar or jre/lib/ext to your classpath because both of these are searched automatically by both java and javac

Example class path Here are some example class paths: Windows: CLASSPATH=.;C:\Program Files\Java\jre1.6.0_01\lib\rt.jar;C:\Tomcat \lib\servlet-api.jar;C:\Tomcat \lib\jsp-api.jar;C:\Program Files\Java\jre1.6.0_02\lib\ext\QTJava.zip Linux: CLASSPATH=.:/usr/java/jdk1.5.0_03/jre/lib/rt.jar

Testing the Installation Once you have installed the JDK, set the CLASSPATH and JAVA_HOME environment variables, and updated your PATH variable, type the following on a command line: > javac –version You should get the following output: javac 1.6.0

JDK Important Locations jdk/bin – contains command line tools such as javac, java, javadoc, and jar jdk/jre – the location of the bundled JRE

Java Language Basics Program.java: The simplest Java program:

Java Language Basics This program will do nothing. Program.java: The simplest Java program:

Compiling from the Command Line To compile, type javac where “ ” is the name of the file you want to compile. For example: > javac Program.java This will output a file named “Program.class”.

Example Compilation on Windows

Running from the Command Line Once compiled, use the java command to run. The java command takes a single argument which is the name of the class containing a main() method that you wish to execute. You only need to specify the name of the class, not the full name of the.class file; if you specify the full name of the.class file, you will get an error. > java Program.class Exception in thread "main" java.lang.NoClassDefFoundError: Program/class > java Program //execution of Program

Example Run in Windows

Java Language Basics A slightly more useful example: Program.java: This program will print “My program is running!” to the screen.

Running from the Command Line Same steps as before: > javac Program.java > java Program

Example Run in Windows

Elements of a Java Program Everything must be declared inside a class. Program.java: class Program Classes in Java are analogous to classes in C++.

Elements of a Java Program Classes can contain fields and methods. Program.java: main() method Methods in Java are the equivalent of member functions in C++. Fields in Java are the equivalent of data members in C++.

Elements of a Java Program Members are either class or instance. Program.java: main() (class method – declared static) Instance members exist for every object (instance) of a class (this is the default). Class members only have one copy per class, and are declared with static.

Elements of a Java Program Field example. Program.java: Instance members exist for every object (instance) of a class (this is the default). Class members only have one copy per class, and are declared with static. number field number is an instance field because it is not declared static

Elements of a Java Program Every class and member must have a visibility. Program.java: A visibility indicates what places in a program the class, field, or method is accessible from. Visibility keywords: public, private, and protected. visibility specifiers

Java Tools – Javadocs Javadocs are html documentation files generated by the javadoc tool, which generates html documentation from source code (it looks for comments of the form /** … */). Javadocs for the Java SE API’s are online:

Java SE API Documentation

Introduction to NetBeans IDE

The IDE in NetBeans IDE stands for Integrated Development Environment. IDE’s are used by professional programmers to accelerate the completion of certain tasks. NetBeans is Sun’s free, open source IDE for Java (it is also written in Java, which means it is available on any platform that Java is available on). NetBeans supports plugins for working in other languages as well, such as C and C++.

About NetBeans IDE Website at Current version of NetBeans is 5.5 with the release of 6.0 expected by the end of this year or the beginning of next year (version 6.0 is currently a release candidate).

Cool Features of NetBeans Syntax highlighting Code completion Integrated debugger Automatic project build facilities using Apache Ant Code refactoring, regular expression search and replace Matisse GUI builder

Web Programming (1 of 2) Java Applets – Run inside of web browser Screenshots:

Web Programming (2 of 2) Java Web Start – Launches Java programs outside of browser with fewer security restrictions than applets (but more security restrictions than regular desktop Java programs) Screenshots: