Download 01/09 - Brian Nakayama

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Computer Science 227
Introduction to Object-oriented Programming
Brian Nakayama1
1
Department of Computer Science, Iowa State University, Ames, IA 50010, USA
Jan 9th , 2017
What is Java?
Your Participation Grade
ˆ In class participation counts for 5% of your grade.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
2 / 11
What is Java?
Your Participation Grade
ˆ In class participation counts for 5% of your grade.
ˆ In our class, I will ask random students to answer
questions or participate in activities.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
2 / 11
What is Java?
Your Participation Grade
ˆ In class participation counts for 5% of your grade.
ˆ In our class, I will ask random students to answer
questions or participate in activities.
ˆ If you’re here and put in good effort, then you get points.
ˆ If you’re not here, then you lose points.
ˆ If you’re not here for four or more, I will no longer ask
you questions.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
2 / 11
What is Java?
Your Participation Grade
ˆ In class participation counts for 5% of your grade.
ˆ In our class, I will ask random students to answer
questions or participate in activities.
ˆ If you’re here and put in good effort, then you get points.
ˆ If you’re not here, then you lose points.
ˆ If you’re not here for four or more, I will no longer ask
you questions.
ˆ Skipping class: It’s a gamble ;), but missing one class
won’t affect you much. Missing most will likely be the
difference between an “A” or a “B”, a “B” or a “C”, etc.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
2 / 11
What is Java?
Your Participation Grade
ˆ In class participation counts for 5% of your grade.
ˆ In our class, I will ask random students to answer
questions or participate in activities.
ˆ If you’re here and put in good effort, then you get points.
ˆ If you’re not here, then you lose points.
ˆ If you’re not here for four or more, I will no longer ask
you questions.
ˆ Skipping class: It’s a gamble ;), but missing one class
won’t affect you much. Missing most will likely be the
difference between an “A” or a “B”, a “B” or a “C”, etc.
Note: You may also lose points if you do something distracting in
class, e.g. playing games, using your phone a lot, or shopping on
Amazon.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
2 / 11
What is Java?
Brief Overview
ˆ Java is a programming language.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
3 / 11
What is Java?
Brief Overview
ˆ Java is a programming language.
ˆ It is one of the most popular programming languages
today.
*note: not necessarily the most popular.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
3 / 11
What is Java?
Brief Overview
ˆ Java is a programming language.
ˆ It is one of the most popular programming languages
today.
*note: not necessarily the most popular.
ˆ Developers use Java to make programs that run on
operating systems such as Windows, iOS, Linux, and
Android.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
3 / 11
What is Java?
Brief Overview
ˆ Java is a programming language.
ˆ It is one of the most popular programming languages
today.
*note: not necessarily the most popular.
ˆ Developers use Java to make programs that run on
operating systems such as Windows, iOS, Linux, and
Android.
ˆ It has a “write once run anywhere” philosophy, and uses a
virtual machine.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
3 / 11
What is Java?
Why Java?
ˆ There are several careers for Java programmers due to
the language’s popularity.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
4 / 11
What is Java?
Why Java?
ˆ There are several careers for Java programmers due to
the language’s popularity.
ˆ It is a (semi) necessary language for Android development.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
4 / 11
What is Java?
Why Java?
ˆ There are several careers for Java programmers due to
the language’s popularity.
ˆ It is a (semi) necessary language for Android development.
ˆ It is object oriented.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
4 / 11
What is Java?
Why Java?
ˆ There are several careers for Java programmers due to
the language’s popularity.
ˆ It is a (semi) necessary language for Android development.
ˆ It is object oriented.
ˆ It has extensive libraries and good community support.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
4 / 11
What is Java?
Why Java?
ˆ There are several careers for Java programmers due to
the language’s popularity.
ˆ It is a (semi) necessary language for Android development.
ˆ It is object oriented.
ˆ It has extensive libraries and good community support.
However, is Java (or any other language) the best? Certain
languages perform better at certain tasks. More importantly, it
is easy to learn other programming languages once you know
one.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
4 / 11
What is Java?
Deep Questions
ˆ What is a program?
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
5 / 11
What is Java?
Deep Questions
ˆ What is a program?
A program is a set of instructions that when read by a
computer performs a certain task. By a set of
instructions, we mean the binary sequences that a CPU
can read.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
5 / 11
What is Java?
Deep Questions
ˆ What is a program?
A program is a set of instructions that when read by a
computer performs a certain task. By a set of
instructions, we mean the binary sequences that a CPU
can read.
ˆ How are programs made?
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
5 / 11
What is Java?
Deep Questions
ˆ What is a program?
A program is a set of instructions that when read by a
computer performs a certain task. By a set of
instructions, we mean the binary sequences that a CPU
can read.
ˆ How are programs made?
They are compiled: Idea ⇒ source code ⇒ (Java
bytecode ⇒) program.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
5 / 11
What is Java?
The Code
ˆ In your first lab, you will type in something similar to the
following as it is shown:
public class Hello{
public static void main(String[] args){
System.out.println("Hello World!");
}
}
ˆ You will then compile and run the code using an IDE, an
Interactive Development Environment.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
6 / 11
What is Java?
The Code
ˆ In your first lab, you will type in something similar to the
following as it is shown:
public class Hello{
public static void main(String[] args){
System.out.println("Hello World!");
}
}
ˆ You will then compile and run the code using an IDE, an
Interactive Development Environment.
ˆ It is also possible to compile this using the Command
Prompt.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
6 / 11
What is Java?
How does the code work?
public class Hello{
public static void main(String[] args){
System.out.println("Hello World!");
}
}
Modifier: public means that this class can be seen by all other
classes.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
7 / 11
What is Java?
How does the code work?
public class Hello{
public static void main(String[] args){
System.out.println("Hello World!");
}
}
Class: all java programs are written within classes. This
keyword tells java that what follows is the name of a class
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
7 / 11
What is Java?
How does the code work?
public class Hello{
public static void main(String[] args){
System.out.println("Hello World!");
}
}
Hello: the name of the class. Since this class is public, the
class name, and the file name must be the same. (Hello.java)
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
7 / 11
What is Java?
How does the code work?
public class Hello{
public static void main(String[] args){
System.out.println("Hello World!");
}
}
public static void main(String[] args): This is a method with
an argument. When ever the program is run, this method is
called.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
7 / 11
What is Java?
How does the code work?
public class Hello{
public static void main(String[] args){
System.out.println("Hello World!");
}
}
System.out.println(): this method prints a String to the
terminal.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
7 / 11
What is Java?
How does the code work?
public class Hello{
public static void main(String[] args){
System.out.println("Hello World!");
}
}
"Hello World!": this is a string.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
7 / 11
What is Java?
How does the code work?
public class Hello{
public static void main(String[] args){
System.out.println("Hello World!");
}
}
A line ending in a ";" is referred to as a statement.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
7 / 11
What is Java?
How to compile
ˆ Today, I will show you how to compile using a terminal on
Linux.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
8 / 11
What is Java?
How to compile
ˆ Today, I will show you how to compile using a terminal on
Linux.
ˆ For a Windows OS, you would use the Command Prompt,
but the overall concept is the same.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
8 / 11
What is Java?
How to compile
ˆ Today, I will show you how to compile using a terminal on
Linux.
ˆ For a Windows OS, you would use the Command Prompt,
but the overall concept is the same.
ˆ In your first lab you will use an Interactive Development
Environment (IDE).
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
8 / 11
What is Java?
How to compile
ˆ Today, I will show you how to compile using a terminal on
Linux.
ˆ For a Windows OS, you would use the Command Prompt,
but the overall concept is the same.
ˆ In your first lab you will use an Interactive Development
Environment (IDE).
ˆ So why bother with the terminal?
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
8 / 11
What is Java?
How to compile
ˆ Today, I will show you how to compile using a terminal on
Linux.
ˆ For a Windows OS, you would use the Command Prompt,
but the overall concept is the same.
ˆ In your first lab you will use an Interactive Development
Environment (IDE).
ˆ So why bother with the terminal?
There may exists situations in which you do not have an IDE
for the language you wish to compile, or in which you need to
use the terminal to help install or test software. I recommend
using the terminal for software such as git.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
8 / 11
What is Java?
How do we use the Terminal?
user@computer:~$ javac Hello.java
user@computer:~$
This compiles the Java code (written using human readable
characters) into Java bytecode.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
9 / 11
What is Java?
How do we use the Terminal?
user@computer:~$ javac Hello.java
user@computer:~$
This compiles the Java code (written using human readable
characters) into Java bytecode.
user@computer:~$ java Hello
Hello World!
user@computer:~$
This runs the Java bytecode, by using a JIT compiler. The JIT
compiler translates the Java bytecode into the bytecode used
by your computer.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
9 / 11
What is Java?
If You Own a Lab Top
ˆ Use this week to install Java and the Eclipse IDE on your
computer using directions from the syllabus.
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
10 / 11
What is Java?
If You Own a Lab Top
ˆ Use this week to install Java and the Eclipse IDE on your
computer using directions from the syllabus.
ˆ And if you don’t own a lap top?
You don’t need one, but you’ll have to spend a good
amount of time in the computer labs in Pearson!
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
10 / 11
What is Java?
Let’s make Hello.java together!
End of the lecture, let’s write code together!
Nakayama (ISU)
Com S 227: Day 0
01/09/2017
11 / 11