How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. OBJECTIVES FOR THIS UNIT Upon completion of this unit, you should be able to: Explain the Java virtual machine.
Using XCode © 2013 Surajit A Bose De Anza College.
CPSC150 Fall 2008 Dr. L. Lambert. CPSC150 Overview Syllabus Use Textbook, ask questions, extra thorough, I will post sections covered All information.
How to Create a Java program CS115 Fall George Koutsogiannakis.
CS115 HOW TO INSTALL THE JAVA DEVELOPMENT KIT (JDK)
Introduction to Java Lab CS110A – Lab Section 004 Instructor: Duo Wei.
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
CENG 161 Introduction to Computer Science Instructor: Dr. Nurdan SARAN Lab Assistant: Arzu Burçak Sönmez.
Tutorial 1 Introduction to Java Programming Bo Chen Department of Computer Science.
CS 2511 Fall  Windows:  Start->Specialized Academic Software- >Programming Languages->NetBeans->NetBeans IDE x.y.z  where x.y.z is a version.
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.
Software Development. Chapter 3 – Your first Windows 8 app.
Editing Java programs with the BlueJ IDE. Working environments to develop (= write) programs There are 2 ways to develop (write) computer programs: 1.Using.
Getting Started With Java Downloading and installing software Running your first program Dr. DwyerFall 2012.
From BlueJ to NetBeans SWC 2.semester.
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
CSCI 273: Processing An Introduction. Programming Languages –An abstract "human understandable" language for telling the computer what to do –The abstract.
(C) 2010 Pearson Education, Inc. All rights reserved.  Java programs normally go through five phases  edit  compile  load  verify  execute.
Chapter 1a© copyright Janson Industries RAD ▮ Explain Eclipse, RAD, and their relationship ▮ Basic RAD concepts ▮ How to install RAD ▮ How to import.
Introduction to Computers and Java Chapter 1.3. A Sip of Java: Outline History of the Java Language Applets A First Java Program Compiling a Java Program.
Board Activity Find your seat on the seating chart Login – Remember your login is your first initial your last name and the last three numbers of your.
Programming Concept Chapter I Introduction to Java Programming.
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
CSCI Processing CSCI Introduction to Algorithm Design An Introduction.
Agenda For Feb PowerPoint Presentation (Introduction to Java Methods) 2.Finish Unit 2 exercises on page 13 (due by the end of the class today). 4.
Unit 1: Java and Eclipse The Eclipse Development Environment.
Comments in Java. When you create a New Project in NetBeans, you'll notice that some text is greyed out, with lots of slashes and asterisks:
Output in Java Hello World!. Structure of a Java Program  All Java files in ICS3U1 have the following structure: class HelloWorld { }  Notice the open.
BUILDING JAVA PROGRAMS CHAPTER 1 ERRORS. 22 OBJECTIVES Recognize different errors that Java uses and how to fix them.
First Programs CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
EIE375 BlueJ: Getting Started Dr Lawrence Cheung.
Downloading and Installing Autodesk Inventor Professional 2015 This is a 4 step process 1.Register with the Autodesk Student Community 2.Downloading the.
Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar
Java Methods Methods contain a group of instructions that together perform a single task. For example if I want to perform the task of “making a pizza”,
 Instructor: Dr. Jason Nichols –  Office Hours: – 9:30-10:30 M/W/F or by appointment – Business Building.
Introduction to Python Lesson 1 First Program. Learning Outcomes In this lesson the student will: 1.Learn some important facts about PC’s 2.Learn how.
Using This PowerPoint This PowerPoint presentation assumes your Computer Science teacher has provided you with the InstallingJava folder, which contains.
CS7 Recitation Cem Akkaya. Outline  Homework-0 in detail  Useful links and tools  Setting up your java environment.
C++ LANGUAGE TUTORIAL LESSON 1 –WRITING YOUR FIRST PROGRAM.
1 Installing Java on Your PC. Installing Java To develop Java programs on your PC: Install JDK (Java Development Kit) Add the directory where JDK was.
Introduction to Eclipse Programming with an Integrated Development Environment.
1/10/2008. >>> About Us Paul Beck * Third quarter TA * Computer Engineering * Ryan Tucker * Second quarter TA * Computer.
Time to apply stuff… Faculty of Mathematics and Physics Charles University in Prague 5 th October 2015 Workshop 1 – Java Wrestling.
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.
Computer Science I Lab 1 ISMAIL ABUMUHFOUZ | CS 180.
1 Development Environments AUBG, COS dept Lecture Title: Dev Env: NetBeans (Extract from Syllabus) Reference:
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
Linux CSE 1222 CSE1222: Lecture 1BThe Ohio State University1.
Author: Loh Jianxiong Christopher Contributions: Chua Jie Sheng, Li Mengran, Peh Shao Hong, Oo Theong Siang, Tong Chun Kit, Tania Chattopadhyay.
Java Methods and Applications CSIS 3701: Advanced Object Oriented Programming.
Computer Programming Your First Java Program: HelloWorld.java.
CS210 Intermediate Computing with Data Structures (Java)
Introduction to Java Import Scanner class to use in our program
The eclipse IDE IDE = “Integrated Development Environment”
Development Environment
How to Run a Java Program
Introduction to Algorithm Design
Java Intro.
How to Run a Java Program
Developing Java Applications with NetBeans
Developing Java Applications with NetBeans
Running a Java Program using Blue Jay.
Review of Previous Lesson
How to Run a Java Program
Presentation transcript:

How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1

