+ All Categories
Home > Documents > This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public...

This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public...

Date post: 30-Mar-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
22
//This is a comment. public class MyProgram { public static void main (String[ ] args) { System out println(This is my first program ); This is the first program that you will write in IS 147. System.out.println( This is my first program. ); } } This is what the program prints when it is run at the linux prompt is run at the linux prompt. 1
Transcript
Page 1: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

//This is a comment.public class MyProgram{public static void main (String[ ] args){System out println(“This is my first program ”);

This is the first program that you will write in IS 147.

System.out.println( This is my first program. );}}

This is what the program prints when it is run at the linux promptis run at the linux prompt. 

1

Henry Emurian
Sticky Note
NOTE: What you see on your student account may not exactly match what you see here. You will be told what name to use for your course directory, and you will be taught how to create and use that directory in class. The white rectangle is the cursor blinking.
Page 2: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

//Some notes about the program.public class MyProgram

Use a comment to give information about your program such the date

{

hi k f hi li

program, such the date when you wrote it.

}

Think of this line as being used to give 

your program a name, such as MyProgram.y g

Your program is written insidewritten inside these braces.

2

Page 3: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

//Notes: Version 2.public class MyProgram{

public static void main (String[ ] args)public static void main (String[ ] args){System.out.println(“This is my first program.”);}

}

Program actions take place here. In this example, the action is to print This is my first program. at p y p gthe command line prompt when you run the program, like this: 

java MyProgram

3

Page 4: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

//This is a comment

Think of this line as the beginning of program statements that 

f ti th t t//This is a comment.public class MyProgram{

perform actions that you want your program to perform. At this point, you will just have to memorize this line without understanding it.

public static void main (String[ ] args){System.out.println(“This is my first program.”);

g

The word main is the name of a method, which is the beginning of a sequence of programmingSystem.out.println( This is my first program. );

}

}

a sequence of programming statements. A method is always followed by parentheses. Sometimes the parentheses are 

} empty, and other times they contain information. In this case, you can see (String[ ] args) within the parenthesesthe parentheses.

Memorize this line. You will see it and use it over and over again. You 

4

will learn what the components mean later.

Page 5: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

//This is a comment.public class MyProgram

Sometimes it may be required to write a computer program that receives a list of items when you start

{

public static void main (String[ ] args)

receives a list of items when you start the program. The term (String[] args)represents that list. For example, you 

public static void main (String[ ] args){

may want a computer program to print a list of cities. You might start the program this way:java MyProgram Baltimore Atlanta

System.out.println(“This is my first program.”);}

j y gYou can think of String[] as a column of words in a spreadsheet and argswould represent the actual words in the cells Baltimore and Atlanta are

}

the cells. Baltimore and Atlanta are put in the spreadsheet cells automatically when you start the program.

You must always use public static void main (String[] args) in a Java program even when you

5

in a Java program even when you don’t plan to receive a list of items.Memorize it.

Page 6: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

//This is a comment.public class MyProgram{public static void main (String[ ] args){System out println(“This is my first program ”);System.out.println( This is my first program. );}}

System out println(“This is my first program ”);System.out.println( This is my first program. );This is an action line of code in your program. The sentence within the quotation marks is printed when you run the program.  You will learn later that you run the program with the following command at the Unix prompt: java MyProgram

This is my first program. will be displayed at the prompt.

Whatever you include within the quotation marks will be displayed For example youWhatever you include within the quotation marks will be displayed. For example, you could write the program as follows:System.out.println(“Hello World”);Most Java courses begin by printing Hello World, but in this course, you will be spared f h i h i i i i

6

from having that initiation.

Page 7: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

This window appears after you logon with TeraTerm.

Type pwd, and then press the Enter key.

7

Page 8: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

What is printed shows your location in your account. The home directory is not accessible on the Internet.

Typing cd www is a shortcut way to move to your Internet directory The

8

move to your Internet directory. The term cdmeans change directory.

Page 9: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

The www directory is accessible on the Internet. If needed, your instructor may examine your dot java files. However, only you can write, revise, compile, and run your programs by accessing your account with TeraTermwith TeraTerm.

The mkdir command makes a subdirectory. This mkdir command 

9

ymakes a subdirectory named IS147. 

Page 10: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

The cd command changes the directory. Here, the command moves to the IS147 subdirectorymoves to the IS147 subdirectory that was created.

10

Page 11: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

The Java program will be written in this subdirectory.

11

Page 12: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

We will use the pico text editor to write Java programs to run on linux. This shows the command to create aThis shows the command to create a file named MyProgram.java.

Here is the pico editor ready for input to be y ptyped.

12

Page 13: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

The Java program has been typed. Note that This is my very first program in IS147.This is my very first program in IS147. has been written to be printed.

On the keyboard, CTRL‐X will exit pico. Enter Y (meaning Yes) to save the programthe program.

13

Page 14: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

At this point, press the Enter key.

The program has been saved, and you’re back to the commandyou re back to the command prompt.

14

Page 15: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

The ls command lists the files in your directory.

Listed is the file that you just created, MyProgram.java.

15

Page 16: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

The javac command compiles MyProgram.java into a bytecode file, MyProgram.class, that you can run at the command prompt.

It may take a few seconds toIt may take a few seconds to compile your program.

16

Page 17: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

If your program has no errors in it, no messages will appear.

17

Page 18: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

Now your directory has two files: MyProgram.class and MyProgram.java.

h bRun the program by typingjava MyProgram.

18

Page 19: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

Here is the output produced by the program

19

program.

Page 20: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

Use the below link at UMBC to download and install TeraTerm. It will work on Vista platforms To use TeraTerm to connect to UMBC enterwork on Vista platforms. To use TeraTerm to connect to UMBC, enter gl.umbc.edu

20

Henry
Typewritten Text
https://wiki.umbc.edu/display/faq/Software+Downloads
Henry
Typewritten Text
Henry
Typewritten Text
Henry
Typewritten Text
Page 21: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

21

Henry Emurian
Typewritten Text
Henry Emurian
Typewritten Text
Henry Emurian
Typewritten Text
Henry Emurian
Typewritten Text
Henry Emurian
Typewritten Text
Henry Emurian
Typewritten Text
Henry Emurian
Typewritten Text
Henry Emurian
Typewritten Text
Henry Emurian
Typewritten Text
Henry Emurian
Typewritten Text
The below link presents the "Hello World" program presented in the Java Tutorial at Oracle. You do not need Step 1. Java has already installed on the UMBC machines. docs.oracle.com/javase/tutorial/getStarted/cupojava/unix.html
Henry Emurian
Typewritten Text
Page 22: This is a comment.emurian/learnJava/swing/...//This is a comment. public class MyProgram {public static void main (String[ ] args) {System out println(“Thisis my firstprogram”);

There are many different ways to format a program. The below link shows the Hello World program presented at Oracle. docs.oracle.com/javase/tutorial/getstarted/application/examples/HelloWorldApp.java

22


Recommended