COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a...
Transcript of COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a...
![Page 1: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/1.jpg)
COMP 248 – Winter 2016
Tutorial 1
![Page 2: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/2.jpg)
Getting started in the lab
Get your computer account from ENCS help
desk (H-960)
Note that computer science students will keep their
account throughout their studies; but non-computer
science students will have their account closed at the
end of the semester.
Login using your user account and password,
and change your password from the ENCS
helpdesk website:
https://fis.encs.concordia.ca/helpdesk-cgi/ch-
own-pwd.cgi
2
![Page 3: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/3.jpg)
Java Installation
Download Java (Java SE 8u25)
• For Windows and Linux, visit the website:
http://www.oracle.com/technetwork/java/javase/downl
oads/index.html (This is not needed for Mac OS X,
since it is already built in).
• Select Download JDK and JRE for windows
platform. (On Windows, you will need admin
privileges.). Once the download is complete, install
java by clicking on the file you downloaded. This will
lead you through the installation process.
• Check the following website if you do not know
whether the OS of your machine is 64 or 32 bits
http://www.stata.com/support/faqs/windows/64-bit-
compliance/ 3
![Page 4: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/4.jpg)
Download and install Java
4
![Page 5: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/5.jpg)
Download and install Java
5
![Page 6: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/6.jpg)
Path Configuration
Right click on
MyComputer
Properties
Advanced
Environment
Variables
Select PATH
Edit
6
![Page 7: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/7.jpg)
Path Configuration
Add the path
“;C:\Program
Files\Java\jdk1.7.0\bi
n” at the place of
highlighted line
Press Ok
Redo the same for
Path in System
variables
7
![Page 8: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/8.jpg)
Check if JDK is Installed
Properly!
8
![Page 9: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/9.jpg)
There are two ways to compile and run a
Java program:
• Using command line
• Through a Development Editor like Eclipse
9
Compile and Run a Java Program
![Page 10: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/10.jpg)
Example of Java program
Hello World Application
Note, the java file must be named as HelloWorld.java
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println(“Hello World!”);
}
}
10
![Page 11: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/11.jpg)
Running Java Program
Using Command Line Write a Java program using any editor (i.e. expL,
Notepad) and save it as (FileName.java) file with the same name as the class.
Go to the directory where you created your program using the command line
Compile the java file using the following command line: > javac FileName.java
The above command line will compile the program and create FileName.class file, if there are no errors in the program
Run the file using the following command line: > java filename
11
![Page 12: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/12.jpg)
Running Java Program
Using Command Line
12
![Page 13: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/13.jpg)
Download Eclipse
To download Eclipse visit the web page
http://www.eclipse.org/downloads/index.php
You may select any mirror site, e.g. "Main
Eclipse Download Site". There are several
versions of Eclipse, and it is important you
install the correct one. Check that the site has
the latest
13
![Page 14: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/14.jpg)
Download Eclipse
14
Click on the Link
![Page 15: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/15.jpg)
Download Eclipse
15
Select your platform
![Page 16: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/16.jpg)
Download Eclipse
16
![Page 17: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/17.jpg)
Download Eclipse
17
![Page 18: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/18.jpg)
Download Eclipse
18
![Page 19: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/19.jpg)
Eclipse Installation
Unlike most modern software products, Eclipse has not have a fancy installation procedure.
To install it, simply extract the zip file in the directory where your programs are stored, e.g. C:\Program Files. This will create a directory named eclipse.
The executable program file is located in this directory and is called "eclipse.exe".
On Windows systems, it is a good idea to create a shortcut to this executable on your desktop. To do this, right-click on the "eclipse.exe" file and select "Send To → Desktop".
19
![Page 20: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/20.jpg)
Eclipse Installation
20
Extract the “eclipse” folder to your preferred destination
![Page 21: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/21.jpg)
Eclipse Installation
21
Open the folder and run “eclipse.exe”
![Page 22: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/22.jpg)
Eclipse Initialization
Eclipse stores all its files in a directory called it "workspace".
When Eclipse is running for the first time, it will ask you where you want the workspace to be placed. You can just use the default location (which will be in the directory where eclipse was installed).
Some people find it more convenient to place the workspace somewhere in their "My Documents" directory, e.g. "My Documents\Eclipse".
After this, you should see the "Welcome to Eclipse" page. When you see this, you are ready to proceed to the next step.
22
![Page 23: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/23.jpg)
Eclipse Initialization
23
![Page 24: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/24.jpg)
Using Eclipse the first time
24
![Page 25: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/25.jpg)
Create a Java Project
25
This is always how to create a new Java Project
![Page 26: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/26.jpg)
Create a Java Project
26
![Page 27: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/27.jpg)
Create a Java Project
27
The project’s name is what you called it
![Page 28: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/28.jpg)
Create a new Java class
28
“src” stands for source code
This is the way to create new Java Classes
![Page 29: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/29.jpg)
Create a new Java class
29
![Page 30: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/30.jpg)
Run a Java program
30
![Page 31: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/31.jpg)
Submission of Assignments and
Lab Exercices Go to the EAS system website @ https://fis.encs.concordia.ca/eas/
Login with your ENCS username and password
Click on the "Student" category
You would expect to see a list of courses you are currently taking
Scroll down and you will see "Expectations of originality“, select "I
agree" and continue
For "Current term course sections“, choose COMP248 for this
course
Browse your compressed file (containing your Java files)
To submit an assignment: select the "submission type" as
"programming_assignment"
To submit a lab exercises, select the "submission type" as “quiz“
31
![Page 32: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/32.jpg)
How to compress files
32
Location of your new Java Classes
![Page 33: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/33.jpg)
How to compress files
33
![Page 34: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/34.jpg)
How to compress files
34
Remember you only need to submit the java files
![Page 35: COMP 248 Winter 2016 Tutorial 1 - Aiman Hanna · Running Java Program Using Command Line Write a Java program using any editor (i.e. expL, Notepad) and save it as (FileName.java)](https://reader033.fdocuments.in/reader033/viewer/2022051808/6008cfb0ea7e7940d9488bc3/html5/thumbnails/35.jpg)
Assignment submission
Caution --- For "submission number,"
please be sure to select accordingly
• assignment #1, please select "1"
• assignment #2, please select "2"
• assignment #3, please select "3"
• etc.
35