1.00 Tutorial 1 Introduction to 1.00 Outline • • • • • Introductions Administrative Issues PS#0 PS#1 Java® Fundamentals 1 Introductions • T A & s tudents introduce yourselves – Name – Y ear • P leas e s ign attendance s heet • P artner ass ignments Office Hours • Office hours are held thrice / week • F eel free to come with ques tions about J ava®, s oftware, or homework, but... • Don't come in if you need homework help, and you have not s erious ly tried to do it on your own. Y ou will be as ked to leave. • T utorial S ections : if you need to s witch s ections , s end email. 2 Course Website • Certificate problems? – Have you installed MIT personal certificates? – Use Netscape instead of Internet Explorer – For "unknown SSL error (-12227)": • • • • uninstall Netscape delete profile folder* (backup bookmarks first) download and install Netscape 7 from web get MIT site certificate and MIT personal certificates (see instructions on course website) *See http://wp.netscape.com/eng/mozilla/ns62/CCKDocs/profile_appx_cck.htm for the path to the profile directory under different operating systems Laptop Problems • See MIT website for where to go for software /hardware problems. 3 Forte: Basics • Startup (just double-click once and wait!) • Make sure the Java® SDK 1.4 API documentation is installed. If not, get from http://java.sun.com/j2se/1.4/download.html (Scroll down to documentation section.) • To check, type the word "String" in the Source Editor, right click, and select "Show Javadoc" PS #0 • Problem 2: Hand In • Problem 3: Hello World (get checked off) • Problem 4: Upload file to your 1.00 homework locker (get checked off) • Problem 5: set up printing in Forte – set up Athena printer 4 PS#1: in class exercise • • • • • • • • declare a variable assign a value to a variable what is a floating point number? what is a float? a double? boolean? assign a value to a boolean what is a String? print a string Math: more exercises • Declare two ints, add them and print the result • Print out the square root of 2 • Print out (pi to the square root of 2) • What is the value of the following expressions (as integers)? 1%3 7%3 1/2 3/2 5 Java® Variables • have a type • are case sensitive (studentCount is different from studentcount) • begin with a letter, underscore, or $: i, _tmp, $x • cannot be Java® keywords. The following are not legal variable names: for, goto, import, while, do,... Java® Fundamental Types • • • • • • • • type boolean (true or false) byte char short int long float double bits 1 8 16 16 32 64 32 64 6 Examples int studentCount = 91; char firstLetter = 'a'; float weight = 180.6F; double area = Math.PI * 5.0 * 5.0; boolean enjoy1.00 = true; boolean xGreaterThanY = x > y; long theNumberOne = 1L; double googol = 1E100; /* 10100 */ Conversion between types • Implicit (automatic) conversion is called promotion: int promoted to double double x = 3.1415 + 2; • Explicit conversion is called casting int myAge = (int)(Math.PI*10.0+4.0); expression cast to int this expression is a double (very accurate) 7 Type Conversion • You will need to perform type conversion often • Watch out for promotion: very common source of (hard-to-find) bugs • Safer to use casting Promotion rules Data Type double float long int char short byte Allowed Promotions None double float,double long,float,double int,long,float,double int, long,float,double short,int,long,float,double Java® is a trademark or registered trademark of Sun Microsystems, Inc. in the United States and other countries. 8