cs211sp08-01 - CS 211 Spring 2008 very quick overview of...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 211 Java overview very quick overview of Java basics actually use inheritance and interfaces intro to threads GUIs recursion/induction, efficiency, sorting data structures (lists, queues, stacks, trees, etc) graph algorithms applications LOTS of programming ! 1 CS 211 - Spring 2008 Books etc. - at java.sun.com /reference/api /docs/books/tutorial - IDE from www.eclipse.org - The Java Language Specification (Gosling et al) - Data Structures and Algorithm Analysis in Java (Weiss) 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS 211 Java overview Java uses classes and objects = hyper organised ! A class Car is like a manufacturer who only construct s individual new cars. A class Bucket will only construct individual new buckets. Cars and buckets have natural things which belong to every car or bucket, although of course cars have different colours, etc.! 2 2
Image of page 2
CS 211 Java overview To build a red car called ferrari, we might write Car ferrari = new Car(red); - I’m not promising that this will work!!!! and to build a yellow car called ccbb, we might write Car ccbb = new Car(yellow); Of course, Bucket rollsroyce = new Bucket(huge); will only give you a peculiarly named huge bucket. If you want to access stuff in your car, then the dot is the “genitive case”, so ferrari.colour would be red, and ccbb.colour would be yellow. This is also like a path ; looking into the ferrari or the ccbb to find the individual colours. More on this later ..... . 3 3
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS 211 Java overview Enough of such generalities! How do we write a simple program in Java? First we need to be able to get stuff in to and out from the computer! System.out.println ( “Once upon a time ...” ) ; looks into the System where it finds an out , and looks into System ’s out where it finds a method (or function or routine ) which can print a String of characters onto a fresh line on the standard output screen. System.out.print ( “Golly gosh” ) ; does exactly the same, except the method print doesn’t finish with a “new line”. 4 - i /o 4
Image of page 4
CS 211 Java overview To read in a String of characters from the standard input keyboard, InputStreamReader nab = new InputStreamReader(System.in); BufferedReader grab = new BufferedReader(nab); constructs a BufferedReader called grab so that grab.readLine( ); reads a whole line of input. Java is a language of “let’s pretend!”, so grab is a virtual keyboard which has the ability (amongst other skills) of readLine( ) - all the other stuff is there to establish a connection between “make believe” and “reality”. 5 - i /o 5
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS 211 Java overview We can do the same thing with files, FileReader secret = new FileReader ( “spy.oops” ) ; BufferedReader james = new BufferedReader (secret) ; constructs a BufferedReader called james so that james.readLine( ) ; reads a whole line of input from spy.oops . As a matter of common courtesy, you should secret.close( ) ; close the ‘file’ when you’ve finished with it! (If you need to specify a path for your file, you can have = new FileReader ( “c:/money/penny/spy.oops” ) ; or whatever is appropriate for your system.) 6 - i /o 6
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern