Unformatted text preview:

Topic 2 Java BasicsAgendaBrief History of Java and Overview of LangaugeSlide 4How Java WorksMore on How Java WorksA Picture is Worth…So What!HelloWorld.javaMore on Java ProgramsAttendance Question 1Attendance Question 2Example ProblemError TypesJava Language Review of Basic FeaturesBasic FeaturesJava Data TypesIdentifiers in JavaData TypesJava Primitive Data TypesWhat are Classes and Objects?Creating and Using ObjectsBuilt in ClassesimportMore on importThe String ClassStandard OutputConstantsExpressions and OperatorsOperatorsExpressionsCastingPrimitive CastingJava Control StructuresControl StructuresBoolean ExpressionsMore Flow of Controlfor Loopswhile loopsAttendance Question 3Attendance Question 4ArraysArrays in JavaArray DetailsArray InitializationArrays of objectsArray UtilitiesThe arraycopy method2D Arrays in JavaTwo Dimensional ArraysThe Real PictureArrays of Multiple DimensionRagged ArraysEnhanced for loopSlide 55Attendance Question 5Attendance Question 6MethodsSlide 59More on Methodsstatic methodsMethod Overloading and ReturnMethod ParametersValue Parameters vs. Reference ParametersValue vs. ReferenceProgramming for CorrectnessCreating Correct ProgramsProgramming by ContractThinking about pre and postconditionsPrecondition ExampleSlide 71AssertionsAssertions Uncover Errors in Your LogicjavadocCS 307 Fundamentals of Computer ScienceJava Basics1Topic 2 Java Basics"On the other hand, Java has already been a big win in academic circles, where it has taken the place of Pascal as the preferred tool for teaching the basics of good programming…"-The New Hacker's Dictionary version 4.3.1www.tuxedo.org/~esr/jargon/html/The-Jargon-Lexicon-framed.htmlCS 307 Fundamentals of Computer ScienceJava Basics2AgendaBrief History of Java and overview of languageSolve a problem to demonstrate Java syntaxDiscuss coding issues and style via exampleSlides include more details on syntax–may not cover everything in class, but you are expected to know theseCS 307 Fundamentals of Computer ScienceJava Basics3Brief History of Java and Overview of Langaugejava.sun.com/features/1998/05/birthday.htmlCS 307 Fundamentals of Computer ScienceJava Basics4A brief history of Java–"Java, whose original name was Oak, was developed as a part of the Green project at Sun. It was started in December '90 by Patrick Naughton, Mike Sheridan and James Gosling and was chartered to spend time trying to figure out what would be the "next wave" of computing and how we might catch it. They came to the conclusion that at least one of the waves was going to be the convergence of digitally controlled consumer devices and computers. "Applets and Applications–"The team returned to work up a Java technology-based clone of Mosaic they named "WebRunner" (after the movie Blade Runner), later to become officially known as the HotJavaTM browser. It was 1994. WebRunner was just a demo, but an impressive one: It brought to life, for the first time, animated, moving objects and dynamic executable content inside a Web browser. That had never been done. [At the TED conference.]"CS 307 Fundamentals of Computer ScienceJava Basics5How Java WorksJava's platform independence is achieved by the use of the Java Virtual MachineA Java program consists of one or more files with a .java extension–these are plain old text filesWhen a Java program is compiled the .java files are fed to a compiler which produces a .class file for each .java fileThe .class file contains Java bytecode. Bytecode is like machine language, but it is intended for the Java Virtual Machine not a specific chip such as a Pentium or PowerPC chipCS 307 Fundamentals of Computer ScienceJava Basics6More on How Java WorksTo run a Java program the bytecode in a .class file is fed to an interpreter which converts the byte code to machine code for a specific chip (IA-32, PowerPC) Some people refer to the interpreter as "The Java Virtual Machine" (JVM) The interpreter is platform specific because it takes the platform independent bytecode and produces machine language instructions for a particular chipSo a Java program could be run an any type of computer that has a JVM written for it.–PC, Mac, Unix, Linux, BeaOS, SparcCS 307 Fundamentals of Computer ScienceJava Basics7A Picture is Worth…The Interpreter's are sometimes referred to as the Java Virtual MachinesThe output of the compiler is .class fileCS 307 Fundamentals of Computer ScienceJava Basics8So What!The platform independence of Java may be a huge marketing tool, but is actually of little use to people learning Object Oriented Programming and Abstract Data TypesWhat is of use is the simplicity of the Java syntax and programming conceptsJava is a "pure" Object Oriented Language–encapsulation, inheritance, and polymorphism–all code must be contained in a class–no free functions (functions that do not belong to some class) like C++, although someone who wants to write messy Java code certainly can–Is OO the best programming paradigm?CS 307 Fundamentals of Computer ScienceJava Basics9HelloWorld.java/** * A simple program */public class HelloWorld{public static void main(String[] args){System.out.println("HELLO CS307!");}}CS 307 Fundamentals of Computer ScienceJava Basics10More on Java ProgramsAll code part of some class public class Foo { //start of class Foo /*all code in here!*/ } // end of class FooThe code for class Foo will be in a file named Foo.java–just a text file with the .java extension–a class is a programmer defined data typeA complete program will normally consist of many different classes and thus many different filesCS 307 Fundamentals of Computer ScienceJava Basics11Attendance Question 1What does 6,967 * 7,793 equal?A. 10,000B. 23,756,201C. 54,293,831D. 2,147,483,647E. - 2,147,483,648CS 307 Fundamentals of Computer ScienceJava Basics12Attendance Question 2How many factors does 54,161,329 have?A. 2B. 3C. 4D. 6E. more than 6Bonus question. What are they?CS 307 Fundamentals of Computer ScienceJava Basics13Example ProblemDetermine if a given integer is prime–problem definition–really naïve algorithm–implementation–testing–a small improvement–another improvement–yet another improvement–always another way ...–what about really big numbers? (Discover AKS Primality Testing)CS 307 Fundamentals of Computer ScienceJava Basics14Error TypesSyntax error / Compile errors–caught at compile time.–compiler did not


View Full Document

UT CS 307 - Topic 2 Java Basics

Documents in this Course
Midterm 2

Midterm 2

15 pages

Midterm 1

Midterm 1

15 pages

Syllabus

Syllabus

24 pages

s

s

8 pages

Midterm 1

Midterm 1

14 pages

Midterm 2

Midterm 2

14 pages

Recursion

Recursion

14 pages

Midterm 1

Midterm 1

16 pages

Load more
Download Topic 2 Java Basics
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Topic 2 Java Basics and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Topic 2 Java Basics 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?