Initial Steps You must install Java SDK. You must install Netbeans. These are steps that you do just once. Once Java and Netbeans are installed, you can run any Java program you like on your computer. 2

Installing Java SDK, Version 8, Update 60 As of August 26, 2015, the current version of Java SDK is Version 8, Update 60 (Java SE Development Kit 8u60). To install the current version of Java SDK: – Go to: – Click on "JDK Download" – Follow the instructions on screen to complete the installation process. If you have trouble installing, the instructor and TAs for help. 3

Installing Netbeans IDE As of August 26, 2015, the current version of Netbeans is To install the current version of Netbeans: – Go to – Download the "Java SE" version – Follow the instructions on screen to complete the installation process. You will be asked about JUnit: choose to install it. If you have trouble installing, the instructor and TA for help. 4

Creating a Netbeans Project (1) Start Netbeans. Go to File->New Project 5

Creating a Netbeans Project (2) Under Categories, select "Java". Under Projects, select "Java Application". Click "Next". 6

Creating a Netbeans Project (3) Give a name to your project, e.g., hello1. Give to your main class the same name as for your project, and click "Finish". Names matter, see next slides. 7

Netbeans suggests a default name for the main class. For example, if the project name is hello1, Netbeans suggest name hello1.Hello1 for the main class. 8 Choosing a Name for the Main Class

Netbeans suggests a default name for the main class. For example, if the project name is hello1, Netbeans suggest name hello1.Hello1 for the main class. You must override that, with hello1 in this example. 9 Choosing a Name for the Main Class

Netbeans suggests a default name for the main class. For example, if the project name is hello1, Netbeans suggest name hello1.Hello1 for the main class. You must override that, with hello1 in this example. The main class name should be the same as the project name. 10 Choosing a Name for the Main Class

Writing Code (1) If you create a new project as described, Netbeans will create a Java file, that looks like this: /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * athitsos */ public class hello1 { /** args the command line arguments */ public static void main(String[] args) { // TODO code application logic here } } 11

Writing Code (2) The place where you put your code is indicated with the text // TODO code application logic here /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * athitsos */ public class hello1 { /** args the command line arguments */ public static void main(String[] args) { // TODO code application logic here } } 12

Writing Code (3) For the first assignments, all you have to do is replace that "TODO" line with your own lines of code. /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * athitsos */ public class hello1 { /** args the command line arguments */ public static void main(String[] args) { // TODO code application logic here } } 13

Writing Code (4) Text that starts with /* and ends with */ is NOT PART OF THE PROGRAM. This text is called "comments", and is meant to be read by humans, not the computer. We will usually not care about (and not show) the comments that Netbeans generates. You can delete them if you want. 14 /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * athitsos */ public class hello1 { /** args the command line arguments */ public static void main(String[] args) { // TODO code application logic here } }

Writing Code (5) Without the comments, the initial code that Netbeans generates looks more simple: 15 public class hello1 { public static void main(String[] args) { // TODO code application logic here } }

A First Example Remember: for a good part of the class, your code will go where the TODO placeholder is. 16 public class hello1 { public static void main(String[] args) { // TODO code application logic here } }

A First Example Here we have replaced the TODO placeholder with a line of code. To run this code, go to Run->Run Project (or press F6) to compile the cod. 17 public class hello1 { public static void main(String[] args) { System.out.println("Hello world"); } }

18 When you run your code, an "Output Window" appears at the bottom, that looks as shown.

Failure to Run A lot of times you will get errors, and you will not be able to run the program. Do not panic, this is a very common thing to happen. For example, on this code we introduce an error on purpose, to see what happens (we delete the semicolon after "Hello world"). Now, when we try to run this code, we get what is shown on the next slide: 19 public class hello1 { public static void main(String[] args) { System.out.println("Hello world") } }

Error Message You will be seeing this window a lot. When you see it, click "Cancel". Then, click on "Run->Clean and Build Project". Now, the output window will show you an error message, which you should try to fix. You will learn how to fix these errors during the course. After you fix the error, you can try running the code again. If you get more errors, keep fixing them till the code runs. 20

Netbean Real-Time Error Detection Note the ! sign on line 3 of the code. This is Netbean's way of telling you that that line is not correct. 21

22 If you put the mouse arrow over the ! sign on line 3, you see an error message. In this particular case, it says: ';' expected. This means that you forgot to put the semicolon at the end. Netbean Real-Time Error Detection

23 You should look for these ! signs, and fix the errors, before you try to run your code. Netbean Real-Time Error Detection

Running Existing Code Oftentimes you may want to run code from somewhere (the slides, the textbook, the course website, etc.). To do that, you need to make sure that your project and main class are named appropriately. Step 1: Look at the code that you want to run, and find the name that shows up right after "public class". Step 2: When you create your project on NetBeans, use that name for your project and your main class. Step 3: Copy the code that you want to run to the.java file that NetBeans created. 24

Running Existing Code – Step 1 Step 1: Look at the code that you want to run, and find the name that shows up right after "public class". For example, in this piece of code, what is the name that shows up right after "public class"? public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world"); } 25

Running Existing Code – Step 1 Step 1: Look at the code that you want to run, and find the name that shows up right after "public class". For example, in this piece of code, the name that shows up right after "public class" is HelloWorld. public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world"); } 26

Running Existing Code – Step 2 Step 2: When you create your project on NetBeans, use that name (e.g., HelloWorld) for your project and your main class. 27

Running Existing Code – Step 3 Step 3: Copy the code that you want to run to the.java file that NetBeans created. 28

Running Existing Code Now you can run the code by pressing F6 (or by selecting Run->Run Project from the top menu), and see the output. 29