CSC116: Introduction To Computer Programming

Transcription

CSC116: Introduction toComputing - Java

Intro to CSC116Course Information IntroductionsWebsiteSyllabusScheduleComputing Environment AFS (Andrew File System) Linux/Unix Commands Helpful TricksComputersFirst Java Program Text Editor Remote Access Java Download

Instructors Course Instructor:– Mrs. Michelle Glatz, mlglatz@ncsu.edu Office Hours: Tues/Thurs 5:00 – 6:00 in DAN 200 and byappointment Email used to set up appointments Support email: group-csc116-glatz 007@ncsu.edu TAs:– Varsha Gopal, vgopal2@ncsu.edu Office Hour: Fridays 11am–12pm in Daniels 200– Brenden Lech, bglech@ncsu.edu Office Hour: Wednesdays 5 – 6 pm in Daniels 200

Office Hours CSC116 Office Hours:– http://go.ncsu.edu/csc116teachingstaffofficehours We will use My Digital Hand duringoffice hours to manage questions:– http://mydigitalhand.org– You should have received an email invite– Please register now

Textbook Building Java ProgramsA Back to Basics Approach4th EditionReges and Stepp NCSU CSC Department, Style Guidelines

Course WebsiteMoodle login page:http://wolfware.ncsu.eduMoodle Course Page (direct link)– course materials– submit coursework– feedback returned– grade book

Moodle Syllabus Link– Syllabus Schedule Link– Schedule– In class exercise due before end of class– Other lab exercises due on Sunday night Assignments due at 11:45 pm

Course Structure The course structure is a mixture oflecturing and practicing as we go throughmaterial. The idea is to reinforce the learning of newmaterial with hands on experience using itright away.

Exercises In-class: Group assignments completed in-class.Similar to examples Lab: Apply new concepts. Due Weekly. Practice-It! Exercises: Every 2 chapters turn inlist of problems solved as Homework(screenshot pdf: cntrl-P, capture your userid)– reate an accountchoose a problem from listType a solution and submit it.The system will test it and tell youwhether your solution is correct.

Programming Assignments There will be 6 programming projects inaddition to the Lecture Exercises. MUST BE DONE INDIVIDUALLY!!

Academic Integrity Do your own work (projects)– Don’t copy from outside resources (don’tgoogle it!)– Don’t look at other student’s code– Don’t show your code to another student See syllabus for violation penalties

Exams Two midterm exams One final exam Check the course schedule on our website fordates. Paper exams, closed book, closed notes, closedcomputer.

Message Board The course message board (Piazza) is agreat place to ask questions and discusstopics with the Instructor, TAs, and all theother students in class– piazza link The only rule is that you may not publiclypost any code that directly comes from anassignment, but example code is permitted Make the question private if need to postyour code. Post to Group 007 if specific to our section

Grading Minimum Grade RequirementNeed a 73 to advance to CSC216 To earn a C- or higher you must: have an exam average of at least 60AND have a project average of at least 60 ActivityWeightExercises:14(.2 * In-class avg .6 * Weekly Exercise avg .2 * Practice-it! avg)Projects30Comprehensive Exercise2Exam 117Exam 217Final Exam20

Regrade Requests The TA’s will send out an email to informyou when they have completed gradingof each assignment. To request a regrade (within one week): Send an email to the Teaching Staff support emailwith Regrade Request as the subject line. group-csc116-glatz 007@ncsu.edu Include the name of the assignment and why youthink it should be regraded.

