10/10/2015Assoc. Prof. Stoyan Bonev1 COS240 O-O Languages AUBG, COS dept Lecture 10b Title: Running Programs & IDEs (Java) Reference: COS240 Syllabus.

Slides:



Advertisements
Similar presentations
1 Copyright © 2005, Oracle. All rights reserved. Introducing the Java and Oracle Platforms.
Advertisements

Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Lab#1 (14/3/1431h) Introduction To java programming cs425
Object Orientated Programming
1 Fall 2008ACS-1903 Chapter 1 Topics Java History Java Programs Why Program? Computer Systems: Hardware and Software Programming Languages What Is a Program.
How to Create a Java program CS115 Fall George Koutsogiannakis.
Java Programming Working with TextPad. Using TextPad to Work with Java This text editor is designed for working with Java You can download a trial version.
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.
Unit2: Object-oriented programming Getting started with Java Jin Sa.
Introduction to Java.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
CS0007: Introduction to Computer Programming Setting Up Java.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
L EC. 01: J AVA FUNDAMENTALS Fall Java Programming.
Marlene Galea.  The JDK (Java Development Kit)  An IDE (Integrated Development Environment) ◦ Different IDEs include:  JCreator  NetBeans  BlueJ.
BASIC JAVA PROGRAMMING TUTORIAL. History  James Gosling and Sun Microsystems  Oak  Java, May 20, 1995, Sun World  Hot Java –The first Java-enabled.
Introducing Java.
CS413: Java Programming language Applications Applets
(C) 2010 Pearson Education, Inc. All rights reserved.  Java programs normally go through five phases  edit  compile  load  verify  execute.
 Java Programming Environment  Creating Simple Java Application  Lexical Issues  Java Class Library.
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.
Using Eclipse. What is Eclipse? The Eclipse Platform is an open source IDE (Integrated Development Environment), created by IBM for developing Java programs.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Programming Languages Machine.
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.
UCSC All rights reserved. No part of this material may be reproduced and sold. 1 IT1202-Fundamentals Of Programming (Using JAVA) Interacting with.
Lesson 1 The Java World AUBG ICoSCIS Team Assoc. Prof. Stoyan Bonev March, , 2013 SWU, Blagoevgrad.
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.
OOP (Java): Simple/ OOP (Java) Objectives – –give some simple examples of Java applications and one applet 2. Simple Java Programs Semester.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
© 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.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Programs.
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
Introduction to Java Programming with Forte Y. Daniel Liang.
Clement Allen, PhD Florida A&M University SUMMER 2006.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to.
Lecture 1. Introduction to Programming and Java MIT- AITI 2003.
Java Programming, Second Edition Appendix A Working with Java SDK 1.4.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Application Architecture Using Java Hong Li. Introduction Developed by a team led by James Gosling at Sun Microsystem. Originally called Oak, designed.
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.
Lecture1 Instructor: Amal Hussain ALshardy. Introduce students to the basics of writing software programs including variables, types, arrays, control.
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 Development Environments AUBG, COS dept Lecture Title: Dev Env: NetBeans (Extract from Syllabus) Reference:
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Introduction to Computers,
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.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
CS-140 Dick Steflik Lecture 3. Java C++ Interpreted optimized for the internet Runs on virtual ized machine Derived from C++ Good object model Widely.
Before You Begin Nahla Abuel-ola /WIT.
GC101 Introduction to computer and program
Chapter 1 Introduction to Computers, Programs, and Java
Running Programs & IDEs Reference: COS240 Syllabus
Java programming lecture one
Chapter 1 Introduction to Computers, Programs, and Java
(Computer fundamental Lab)
Outcome of the Lecture Upon completion of this lecture you will be able to understand Fundamentals and Characteristics of Java Language Basic Terminology.
Presentation transcript:

10/10/2015Assoc. Prof. Stoyan Bonev1 COS240 O-O Languages AUBG, COS dept Lecture 10b Title: Running Programs & IDEs (Java) Reference: COS240 Syllabus

