How to Run a Java Program

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

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.
CPSC150 Fall 2008 Dr. L. Lambert. CPSC150 Overview Syllabus Use Textbook, ask questions, extra thorough, I will post sections covered All information.
CS115 HOW TO INSTALL THE JAVA DEVELOPMENT KIT (JDK)
Introduction to Java Lab CS110A – Lab Section 004 Instructor: Duo Wei.
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.
J2ME Programming. 2 Recommended Books Programming Wireless Devices with the Java2 Platform, Micro Second Edition (Paperback) by Roger Riggs (Editor),
Editing Java programs with the BlueJ IDE. Working environments to develop (= write) programs There are 2 ways to develop (write) computer programs: 1.Using.
Digital Logic and State Machine Design Installing Xilinx WebPACK 12.4 CS 2204 Digital Hardware.
Chapter 1a© copyright Janson Industries RAD ▮ Explain Eclipse, RAD, and their relationship ▮ Basic RAD concepts ▮ How to install RAD ▮ How to import.
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Hello World in the Forte IDE An introduction to the Forte IDE (integrated development environment) writing the classic “Hello World” program in Java.
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.
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
11/25/2015Slide 1 Scripts are short programs that repeat sequences of SPSS commands. SPSS includes a computer language called Sax Basic for the creation.
 Instructor: Dr. Jason Nichols –  Office Hours: – 9:30-10:30 M/W/F or by appointment – Business Building.
Using This PowerPoint This PowerPoint presentation assumes your Computer Science teacher has provided you with the InstallingJava folder, which contains.
C++ LANGUAGE TUTORIAL LESSON 1 –WRITING YOUR FIRST PROGRAM.
PART 2 INTRODUCTION TO DYNAMIC WEB CONTENT AND PHP.
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.
Time to apply stuff… Faculty of Mathematics and Physics Charles University in Prague 5 th October 2015 Workshop 1 – Java Wrestling.
Computer Science I Lab 1 ISMAIL ABUMUHFOUZ | CS 180.
1 Development Environments AUBG, COS dept Lecture Title: Dev Env: NetBeans (Extract from Syllabus) Reference:
Instructions for using this template. Remember this is Jeopardy, so where I have written “Answer” this is the prompt the students will see, and where.
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
Author: Loh Jianxiong Christopher Contributions: Chua Jie Sheng, Li Mengran, Peh Shao Hong, Oo Theong Siang, Tong Chun Kit, Tania Chattopadhyay.
Publisher CREATING A NEWSLETTER. Finished Product.
Java Methods and Applications CSIS 3701: Advanced Object Oriented Programming.
DEVRY CIS 170 C I L AB 1 OF 7 G ETTING S TARTED Check this A+ tutorial guideline at
CS210 Intermediate Computing with Data Structures (Java)
Getting Started with.
Introduction to Java Import Scanner class to use in our program
The eclipse IDE IDE = “Integrated Development Environment”
Development Environment
Obtaining the Required Tools
Create Rubrics for your Project-Based Learning Activities.
Eclipse Navigation & Usage.
CompSci 230 Software Construction
Macrosystems EDDIE: Getting Started + Troubleshooting Tips
Some Tips for Using Eclipse
Writing Methods.
String Output ICS 111: Introduction to Computer Science I
Using the Multiple Choice Template
Introduction to Algorithm Design
How to Run a Java Program
Getting Started with:.
CS115 HOW TO INSTALL THE JAVA DEVELOPMENT KIT (JDK)
Download and Installation of code::blocks
Macrosystems EDDIE: Getting Started + Troubleshooting Tips
This is a setup file for a Jeopardy game.
Introduction to AppInventor
Java Tutorial – Application Building
This is a setup file for a Jeopardy game.
Developing Java Applications with NetBeans
Developing Java Applications with NetBeans
Running a Java Program using Blue Jay.
Macrosystems EDDIE: Getting Started + Troubleshooting Tips
This is a setup file for a Jeopardy game.
CSCE 206 Lab Structured Programming in C
Review of Previous Lesson
Java Code Review with CheckStyle
Macrosystems EDDIE: Getting Started + Troubleshooting Tips
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 Last modified: 8/23/2018

Outline Java SDK installation Netbeans installation Create a Java program in Netbeans Run the program Error messages Creating a program with existing code (create new and copy/paste) Comments

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.

Installing Java SDK Install: Java SDK is Version 8 from Java SE Development Kit 8u181. NOTE: do not instal Java SDK 9 as it does not support Netbeans. To install the current version of Java SDK: Go to: http://www.oracle.com/technetwork/java/javase/downloads/index.html In the section for Java SE 8u181, click on "JDK Download“ button.

Installing Java SDK In the table for “Java SE Development Kit 8u181”: check the button to “Accept License Agreement” and download the package based on your operating system. Follow the installation instruction to complete the process. If you have trouble installing, see the instructor or TA for help.

Installing Netbeans IDE 8.2 Go to https://netbeans.org/downloads/index.html Download the "Java SE" version (or a superset of it) “Java SE” covers what we need. Recommended. Supersets of it (cover that and more): “Java EE”, “All” Follow the instructions on screen to complete the installation. You will be asked about JUnit: choose to install it.

File Location Starting Netbeans, Make one folder for homework. Make sure you create your projects in this folder.

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

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

Creating a Netbeans Project (3) Give a name to your project, e.g., Hello. Give to your Main Class the same name as for your project, and (after reading the next slide) click "Finish". It should be the same name in the circled boxes. Replace hello.Hello with Hello (NOTE: that this requirement is for this class only. Normally when using Java, you keep the default. E.g.: hello.Hello

Choosing a Name for the Main Class Click "Finish".

Projects in Netbeans See the project folder created. See the source file. Open it with a different editor. Notice that the source file exists BEFORE we ‘run’ the code. This type of file will be submitted for homework. Deleting a project (with or without deleting the code) Closing a project.

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. */ /** * * @author yourname public class hello1 { * @param args the command line arguments public static void main(String[] args) { // TODO code application logic here }

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. */ /** * * @author yourname public class hello1 { * @param args the command line arguments public static void main(String[] args) { // TODO code application logic here }

Writing Code (3) For the first programs, 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. */ /** * * @author yourname public class hello1 { * @param args the command line arguments public static void main(String[] args) { // TODO code application logic here }

Writing Code - Comments 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. Comments that extend over 1 line: // 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. */ /** * * @author yourname public class hello1 { * @param args the command line arguments public static void main(String[] args) { // TODO code application logic here }

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

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

A First Example - Running the code 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 code. public class hello1 { public static void main(String[] args) { System.out.println("Hello world"); }

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

The Output Window is NOT the Source Code/Source File. It should not be submitted with the homework. It simply shows ‘the result’ of one execution of your program. It ‘resets’ when you run the program again. See Figure 8 ‘From Source code to Running Program’, page 9 in the textbook.

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: 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" (or: right click on the project name and select "Clean and Build“). 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.

Netbean Real-Time Error Detection Note the ! mark on line 3 of the code. This is Netbean's way of telling you that line 3 is not correct: it has a syntax error.

Netbean Real-Time Error Detection 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. You should look for these ! signs, and fix the errors, before you try to run your code.

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.

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

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

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.

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

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.