Presentation is loading. Please wait.

Presentation is loading. Please wait.

How do we make our Welcome.java program do something? The java in our Welcome.java file won’t do anything by itself. We need to tell the computer to execute.

Similar presentations


Presentation on theme: "How do we make our Welcome.java program do something? The java in our Welcome.java file won’t do anything by itself. We need to tell the computer to execute."— Presentation transcript:

1 How do we make our Welcome.java program do something? The java in our Welcome.java file won’t do anything by itself. We need to tell the computer to execute the program in the file. This is a two-stage process. First stage: Compile the program into a concise set of instructions your computer can carry out directly >javac Welcome.java Second stage: Tell the computer to carry out the compiled instructions >java Welcome Welcome to Java javac stands for java compiler Tells the computer to execute the compiled java instructions in Welcome.class javac puts the compiled instructions in a new file Welcome.class

2 Translating from high to low..... Human speaks English Programmer encodes problem in a high-level Language (Java) Compiler Translates Java into compiled code Computer executes machine code instructions

3 public class Welcome { public static void main(String[] args){ System.out.println(“Welcome to java”); } Java source code in file Welcome.java 3%(*$&£.... (*&£*&£ *(&^^!__£+ ~@{W}{~@W}{~@ (£()*&(*H###~}{}{} (*(*(*(*£ Java bytecode in file Welcome.class 10010101001010010001111110001010 Program instructions carried out JAVAC compiles the source code JAVA virtual machine executes code

4 Writing your first program Open a new file in Notepad (or any other simple editor; not Word, tho!). You’ll find Notepad under Programs\Accessories. Type the Welcome.java code into this new file. Save the file in the Java folder in your home directory, with the name Welcome.java You have now written and saved your first draft of the program. Next you need to compile your program (convert it into a form that can do something), and once compiled, to run it (see what it does). Exit Notepad.

5 Compiling your program Open the command prompt on your computer. You’ll find this under Programs\Accessories. The command prompt is a window that allows you to type commands directly to the computer. Type cd H:\Java  at the command prompt (this command puts you in the Java folder of your Home ( H: ) directory) Type dir  to get a dir ectory of all files in H:\Java (you will see Welcome.java)

6 Compiling your program (continued) Type dir  to get a dir ectory of all files in H:\Java (you will now see Welcome.java and Welcome.class, if there were no compilation errors) Type javac Welcome.java  The javac command compiles your high-level Welcome.java file into low-level bytecode program in a file Welcome.class If there are any “grammatical” errors in your Welcome.java program (and there often are!) javac will print them out.

7 Running your compiled program Type java Welcome  to run the Welcome program The java command gets the file Welcome.class and executes the bytecode commands in that file. If your Welcome.java program compiled correctly (with no errors), you will now have a Welcome.class file that can be run. If you give commands like java Welcome.class or java Welcome.java they won’t work because the java command will look for Welcome.class.class or Welcome.java.class If your Welcome program is written correctly, when run it’ll display Welcome to java on the command prompt

8 Homework Read Liang, pp 14..20 (top of page) Do review questions, p. 26: 1.4 1.7 1.8 1.10 1.12 You will also be doing programming exercises in your practicals.

9 Computer labs start next week (27 th ) Where are the labs? Go up the stairs in the computer science building to the first floor. Turn right and go down to the end of the corridor; the first year labs are facing you. Go in and pick a computer. You must go at the time allocated for your group, as listed on the following slides.

10 Lab Times each Week You must go to the labs at the time for your option. Arts: Monday 4-6 Actuarial & Finance: Thursday 4-6 Denominated Computer Science : Monday 2-4 Denominated Computer Science : Tuesday 2-4 Denominated entry computer science have a choice: IMPORTANT: If you are a Denominated Computer Science student who is doing CHEMISTRY, you MUST sign up for the MONDAY 2-4 labs. This is because your chemistry labs will be on Tuesday.

11 General Science lab times General Science option G : Tues 4-6 or Wed 4-6 General Science option F, J, or M : Thursday 2-4 General Science option I or O : Wed 2-4 General Science option H or K : Mon 2-4 or Tues 2-4 (Students doing option H must go to the computer lab time that does not clash with their chemistry time) (Students doing option G must go to the computer lab time that does not clash with their chemistry time)

12 What you need in computer labs To use the computer labs, you need two things. 1) Your student account and password (this will have been given to you on registration). (Your student account will look like a random sequence of letters and numbers, maybe something like s04bf0fc@student.ucd.ie.) 2)Your student number (this will be on your Student Card). If you haven’t registered yet, simply bring along your CAO number. 3)You need both account+password and student number!


Download ppt "How do we make our Welcome.java program do something? The java in our Welcome.java file won’t do anything by itself. We need to tell the computer to execute."

Similar presentations


Ads by Google