CS 177 Recitation Week 1 – Intro to Java. Questions?

Slides:



Advertisements
Similar presentations
Lecture 0 CSIS10A Overview. Welcome to CSIS10A (5 mins) – Typical format for class meetings New material first (monitors off, notebooks out) Practice.
Advertisements

JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. OBJECTIVES FOR THIS UNIT Upon completion of this unit, you should be able to: Explain the Java virtual machine.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. GCOC – A.P. Computer Science A College Board Computer Science A Topics Covered Program Design - Read and understand.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Your First Java Program: HelloWorld.java
Chapter 1: Introduction
C Programming for engineers Teaching assistant: Ben Sandbank Home page:
Chapter 2: Your First Program! Hello World: Let’s Program  All programs must have the extension.java  Our first program will be named: HelloWorld.java.
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.
Week 1 - Wednesday.  What did we talk about last time?  Syllabus  Computers.
How to Create a Java program CS115 Fall George Koutsogiannakis.
How do we make our HelloTester.java program do something? The java in our HelloTester.java file won’t do anything by itself. We need to tell the computer.
Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming.
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
CMPT 120 Introduction to Computer Science and Programming I Chris Schmidt.
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
School of Computing Science CMT1000 © Ed Currie Middlesex University Lecture 3: 1 CMT1000: Introduction to Programming Ed Currie Lecture 3: Program structure.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Getting Started with Java
IB Computer Science II Paul Bui
Hello AP Computer Science!. What are some of the things that you have used computers for?
1 TOPIC 1 INTRODUCTION TO COMPUTER SCIENCE AND PROGRAMMING Topic 1 Introduction to Computer Science and Programming Notes adapted from Introduction to.
COMP 110: Introduction to Programming Tyler Johnson January 14, 2009 MWF 11:00AM-12:15PM Sitterson 014.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
Hello World 2 What does all that mean?.
CS 106 Introduction to Computer Science I 01 / 25 / 2010 Instructor: Michael Eckmann.
What is a Computer? An, electrical machine, that can be programmed to accept data (input), process it into useful information (output) and store it away.
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
CSC204 – Programming I Lecture 4 August 28, 2002.
Programming With C.
Introduction to Computer Systems and the Java Programming Language.
Board Activity Find your seat on the seating chart Login – Remember your login is your first initial your last name and the last three numbers of your.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
CSCI Processing CSCI Introduction to Algorithm Design An Introduction.
Compiling and the Java Virtual Machine (JVM). The syntax of Pseudocode is pretty loose –visual validation encourages a permissive approach –emphasized.
Chapter 2: Java Fundamentals
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Introduction to programming in the Java programming language.
8/31: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
CS101: Introduction to Computer Science Slides adapted from Sedgewick and Wayne Copyright © Your First Java.
1 TOPIC 1 INTRODUCTION TO COMPUTER SCIENCE AND PROGRAMMING Topic 1 Introduction to Computer Science and Programming Notes adapted from Introduction to.
1 WELCOME TO CIS 1068! Instructor: Alexander Yates.
Hello Computer Science!. Below is an example of a Hello World program in JAVA. While it is only three lines of code, there are many things that are happening.
Chapter 1- Basic Computing and your first program.
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
CSC 110 – Intro to Computing - Programming
ITP 109 Week 2 Trina Gregory Introduction to Java.
Programming for Interactivity Professor Bill Tomlinson Tuesday & Wednesday 6:00-7:50pm Fall 2005.
1/16: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Introduction to programming in java
Computer Programming Your First Java Program: HelloWorld.java.
Week 1 - Wednesday CS 121.
Lecture 1b- Introduction
CSC201: Computer Programming
Java programming lecture one
Intro to Java.
String Output ICS 111: Introduction to Computer Science I
Introduction to Algorithm Design
Tonga Institute of Higher Education
Java Intro.
Programming Fundamentals Lecture #3 Overview of Computer Programming
IB Computer Science II Paul Bui
Computer Programming-1 CSC 111
Week 1 - Friday COMP 1600.
How to Run a Java Program
Presentation transcript:

CS 177 Recitation Week 1 – Intro to Java

Questions?

Computers  Computers can do really complex stuff. How? By manipulating data according to lists of instructions.  Fundamentally, this is all that a computer can actually do.  Different kinds of computers: supercomputers, desktops, laptops, embedded.  Different kinds of computer have different sizes, computing powers, uses, etc.

Computers  What is hardware? What are some examples?  What is software? What are some examples?  The physical components of the computer (stuff you can touch).  monitor, CPU, keyboard, memory, hard drive, etc.  Programs that run on the hardware and make it do stuff.  Windows, Firefox, MS Powerpoint, World of Warcraft, etc