Computing Environment Review of E115 topics that will beimportant for the course. The materials come from the E115 Textbook(http://ncsu.orgsync.com/org/e115/)

AFS AFS: Andrew File System Distributed file system used to organizefiles, which is used at NC State Personal home directory ncsu.edu/users/m/mlglatz

Handy UNIX Commands cd pwd ls mkdir cp mv rm rmdir

Traverse Directory Tree & FindCurrent Location cd: change directory pwd: print working directory Log on, open a terminal window, and tryentering these command at the prompt:–––––––––cd .pwdpwdcd usernamepwdcd ././.pwdcd ( or cd )pwd

What’s in a directory? ls: list contents of directory Try it:––––––cd /afs/eos.ncsu.edu/courses/csc/lsls -lcdls -als –al

Organize your CSC116 Files mkdir – make directory Try it:––––––––cdmkdir csc116cd csc116mkdir exercisesmkdir projectscd exercisesmkdir Lab1cd Lab1

Helpful Tricks/Shortcuts Up/Down arrows – Recall previous commands Tab completion – Completes commands/filenames Ctrl C – to regain command prompt if systemis “hung up”

What you will learn in CSC116 Problem solving – the purpose of writing aprogram is to solve a problem Java programming language Concepts of Object-Oriented Programming(OOP) – encapsulated collection of datavariables and methods Documentation techniques Testing methods

Computers Hardware Software Number Systems– Base 10 (decimal)– Base 2 (binary) Bits and Bytes Programming

Hardware The physical components that make up acomputer:– CPU (Central Processing Unit) Executes program instructions (brains)– Memory (RAM) Used to store current program and data– Hard Disk Permanent data storage

Software Computer programs Operating System Bridge between hardware, programs, user Allocates memory and send instructionsto CPU Applications Programs run within the operatingsystem

Binary and Decimal Typically, we (humans) use the base-10(decimal) notation.– Uses the digits 0 through 9 All information is stored on a computer asbinary numbers– 1’s and 0’s (base 2)– 10 (1 * 21 0 * 20) 2 base-10– 11 (1 * 21 1 * 20) 3 base-10– 100 (1 * 22 0 * 21 0 * 20) 4 base-10

Binary and Decimal Binary (Base-2)2423222120168421 Decimal (Base-10)10410310210110010,0001,000100101

Convert between Decimal andBinary 20 Decimal to Binary (20 – 16 4, 4 – 4 0) 1 1 1 0 0 Binary to Decimal24232221201110016840016 8 4 0 0 28

Bits and Bytes Bit – Binary Digit Byte – 8 Bits Kilobyte (KB) 210 – 1024 bytes Megabyte (MB) 220 – 1,048,576 bytes Gigabyte (GB) 230 – 1,073,741,824 bytes

Programming Languages We can write a program using only 0s and 1s, but thathas many disadvantages– Hard to look at and understand– Very tedious! We use a programming language instead - we writecode in English instead of 0s and 1s, which is mucheasier to read and understand The code we write is interpreted by a program calleda compiler, which translates our English into 0s and1s for the processor to understand Java is the programming language we will use in thiscourse

Computer Programming Algorithm - A step‐by-step description of how toaccomplish a task. Program – A list of instructions to be carried out by acomputer. Computer Programming – the art of designing andwriting a group of instructions that the computer’sprocessor executes.

Computing Environments Use Classroom/campus linux desktop computers– During class, used for lecture demos– Ensures that programs work on linux Connect Remotely to campus linux computers– Work from home– Need wifi connection– Ensures that programs work on linux Work natively on your laptop– Efficiently work at home– No need for wifi– Must transfer final files to afs and run using one of the othermethods to ensure programs work on linux.

Remote AccessWindows: https://www.itecs.ncsu.edu/software/catalog/ Run X-Win32 and then run PuTTY. X-Win32 is a X11 Windows System that enables you to display a Unix orLinux application with a graphical user interface (GUI) on your Windowscomputer. PuTTY is a SSH client that gives you terminal access to run commands andcommand-line applications (make sure to enable X11 forwarding). Click on application to download Brings you to software download page There is a documentation/installation link for each application.Macintosh: Download and Install XQuartz: https://www.xquartz.org/ Run XQuartz then open terminal window Application Utilities Terminal ssh -X -Y your unity id@remote.eos.ncsu.edu

File TransferTransfer Files between Your Laptop and AFS https://www.itecs.ncsu.edu/software/catalog/ For the desired application:– Click on supplication name Brings you to software download page Click on desired downloadWindows: Use FileZilla and/or WinSCP.Macintosh: Use FileZilla

Software You may download the Java 2 Standard Edition (J2SE)Software Development Kit (JDK) downloads/index.html– Download JDK version 8u191, DO NOT download version 11. Text Editor Campus Linux Computers gedit (gedit filename & - opens in newwindow) Mac TextWrangler, Aquamacs Windows Notepad

Configure Editor Configure to convert tabs to 4 spaces sources/text-editorspaces.html– TextWrangler : Preferences- Editor Defaults- Auto-expand tabsSet tabs to 4 spacesrestart TextWrangler for changes to take place– Notepad : Settings- Preference- LanguageSet Tab size to 4Check Replace by space box– Gedit:gedit icon in the application bar (top of screen)Go to Preferences. Insert spaces instead of tabs

Java Download for Laptop The next set of slides show the java download and setup process. The current version on the download site is Version 11.– We will be using version 8 The java version used for demonstration is version 8update 152 (current version is 191) loads/index.html

Download JavaCurrent Download is Version 11, don’t download this one.

Download JavaPage down to the following Version 8 downloads. Clickon the JDK download

Accept Agreement

Installation Save the file to the desktop and run it Install to default locationThe installation screen should read (don't change it):Install to:C:\Program Files\Java\jdk1.8.0 152\

Installation

Install Directory

Setting the Path – Windows Once the installer is finished, you must set your computer's pathbefore Java will work correctly – FOR WINDOWS ONLY Go to the Control Panel and double-click System Select the Advanced tab Click on the Environment Variables button Look under System Variables for "Path"Click on "Path" and then click edit Add the following to the end of the Path:;C:\Program Files\Java\jdk1.8.0 152\bin Click OK.

Setting CLASSPATH - Windows Look to see if there is a variable namedCLASSPATH If there is not, then Click the "New" button. For the variable name, type:CLASSPATH For the value, type: .; (that period semicolon) Click OK. Exit out of all the open windows

Installed Correctly? Open up a command prompt.– On Windows: Open Command Prompt- On MAC OSX: Open the Applications folder,open the Utilities folder, then open the Terminal application. Type java and hit enter "command not found“ means java is not installed correctly list of options for running java means installed ok Type java -version and hit enter It should list version you installed (e.g. 1.8.0 152)

Write Compile Execute A human writes Java code, known as source code (.java file)– gedit HelloWorld.java & The Java compiler converts the source code into machine codeor byte code (.class file)– javac HelloWorld.java The computer has a Java Virtual Machine (JVM), whichtranslates the byte code into instructions that the specificcomputer’s processor can understand.– java HelloWorld A .class file can be used on any computer that has a VirtualMachine, no matter what platform the class file was created on(platform independence) Output – messages printed to the screen

Classic First Program Write a program that prints the text “Hello, World!” to thescreenpublic class HelloWorld {public static void main(String[ ] args) {System.out.println(“Hello, World!”);}}RULE:The name you give your class MUST be the same name you giveyour file. Thus, the above program must be saved in a file calledHelloWorld.java

In-Class Assignment Go to our Moodle page and work on theHelloWorld.java assignment:/*** This is an example class that illustrates printing a message to the screen** @author YOUR NAME*/public class HelloWorld {public static void main(String[] args) {System.out.println("Hello World! My name is [put your name here].");System.out.println("I [am new to programming, have done some Java/C/etc. programming].");System.out.println("I am a [freshman, sophomore, junior, senior] in the [department name]department.");System.out.println("At home, I use a [pc, mac, etc] with the [Windows 7/8/10, OSX, Linux, etc]operating system.");}}

Computer Programming Algorithm - A step‐by-step description of how to accomplish a task. Program –A list of instructions to be carried out by a computer. Computer Programming –the art of designing and writing a group of instructions