10/10/2015Assoc. Prof. Stoyan Bonev2 Lecture Contents: Java applications classified Processing Java source texts –How Java works –IDEs to run Java

10/10/2015Assoc. Prof. Stoyan Bonev3 Java programs may be applications or applets. Applications are standalone programs, similar to.NET Console and Windows applications. Applets are similar to applications, but they do not run as standalone programs. - Instead, applets adhere to a set of conventions that lets them run within a Java-compatible browser (client- side). - You can only run an applet from an HTML page. Java applications classified

10/10/2015Assoc. Prof. Stoyan Bonev4 Java, C#, C++ - High Level PL In order to run /to execute/, any program written in HLL should be transformed to executable form Three ways to convert source code into executable form: –Compiler – generate object code –Interpreter – interpret the source code –Compiler of semi-interpreting type

10/10/2015Assoc. Prof. Stoyan Bonev5 Source program compiler data Results Object program Executing computer Compile time Run time

10/10/2015Assoc. Prof. Stoyan Bonev6 Data Results Source program Interpreter Compile time Run time

10/10/2015Assoc. Prof. Stoyan Bonev7 Source program compiler data Results Object program in IL form Interpreter Compile2 time Run time Compile1 time

10/10/2015Assoc. Prof. Stoyan Bonev8 Processing HLL programs Java is compiled to intermediate form – bytecode. Bytecode processed by interpreter named JVM. C# and C++ (managed code) are compiled to intermediate form – MSIL code. MSIL code processed by interpreter named CLR. C++ (native, unmanaged code) is directly compiled to executable native machine code. No intermediate code, no need of interpreter.

10/10/2015Assoc. Prof. Stoyan Bonev9 How Java Works Java's platform independence is achieved by the use of the Java Virtual Machine (JVM). A Java program consists of one or more files with a.java extension these are just text (i.e. source) files. When a Java program is compiled, the.java files are fed to the compiler which produces a.class file for each.java file. The.class file contains Java bytecode. Java bytecode is like machine language, but it is intended for the Java Virtual Machine, not a specific processor.

10

11 Executing a Java program

12 JVM emulation run on a physical machine

13 JVM handles translations

14 Java Popularity Pure Java includes 3 software facilities: JRE JVM JDK

15 JRE The Java Runtime Environment (JRE) provides – the libraries, – the Java Virtual Machine, and – other components to run applets and applications written in Java.

16 JVM - Overview Java Virtual Machine is a program which executes certain other programs, namely those containing Java bytecode instructions. JVM is distributed along with Java Class Library, a set of standard class libraries (in Java bytecode) that implement the Java application programming interface (API). These libraries, bundled together with the JVM, form the Java Runtime Environment (JRE).Java Class Library standard class librariesapplication programming interfaceJava Runtime Environment (JRE) JVMs are available for many hardware and software platforms. The use of the same bytecode for all JVMs on all platforms allows Java to be described as a write once, run anywhere programming language, versus write once, compile anywhere, which describes cross-platform compiled languages. platformswrite once, run anywherewrite once, compile anywherecompiled languages Oracle Corporation, the owner of the Java trademark, produces the most widely used JVM, named HotSpot, that is written in the C++ programming language.Oracle CorporationtrademarkHotSpotC++

17 JVM JVM architecture. Source code is compiled to Java bytecode, which is verified, interpreted or JIT-compiled for the native architecture. The Java APIs and JVM together make up the Java Runtime Environment (JRE).

18 JDK contents The JDK has a collection of programming tools, including:

19 JDK contents java – the loader for Java applications. This tool is an interpreter and can interpret the class files generated by the javac compiler. Now a single launcher is used for both development and deployment. The old deployment launcher, jre, no longer comes with Sun JDK, and instead it has been replaced by this new java loader.loader javac javac – the Java compiler, which converts source code into Java bytecodejavacJava compiler Java bytecode javadoc – the documentation generator, which automatically generates documentation from source code commentsjavadocsource code jar – the archiver, which packages related class libraries into a single JAR file. This tool also helps manage JAR files.librariesJAR file

