DOC PREVIEW
UT CS 307 - Java Basics

This preview shows page 1-2-3-4-5-6 out of 19 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Topic 2Topic 2 Java Basics"On the other hand, Java has already been a big winin academic circles where it has taken the place ofin academic circles, where it has taken the place of Pascalas the preferred tool for teaching the basics of good programming"good programming…-The New Hacker's Dictionary version 4.3.1www tuxedo org/~esr/jargon/html/TheJargonLexiconframed htmlwww.tuxedo.org/~esr/jargon/html/The-Jargon-Lexicon-framed.htmlCS 307 Fundamentals of Computer ScienceJava Basics1AgendaBrief History of Java and overview of languageSolve a problem to demonstrate Java syntaxDiscuss coding issues and style via examplescuss cod g ssues a d sty e a e a p eSlides include more details on syntaxmay not cover everything in class but you are–may not cover everything in class, but you are expected to know theseCS 307 Fundamentals of Computer ScienceJava Basics2Brief History of Java and Overview of Langaugejava.sun.com/features/1998/05/birthday.htmlCS 307 Fundamentals of Computer ScienceJava Basics3A brief history of Java–"Java whose original name was Oak was developed as a–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 timetryingtoJames 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 ofleast 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 HotJavaTMbrowser It was 1994WebRunnerwas just ademobut anbrowser. It was 1994. WebRunnerwas 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 CS 307 Fundamentals of Computer ScienceJava Basics4[conference.]"How Java WorksJ'ltf id d i hidbthJava's platform independence is achieved by the use of the Java Virtual MachineA Java program consists of one or more files with aA 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 filefor each .java fileThe .class file contains Java bytecode. Bytecode is like machine language but it is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 Basics5More on How Java WorksT J h b d i l fil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 (IA32to machine code for a specific chip (IA-32, PowerPC) Some people refer to the interpreter as"The JavaSome people refer to the interpreter as The Java Virtual Machine" (JVM) The interpreter is platform specific because it takesThe 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.CS 307 Fundamentals of Computer ScienceJava Basics6– PC, Mac, Unix, Linux, BeaOS, Sparc A Picture is Worth…The output of the compiler is .class fileThe Interpreter's are sometimes referred to as the Java Virtual CS 307 Fundamentals of Computer ScienceJava Basics7MachinesSo What!The platform independence of Java may be a hugeThe platform independence of Java may be a huge marketing tool, but is actually of little use to people learning Object Oriented Programming and Ab t t D t TAbstract Data TypesWhat is of use is the simplicity of the Java syntax and programming conceptsand programming conceptsJava is a "pure" Object Oriented Language–encapsulation, inheritance, and polymorphismencapsulation, inheritance, and polymorphism– all code must be contained in a class– no free functions (functions that do not belong to some class) like C++ altho gh someone ho ants to riteclass) 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 Basics8HelloWorld.java/*** A simple program*/bli l H ll W ldpublic class HelloWorld{public static void main(String[] args)public static void main(String[] args){System.out.println("HELLO CS307!");System.out.println( HELLO CS307! );}}CS 307 Fundamentals of Computer ScienceJava Basics9}More on Java ProgramsAll code part of someclassAll code part of some classpublic class Foo {//start of 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 diff t filCS 307 Fundamentals of Computer ScienceJava Basics10different filesAttendance Question 1What does 6,967 * 7,793 equal?A. 10,000B. 23,756,201C 54 293 831C. 54,293,831D. 2,147,483,647E2 14 483 648E. -2,147,483,648CS 307 Fundamentals of Computer ScienceJava Basics11Attendance Question 2How many factors does 54,161,329 have?A. 2B. 3C4C. 4D. 6Eh6E. more than 6Bonus question. What are they?CS 307 Fundamentals of Computer ScienceJava Basics12Example ProblemDetermine if a given integer is prime– problem definition– really naïve algorithm– implementation– testing–a small improvementp– another improvement–yet another improvementyp– always another way ...–what about really big numbers? (Discover AKSCS 307 Fundamentals of Computer ScienceJava Basics13what about really big numbers? (Discover AKS Primality Testing)Error TypesSyntax error / Compile errors– caught at compile time.– compiler did not understand or compiler does not allowRuntime error– something “Bad” happens at runtime. Java breaks these into Errors and ExceptionsLogic Errorg– program compiles and runs, but does not do what you intended or wantCS 307


View Full Document

UT CS 307 - 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 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 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 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?