1
Gentle Introduction to Programming
Tirgul 1: Shell and Scala “hands on” in
the lab
2
Today• Login to your account• Your Account, basic Linux commands• Using the interpreter• Eclipse – “Hello World!”• Understanding compiler messages• Eclipse:
• Command line arguments• Debugger
• Home work – practice Shell commands
3
Today• Login to your account• Your Account, basic Linux commands• Using the interpreter• Eclipse – “Hello World!”• Understanding compiler messages• Eclipse:
• Command line arguments• Debugger
• Home work – practice Shell commands
4
Your Account, Basic Linux Commands
• User’s account: to log in select session: GNOME• Web browser • Open the “system handouts” file from the course’s site (in the session’s section)• Shell / Console
5
Basic Linux Commands
6
Security (chmod)
7
Today• Login to your account• Your Account, basic Linux commands• Using the interpreter• Eclipse – “Hello World!”• Understanding compiler messages• Eclipse:
• Command line arguments• Debugger
• Home work – practice Shell commands
8
Using the Interpreter• Type “scala” from the console• Start trying some basic commands:
• println(“hello world!”)• val x = 5• var y = 1.4
• Define a function that receives two integers and return their sum. Use it on several inputs.
9
Today• Login to your account• Your Account, basic Linux commands• Using the interpreter• Eclipse – “Hello World!”• Understanding compiler messages• Eclipse:
• Command line arguments• Debugger
• Home work – practice Shell commands
10
Eclipse• Type “eclipse35 &” from the console• Use a workspace located on your account• How to solve common technical problems:
• “Clean” your eclipse by removing the .eclipse directory (rm –R .eclipse, from your root)• Start a new workspace / remove the old one
11
Open Eclipse – Set Workspace
12
Open Eclipse
13
Define New Project
14
If you don’t find the Scala new project…
File New Project
15
New Object
16
Write Some Code
17
Run
output
18
Today• Login to your account• Your Account, basic Linux commands• Using the interpreter• Eclipse – “Hello World!”• Understanding compiler messages• Eclipse:
• Command line arguments• Debugger
• Home work – practice Shell commands
19
Understanding Compiler MessagesOpen the interpreter, try the following lines of code, and try to understand what the compiler means, and how to solve it
val x = 5
x = 6
Println(“123”)
val f = (x : Int => x + 1)
if x > f(x) x = 9
val f = (x : int) => x + 1
20
And In Eclipse
• Select and copy a program of your choice to Eclipse• How are compilation errors marked in Eclipse?• Perform compilation errors purposely and see how the compiler’s errors look like:
• Change an upper-case letter to lower case• Remove a closing brackets
• Where are the compiled files?
21
Today• Login to your account• Your Account, basic Linux commands• Using the interpreter• Eclipse – “Hello World!”• Understanding compiler messages• Eclipse:
• Command line arguments• Debugger
• Home work – practice Shell commands
22
Command Line Arguments In Eclipse
23
Command Line Arguments In Eclipse
24
Usage Example
?
Fibonacci.scala
25
Example: Prime
• Write a program that receives from the command line arguments a list of numbers, and prints out for each whether it is prime
• Use the prime code that is published, and wrap it as a function• Notice, that the number of arguments is not known in advance!
26
The Debugger
• Some programs may compile correctly, yet not produce the desirable results
• These programs are valid and correct Scala programs, yet not the programs we meant to write!
• The debugger can be used to follow the program step by step and may help detecting bugs in an already compiled program
27
Debugger – Add Breakpoint
• Right click on the desired line
• “Toggle Breakpoint”
28
Debugger – Start Debugging
breakpoint
debug
29
Debugger – Debug Perspective
30
Debugger – Debugging
Current state
Current location
Back to Scala perspective
31
Today• Login to your account• Your Account, basic Linux commands• Using the interpreter• Eclipse – “Hello World!”• Understanding compiler messages• Eclipse:
• Command line arguments• Debugger
• Home work – practice Shell commands
32
Home Work - Shell