Computers  What are some important (hardware) parts of a computer?  CPU – does calculations (the brain)  Memory – stores data (cache, RAM, hard drive, etc)  I/O devices – allows the user and the computer to communicate (monitor, mouse, keyboard, etc)

Programming  Computers only manipulate data according to a list of instructions.  Computers are stupid, but really fast.  Computers can only do very simple things (like adding two numbers), but they can do millions or billions of simple things a second.  Programming – the process of creating lists of instructions for the computer to follow.

Programming  The process of software development: 1) Understand the problem that you need to solve. 2) Plan a solution to the problem. 3) Implement the solution (write the program). 4) Test the program (compile and run it), and fix any errors.

Programming Languages  We have to use programming languages to give computers instructions because human languages (like English) are too vague.  We are going to write programs in a programming language called Java.  There are lots of other programming languages too.

Programming Languages  We classify programming languages as high or low level.  Low level languages are closer to (or are) what the computer actually understands, and have very simple commands.  ex) machine code, assembly languages  High level languages are easier for humans to understand and have more complex commands.  Programs written in high level languages have to be translated to a low level language before they can be run.  ex) Java, Python

Compiling  What special program translates a program written in a high-level language into a low-level language?  a compiler  How things usually work:  The compiler translates the program directly into machine code and the program can be run.

Compiling  Java is weird:  The Java compiler translates the program into bytecode, a sort of intermediate language.  When the Java program is run, the Java Virtual Machine compiles/translates the bytecode into machine code, and then the program runs.  The machine code produced is different depending on the computer. The bytecode will be the same no matter what computer the program is compiled on.  The “Whatever.class” file you get after compiling your “Whatever.java” file contains the bytecode.

Java  Java programs are just text files, and can be written in any text editor or DrJava.  Java is a language, and therefore has rules that you have to learn and obey.  If you do not follow Java’s rules, your program will not compile or won’t run correctly.

Anatomy of a Java Program public class NameOfClass { public static void main(String[] args) { }  Every Java program must be inside a class. The keyword class tells Java that you are making a new class.  Replace NameOfClass with what you want to call your program. The program will need to be saved in a file called NameOfClass.java.  For now, the rest of the stuff is magic words. Just remember to type them in, or your program won’t work.

Simple Program public class HelloWorld { public static void main(String[] args) { System.out.print(“Hello, world! ”); System.out.println(100.34); System.out.println(“Programming is fun!”); }  This program just prints some stuff on the screen.  You can use System.out.println() to print anything in quotes (“fish”, “foobar”) or numbers (5, 20.6).  System.out.print() does the same thing, but does not put a newline after the printed stuff.

Running a Program  Let’s run our HelloWorld program and see it in action! There are two different ways to do it.  In the terminal or command prompt:  Change to the directory where your Java file is saved.  To compile, type “javac HelloWorld.java”  If you don’t see any messages, your program compiled successfully.  Compiling creates a “class” file with the same name as your Java file (in this case, “HelloWorld.class”).  To run, type “java HelloWorld”.

Running a Program  In DrJava:  To compile, push the “Compile” button (upper right corner of the window).  If it says “Compilation completed”, everything worked.  To run, push the “Run” button (near the Compile button).  NOTE: You don’t have to use DrJava if you don’t want to, especially at home. It will probably make your life easier, though.

Some Java Details  All statements in Java must end with a semicolon (;).  Think of it like the period at the end of an English sentence.  All classes and methods must have curly braces ({ and }) around their contents.  Java is case sensitive (“class” is not the same as “Class” or “CLASS” or “cLAss”).

Comments  Programs can be confusing to read.  Use comments to leave notes for yourself or anyone else who reads your code.  Comments do not affect how the program runs (they’re ignored by the computer).  Two ways to make comments:  // I’m a comment  Use for single-line comments  /* I’m a comment. */  Use for comments that are multiple lines long

Coding with Style!  Java ignores whitespace, so use whitespace to make your code more readable.  Indent all the lines of code between a class’ or method’s curly brackets.  This makes your code MUCH easier to read. Really. It does.  We WILL take points off on assignments if you do not indent your code nicely!

Indentation Examples  Good public class NameOfClass { public static void main(String[] args) { System.out.println(“Hello, world!”); }  Bad public class NameOfClass { public static void main(String[] args) { System.out.println(“Hello, world!”); }  Horrible! public class NameOfClass { public static void main(String[] args) { System.out.println(“Hello, world!”); }

Questions?