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.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Object Orientated Programming
Introduction to Java Programming, 4E
Unit2: Object-oriented programming Getting started with Java Jin Sa.
Lab 1 Instructor: Jolanta Soltis.
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
Introduction to Java.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
PHY281Introduction to JavaSlide 1 Introduction to Java In this section we will learn how how to use Java and write our first Java Applet:  The Java Development.
CS0007: Introduction to Computer Programming Setting Up Java.
01 Introduction to Java Technology. 2 Contents History of Java What is Java? Java Platforms Java Virtual Machine (JVM) Java Development Kit (JDK) Benefits.
Marlene Galea.  The JDK (Java Development Kit)  An IDE (Integrated Development Environment) ◦ Different IDEs include:  JCreator  NetBeans  BlueJ.
Introduction to Java Presented by Daniel Rosenthal Friday, November 16 th, 2007.
Introducing Java.
From BlueJ to NetBeans SWC 2.semester.
(C) 2010 Pearson Education, Inc. All rights reserved.  Java programs normally go through five phases  edit  compile  load  verify  execute.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
Fundamentals of Java.  Explain the structure of a Java class  List and explain steps to write a Java program  Identify the benefits of NetBeans IDE.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Programming Languages Machine.
UCSC All rights reserved. No part of this material may be reproduced and sold. 1 IT1202-Fundamentals Of Programming (Using JAVA) Interacting with.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Appendix E The EZJava.
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.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
Java and C# [this is a bonus – it is not a required lesson] ACO101: Introduction to Computer Science.
© 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
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Introduction to Java Programming with Forte Y. Daniel Liang.
Java Programming Presented by Daniel Rosenthal Friday, November 30 th, 2007.
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
JAVA PROGRAMMING BASICS CHAPTER 2. History of Java Begin with project Green in 1991 founded by Patrick Noughton, Mike Sheridan and James Gosling who worked.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
CS Software Studio Java Lab 1 Meng-Ting Wang PLLAB, Computer Science Department, National Tsing-Hua University.
EIE375 BlueJ: Getting Started Dr Lawrence Cheung.
Introduction to Java The Java Platform, The Java Language, JDK, Eclipse Svetlin Nakov Technical Trainer Software University
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
JAVA Programming “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
22-July-2002cse142-13B-Development © 2002 University of Washington1 Development Tools CSE 142, Summer 2002 Computer Programming 1
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
The Java Platform, The Java Language, JDK, IntelliJ
Application Architecture Using Java Hong Li. Introduction Developed by a team led by James Gosling at Sun Microsystem. Originally called Oak, designed.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Today… “Hello World” ritual. Brief History of Java & How Java Works. Introduction to Java class structure. But first, next slide shows Java is No. 1 programming.
introductory lecture on java programming
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Overview of Programming.
Lecture1 Instructor: Amal Hussain ALshardy. Introduce students to the basics of writing software programs including variables, types, arrays, control.
3/5/2002e-business and Information Systems1 Java Java Java Virtual Machine (JVM) Java Application Program Interface (API) HW Kernel API Application Programs.
การเขียนโปรแกรมภาษา จาวา Java Programming อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 1.
ITP 109 Week 2 Trina Gregory Introduction to Java.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
1 1 1 Introduction to Java. 2 History of Java Java – Originally for intelligent consumer-electronic devices – Then used for creating Web pages with dynamic.
Introduction to Java Programming, 4E Y. Daniel Liang.
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
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.
Lecture 1b- Introduction
Introduction to Java Import Scanner class to use in our program
Java programming lecture one
How to Run a Java Program
CS115 HOW TO INSTALL THE JAVA DEVELOPMENT KIT (JDK)
Introduction to Java Brief history of Java Sample Java Program
Review of Previous Lesson
Presentation transcript:

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 Edition, SE and Enterprise Edition, EE – With versions 1.2 through 1.5, SE and EE were known as Java 2 Platform, J2SE and J2EE. – Latest version is called Java SE 6 and Java EE 6 Syntax is similar to C++ – Both languages are case-sensitive Web-based applications

Portability Java: Write Once Run Anywhere Java Source Code Java Byte Code (Intermediate Code) Java Byte Code Java Virtual Machine (JVM) Executable Code

Download Java SE Development Kit, SDK sp sp JDK 6 Update 14 with JavaFX SDK Select or Create a folder for downloaded file: – For example. C:\JavaDownload

Directories of the JDK Typical JDK directory: – C:\Program Files\Java\jdk1.6.0_14 Sub Directories: – bin: Java development tools including the Java compiler (javac) – Jre: Java Runtime Environment needed to run compiled Java programs – lib: Additional libraries used by the development tools – Note: indows/jdkfiles.html