20 A Simple Java Program //This program prints message “ Welcome, Java! “ // braces in new-line style public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } Listing 1.1

21 A Simple Java Program //This program prints message “ Welcome, Java! “ // braces in end-line style (recommended) public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } Listing 1.1

22 Creating, Compiling, and Running Java Programs

23 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 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 bytecode. The bytecode can then run on any computer with a Java Virtual Machine, as shown below. Java Virtual Machine is a software that interprets Java bytecode.

Java Programming: From Problem Analysis to Program Design, 3e24 Approaches to run Java How to Compile/Run Java Programs – javac, java Java IDEs – TextPad, jGRASP, BlueJ, NetBeans, Eclipse Java Development Tools – javadoc, jar, jdb

Assoc. Prof. Stoyan Bonev 10/10/ Creating, Compiling & Running Java F From the Command Window F From within IDE

Creating, Compiling and Running Java from Command Line Window F First: to open a Command Window –Click Start, All Programs, Accessories, Command Prompt F Second: to create a separate directory/folder on C: drive or Q: drive where to save.java and.class files –md COS240Progs –cd COS240Progs F Third: to Set path to JDK bin directory –Already done by OCC F Fourth: to create and save Java source file –Notepad/Write Welcome.java F Fifth: to Compile –javac Welcome.java F Sixth: to Run –java Welcome

Assoc. Prof. Stoyan Bonev 10/10/ Creating and Editing Using editors like Notepad, WordPad, etc To use NotePad, type notepad Welcome.java from the DOS prompt. To use WordPad, type write Welcome.java from the DOS prompt.

Assoc. Prof. Stoyan Bonev 10/10/ Compiling, and Running Java Programs F In order to compile your Java program, you should type javac Welcome.java F In order to run your compiled to bytecode Java program, you should type java Welcome

