Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Introduction to Java ISYS 350

2 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

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

4

5 Download Java SE Development Kit, SDK http://java.sun.com/javase/downloads/index.j sp http://java.sun.com/javase/downloads/index.j sp JDK 6 Update 14 with JavaFX SDK Select or Create a folder for downloaded file: – For example. C:\JavaDownload

6

7 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: http://java.sun.com/javase/6/docs/technotes/tools/w indows/jdkfiles.html

8 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:

9 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”

10 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

11 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

12 Slide 12

13 Slide 13

14 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

15 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

16 Download NetBeans IDE Before you install the IDE, the Java SE Development Kit must be installed on your system. Website: http://www.netbeans.org/downloads/index.html http://www.netbeans.org/downloads/index.html Choose All that includes Java, PHP with bundled servers. NetBeans IDE 6.7.1 Installation Instructions – http://www.netbeans.org/community/releases/67/ins tall.html

17 NetBeans’ Tutorials From NetBeans home page: – http://www.netbeans.org/ – click Tutorials link Quick Start Guide

18 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.

19 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.

20 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. "); }

21 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.

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

23 Java Language Tutorials http://java.sun.com/docs/books/tutorial/java/ TOC.html http://java.sun.com/docs/books/tutorial/java/ TOC.html Questions and Exercises section at the end of each topic.

24 Murach’s Java SE 6, C1© 2007, Mike Murach & Associates, Inc. Slide 24 Java API page: http://java.sun.com/javase/7/docs/api/ 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.

25 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 */

26 Slide 26 Naming an Identifier

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

28 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.

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

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

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

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

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

34 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.

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

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

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

38 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();

39 How to use Java classes

40 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.

41 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);

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

43 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)); }

44 Formula to Expression

45 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.*;


Download ppt "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."

Similar presentations


Ads by Google