Testing Java Installation public class TestApp { public static void main(String[] args) { System.out.println("Java has been successfully installed. "); } Demo: Use NotePad to create a Java program:

Save this program 1.The name of this program must mach the name of the public class. 2. It must have an extension “java” in lower case. 3. In the Save As box, enclose the name in quotation marks like this: “TestApp.java”

Start the Command Prompt and Change Path Start the command prompt: – Start/Run/ – Then, run this program: C:\WINDOWS\system32\cmd.exe Set the path to the bin folder in order to run java compiler: – Right click MyComputer icon and choose Properties – Select the Advanced tab and click on the Environment Variables button – Use the Enviroment Variables dialog box to edit the variable named Path – Type a semicolon and the path C:\Program Files\Java\jdk1.6.0_14\bin to the far right of the list of paths. From the Command prompt, change the directory to the program’s folder: – C: > CD C:\Java\Examples

Run a Java Program from Command Prompt Compile the program: javac TestApp.java – If no syntax error, a class with the same name will be created in the same folder Run the program: java TestApp

Slide 12

Slide 13

Integrated Development Environment, IDE An integrated development environment (IDE) also known as integrated design environment is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of: – a source code editor – a compiler and/or an interpreter – build automation tools – a debugger Examples: NetBeans, Eclipse

NetBeans IDE A free, open-source Integrated Development Environment for software developers. You get all the tools you need to create professional desktop, enterprise, web, and mobile applications. Support many languages: – Java, PHP, C++, Ruby Support many platforms: – Windows, Linux, Mac OS X and Solaris

Download NetBeans IDE Before you install the IDE, the Java SE Development Kit must be installed on your system. Website: Choose All that includes Java, PHP with bundled servers. NetBeans IDE Installation Instructions – tall.html

NetBeans’ Tutorials From NetBeans home page: – – click Tutorials link Quick Start Guide

Using NetBeans to Create the TestApp Java Program 1. Start NetBeans 2. Click File/New Project and select Java 3. Name project and specify project folder 4. Copy and paste the TestApp program’s statements to the generated Main method. 5. Click Run/Run Main project to test.

Class and Method Class: When develop a Java application, you code one or more classes for it. – Access modifier: Control the scope of a class public: Other classes can access it. private: Used only in a project. Method: A class may contain one or more methods which are pieces of code that perform tasks. The “main” method: – A special method that is automatically executed when the class that holds it is run. It is always declared to be public.

The Syntax for Declaring a Class public!|or private class ClassName { statements } public class TestApp { public static void main(String[] args) { System.out.println("Java has been successfully installed. "); }

main Method Syntax public static void main(String[] args) – public: Other classes can access it. – static: Other classes can call this method directly without first creating an object. – void: The method won’t return any values. – The code in the parenthesis lists the arguments that the method uses. Every main method has an argument named args which is defined as an array of strings.

Package and Project Package: Related classes are organized into package. A project may contain one or more packages.

Java Language Tutorials TOC.html TOC.html Questions and Exercises section at the end of each topic.

Murach’s Java SE 6, C1© 2007, Mike Murach & Associates, Inc. Slide 24 Java API page: Java Application Program Interface, API API is an interface that defines the ways by which an application program may request services from libraries. API, provides all the classes that are included as part of the JDK. You can view the API documentation from the Java web site, or you can download and install it on your system.

Basic Coding Skills Statements: Direct the operation of the program. – Can continue from one line to next line – Spaces – Block of code: { } – Indentation for easy reading Comments: – Single-line comment: //comment – Block comment: /* comment comment */

Slide 26 Naming an Identifier

Murach’s Java SE 6, C2© 2007, Mike Murach & Associates, Inc. Slide 27

Write a Program that asks user to enter two numbers and displays the larger number Inputs: – two numbers entered via keyboard – Must be able to read the numbers – Must be able to save the numbers in the program Declare two variables Process: Compare the two numbers Output: – Must be able to display the result.

Murach’s Java SE 6, C2© 2007, Mike Murach & Associates, Inc. Slide 29

Murach’s Java SE 6, C2© 2007, Mike Murach & Associates, Inc. Slide 30

Murach’s Java SE 6, C2© 2007, Mike Murach & Associates, Inc. Slide 31

Murach’s Java SE 6, C2© 2007, Mike Murach & Associates, Inc. Slide 32

Murach’s Java SE 6, C2© 2007, Mike Murach & Associates, Inc. Slide 33

Using Java Classes To develop Java applications, we need to use many different Java classes. Groups of related Java classes are organized into packages. To use a class from a package we use the “import” statement to import the class.

Murach’s Java SE 6, C2© 2007, Mike Murach & Associates, Inc. Slide 35

Murach’s Java SE 6, C2© 2007, Mike Murach & Associates, Inc. Slide 36

Murach’s Java SE 6, C2© 2007, Mike Murach & Associates, Inc. Slide 37

Reading Data Entered from Keyboard Need utilities: – Class Scanner: A simple text scanner which can parse primitive types and strings java.util.Scanner Methods: nextDouble, nextInt – Must import the Scanner class to program. import java.util.Scanner; – System.in The "standard" input stream. This stream is already open and ready to supply input data. Typically this stream corresponds to keyboard input. Example: – Scanner sc = new Scanner(System.in) ; – double num1 = sc.nextDouble();

How to use Java classes

Murach’s Java SE 6, C2© 2007, Mike Murach & Associates, Inc. Slide 40 A static method of a class can be called directly without first creating an object from the class.

The larger of two numbers max method of the Math Class The max method is declared as static (see Java API) – public static float max(float a, float b) – Example: Math.max(num1,num2) Other methods: – public static double pow(double a, double b) a raises to the power of b Math.pow(a, b);

Display Result System.out Class – System.out.println(data) – System.out.print(data) System.out.println("The larger number is: " + Math.max(num1,num2));

Code Example import java.util.Scanner; public class Test2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in) ; System.out.println("enter the first number: "); double num1 = sc.nextDouble(); System.out.println("enter the second number: "); double num2 = sc.nextDouble(); System.out.println("The larger number is: " + Math.max(num1,num2)); }

Formula to Expression

Date Class java.util.Date The class Date represents a specific instant in time, with millisecond precision. – Date myDate = new Date(); – System.out.println("Today is: " + myDate.toString()); Note: import java.util.Date; Note: import java.util.*;