Assoc. Prof. Stoyan Bonev 10/10/ Compiling, and Running Java Programs public class Welcome { public static void main(String args[]) { int i=1; while (i<5) { System.out.println("Greeting to Blagoevgrad!"); i++; } // end of while loop } // end of method main } // end of Welcome class

Assoc. Prof. Stoyan Bonev 10/10/ Compiling and Running Java from IDEs F Java IDEs: –TextPad – jGRASP – BlueJ – NetBeans – Open source by Sun – Eclipse – Open source by IBM

Assoc. Prof. Stoyan Bonev 10/10/ Compiling and Running Java from TextPad F.F.

Assoc. Prof. Stoyan Bonev 10/10/ Compiling and Running Java from TextPad F Edit the.java file F The edited file should be saved before the coming commands to take effect. F Subjects of interest: –Select tools, click run (user is expected to type command and parameters) –Command:javacParameter:Welcome.java –Command:javaParameter:Welcome –Select view, click tool output

Assoc. Prof. Stoyan Bonev 10/10/ Compiling and Running Java from TextPad public class COS240 { public static void main(String args[]) { int i=1; for (i=1; i<=5; i++) System.out.println("Greeting from COS dept"); }

Assoc. Prof. Stoyan Bonev 10/10/ Compiling and Running Java from jGRASP

Assoc. Prof. Stoyan Bonev 10/10/ Compiling and Running Java from jGRASP Subjects of interest: F Select Build, Click Compile F Select Build, Click Run Or F Select Build, Click Run as Applet Or F Select Build, Click Run as Application F CheckBox: run in MS-DOS window

Assoc. Prof. Stoyan Bonev 10/10/ Compiling and Running Java from jGRASP import java.util.Scanner; public class COS240Proba { public static void main(String args[]) { Scanner cin = new Scanner(System.in); int pom = cin.nextInt(); float pom2 = cin.nextFloat(); double pom3 = cin.nextDouble(); System.out.println(" " + pom + " " + pom2 + " " + pom3); }

Assoc. Prof. Stoyan Bonev 10/10/ Compiling and Running Java from NetBeans

Assoc. Prof. Stoyan Bonev 10/10/ Compiling and Running Java from NetBeans F Subjects of interest: F The concept of a project F The user is expected: F To choose project (Categories: Java, Projects: Java application) F To name the project and to locate the project F To create Main class and to set as Main project F To type the Java source text F To select Run, click Run Main Project (F6) F Or F To select Run, click Build Main Project(F11), click Run Main Project (F6) F Or F To select Run, click Clean and Build Main Project(Shift+F11), click Run Main Project (F6)

Assoc. Prof. Stoyan Bonev 10/10/ Compiling and Running Java from Eclipse

Assoc. Prof. Stoyan Bonev 10/10/ Compiling and Running Java from Eclipse F Subjects of interest: F The concept of a project F Compilation activated when File_save activity take place F List of steps to follow:

Assoc. Prof. Stoyan Bonev 10/10/ Compiling and Running Java from Eclipse F Open the Java perspective: –In main menu select Window > Open Perspective > Java F Create a Java project –In main toolbar Click New Java Project btn, Enter HelloWorld for name, click Finish F Create your Helloworld class –In main toolbar Click New Java class btn, select xx\src as a source folder, enter HelloWorld for class name, click check box to create the main() method, click Finish F Add a println statement –Type stmts, then save changes, the class will automatically compile upon saving F Run your java application –Right click on your class in the Package Explorer, and then select Run As>Java application

Assoc. Prof. Stoyan Bonev 10/10/ Eclipse F Downloads: – F Tutorials: – –

Assoc. Prof. Stoyan Bonev 10/10/ Java Development Tools F Brief overview on Java Development Tools : (Detailed discussion in lecture 29) – java – javac – javadoc – jar – jdb

Assoc. Prof. Stoyan Bonev 10/10/ Running java F Synopsis java [interpreter options] classname [program arguments] java [interpreter options] -jar jarfile [program arguments] F Description F Common Options

Assoc. Prof. Stoyan Bonev 10/10/ Running javac F Synopsis – javac [options] files F Description F Common Options

Assoc. Prof. Stoyan Bonev 10/10/ Running javadoc F Synopsis javadoc package… sourcefiles… F Description F Common Options

Assoc. Prof. Stoyan Bonev 10/10/ Running jar F Synopsis jar c|t|u|x [jarfile] [manifest] [-C directory] [input files] jar I [jarfile] F Description F Common Options

Assoc. Prof. Stoyan Bonev 10/10/ Running jdb F Synopsis jdb [options] class [program options] F Description F Common Options

10/10/2015Assoc. Prof. Stoyan Bonev49 Practical session Task: write a program to input two integral values and to compute and display the result of their addition, subtraction, multiplication and division Language: Java IDE: Eclipse

10/10/2015Assoc. Prof. Stoyan Bonev50 Practical session Task: write a program to input two integral values and to compute and display the result of their addition, subtraction, multiplication and division Language: Java IDE: NetBeans

10/10/2015Assoc. Prof. Stoyan Bonev51 Practical session Task: write a program to input two integral values and to compute and display the result of their addition, subtraction, multiplication and division Language: Java IDE: jGRASP

10/10/2015Assoc. Prof. Stoyan Bonev52 Practical session Problem: To accumulate sum of stream of input integers terminated by sentinel value Language: Java IDE: Eclipse

10/10/2015Assoc. Prof. Stoyan Bonev53 Practical session Problem: To accumulate sum of stream of input integers terminated by sentinel value Language: Java IDE: NetBeans

10/10/2015Assoc. Prof. Stoyan Bonev54 Practical session Problem: To accumulate sum of stream of input integers terminated by sentinel value Language: Java IDE: jGRASP

Thank You for Your attention!