Java Programming Week 1 - University Of New Haven

1y ago
306.50 KB
25 Pages
Last View : 4d ago
Last Download : 6m ago
Upload by : Wren Viola

OutlineJava is. . .Let’s get started!Java ProgrammingWeek 1Alice E. FischerJanuary 22 and 29, 2015Java Programming -Week 1. . .1/25

OutlineJava is. . .Let’s get started!Java is. . .The JDKExamples: Two Kinds of ProgramsLet’s get started!BasicsInput and OutputJava Programming -Week 1. . .2/25

OutlineJava is. . .Let’s get started!The JDKJava is. . .The Java Development KitByte Code in the SandboxThe Garbage CollectorJava is Object OrientedTwo Kinds of ProgramsJava Programming -Week 1. . .3/25

OutlineJava is. . .Let’s get started!The JDKJava is HugeThe parts of Java are:IA core language that is a lot like C.IMany many libraries.IToolkits for building windowing and network applications.IA compiler to go from source code to byte code.IA virtual machine that executes Java byte code.Java Programming -Week 1. . .4/25

OutlineJava is. . .Let’s get started!The JDKThe Java Development Kitincludes a byte-code compiler and loader, toolkits, libraries, and abyte-code interpreter. The IDE is an independent application.Eclipse or Your IDEYour Program CodeJDKJava LanguagejavaJavacJavadocjarScriptingRich Internet Applications:Toolkits:FXJava 2DIntegration Libraries:JDBCMore Base Libraries:JREJNIMathBase nizingJava HotSpot Client and Server VMAccessibilityRMIInt'l SupportNetworkinglangSecurityJava Web strumentationJust In Time Compiler (JIT)Java Virtual MachineLinux or Windows or MacOSX5/25Java systems run on top of many operatingsystems.Java Programming -Week 1. . .

OutlineJava is. . .Let’s get started!The JDKByte Code in the SandboxJava uses byte-code to achieve portability (system independence).IA .java file is translated into a .class file.IAll the .class files for an application are combined into a .jarfile or a .war fileIThe .jar file can be executed on any machine that has a JavaVirtual Machine (JVM)IThe JVM interprets the byte codes by executing theappropriate machine instructions for the local computer.IProtections are built into the JVM to prevent code fromwiping out the system. We say that java programs executeinside a sandbox.Java Programming -Week 1. . .6/25

OutlineJava is. . .Let’s get started!The JDKThe Java SandboxJava program(,java file)lexerJava Interpreter (back end)"The Sandbox"parserbyte codemodule.class fileClassverifier &loaderrunningJavaprogramJava Compiler (front end)Byte codeinterpreterJava Programming -Week 1. . .7/25JIT compiler

OutlineJava is. . .Let’s get started!The JDKFrom Source to Bytecodeint k 17*17;Java Programming -Week 1. . orintk 17*17;Declare kAssignmentStatement8/25Bytecode

OutlineJava is. . .Let’s get started!The JDKSafe for Beginners?Java was designed to be a safe language.I It is safe to run an Applet imported from elsewhere becausethe Applet runs in a sandbox.I Java attempts to find and forbid every kind of error that it ispossible to find at compile time.I There are no explicit pointers. That means you can’t makethe same kind of pointer errors you make in C.I However, explicit or not, the pointers are there and sometimescause problems. Java’s favorite run-time error comment is”Null Pointer Error”.I Memory areas that can no longer be used (garbage) areidentified and collected automatically. This frees the programfrom the need to manage his own allocations.Java Programming -Week 1. . .9/25

OutlineJava is. . .Let’s get started!The JDKThe Garbage CollectorLike C, Java has three kinds of storage:Iauto: stored on the run-time stack, created / discarded whena function is called / returnsIstatic: created and initialized when the program is loaded.Persists until the program terminates.Idynamic: allocated using malloc or new.C and Java handle auto and static storage the same way. However,when dynamic storage is needed,IIn C, it must be explicitly freed by the programmer.IIn Java, it sits there until the garbage collector picks it up forrecycling. The cost, of course, is inefficiency and a loss ofcontrol over timing.Java Programming -Week 1. . .10/25

OutlineJava is. . .Let’s get started!The JDKJava is Object OrientedBut what does Object Oriented mean?IIt is a way of thinking, not a language or set of languages.IData representation is designed first, code second.IA class is a collection of data fields plus the functions thatoperate on that data.IEverything is defined around classes; they contain data andrelated functions.IObjects are instances of classes.IEach class should protect itself and take care of itself.IMuch attention is paid to the ways in which classes interact.Java Programming -Week 1. . .11/25

OutlineJava is. . .Let’s get started!Examples: Two Kinds of ProgramsTwo Kinds of Java ProgramsWe will study two kinds of Java programs:IA console program, sometimes called “tool”: WinterWorkYou see the output in the console window.IApplication: Winter.javaThe application creates its own graphics window and uses it.When you launch the application, the window appears.Java Programming -Week 1. . .12/25

OutlineJava is. . .Let’s get started!Examples: Two Kinds of ProgramsWinterWorkA console program can run from the command line and uses thecommand window for input and output.IA console program must define a class.IInside that class there must be a main function.IInstead, an application has a start function and it runs insidethe Java FX environment.IAt the top of the file, a comment should document thepurpose of the class, the author, and the date.We will write console programs for a few weeks until this class hasmastered Java basics.Java Programming -Week 1. . .13/25

OutlineJava is. . .Let’s get started!Examples: Two Kinds of ProgramsAn FX Application: WinterIA graphics window lets you create output in color, withvarious fonts (lines 22–24).IAn application has a start() function and can be run from acommand shell or an IDE.IIt is derived from the class Application, which supplies agraphics window for your content.IThe start() function creates the contents of the window(lines 35–38) and makes it visible.IThe class members (line 18–25) define the parts of thewindow.Java Programming -Week 1. . .14/25

OutlineJava is. . .Let’s get started!BasicsJavadoc CommentsOO VocabularyWinterWorkInput and OutputMiles Per HourConsole InputConsole OutputJava Programming -Week 1. . .15/25

OutlineJava is. . .Let’s get started!BasicsJavadoc CommentsIn addition to the two kinds of comments C, we have a third:IIIIA Javadoc comment starts with /** and a brief generaldescription of the purpose of the function. It ends with thenext */.Inside, you write javadoc annotations such as @author, @since,@param, @return. Each one is followed by relevantinformation.Following that is a detailed description of what the functiondoes.When your source code is run through a Javadoc application,it generates html documentation pages from your Javadoccomments. This makes it easy to keep the documentation foryour program up to date.Java Programming -Week 1. . .16/25

OutlineJava is. . .Let’s get started!BasicsOO VocabularyIIIIIIpackage: A package is a set of classes that work together andare stored in the same subdirectory. When you use asystem-defined package, you usually import its publicdeclarations into your namespace.When you create your own package, it must have the samename as the directory in which it is stored.class: Everything in Java is inside classes. Each class has aname. A publicclass must be in a file with the same name.instantiate: To make a new object, we instantiate a class.The object is called and instance of the class.object: An instance of a class.primitive: An instance of built-in type such as int or double.Java Programming -Week 1. . .17/25

OutlineJava is. . .Let’s get started!BasicsKeywordsIpublic: a class, function, or data object that may be used byany part of your program.Istatic: A static function or variable can be used immediatelywhen your program is loaded. Your main function must bepublic static.Iimport: This command brings into your program the names ofall the public members of the selected package. You can usethese public members without the “import”, but then youmust write the entire long name each, including the class andpackage that it is defined in.Java Programming -Week 1. . .18/25

OutlineJava is. . .Let’s get started!BasicsWinterWork/** a first Java [email protected] Alice [email protected] 1/29/07*/public class WinterWork {// A console program must have a main function.public static void main(String[] args) {System.out.println( "\n Winter time, Java.");System.out.println( " New, yet not new, much to " "learn.\n Hard work brings rewards.\n ");}}Java Programming -Week 1. . .19/25

OutlineJava is. . .Let’s get started!BasicsElements to note in WinterWork.javaIThe author’s name and other identifying information shouldbe in a Javadoc comment at the top of the file.IOther comments begin with // and go to the end of the line,or begin with /* and end with */Iimport commands bring the names defined within a packageinto your namespace. java.lang contains the most basicclasses in the Java language. It is imported automatically, sothis command may be omitted.IThe most basic parts of Java are like C, including statements,string literals, and newline characters.Java Programming -Week 1. . .20/25

OutlineJava is. . .Let’s get started!Basicspublic static void main( String[] args );IIf something is static, it can be used without creating anyobjects. The Java libraries are full of public static functionsthat can be called any time, any where.IThe main function must always be public and static Theseproperties make it possible for main to be started up by theJava system.IThe main function must void. Unlike a main program in C,it will NOT return any status code or information of any kindto the Java system when the program ends.IThe Java system CAN send command-line arguments intomain, although we will not do so this term. These are sent tomain in the form of an array of Strings: (String[] args )Java Programming -Week 1. . .21/25

OutlineJava is. . .Let’s get started!BasicsStreamsStreams are used for input and output. Three streams arepredefined in Java, inside the class is the “standard” input stream. Like stdin in C,it is connected to the keyboard. Its type is InputStream.ISystem.out is the “standard” output stream. Like stdout inC, it is connected to the screen. Its type is PrintStream.ISystem.err is the “standard” stream for error comments,connected to the screen. Like stderr in C, it is connected tothe screen. Its type is PrintStream. Output sent toSystem.err is mixed in with output sent to System.out.These streams are all static objects. They are opened for you andare ready to use when your program starts up.Java Programming -Week 1. . .22/25

OutlineJava is. . .Let’s get started!BasicsThe code inside main()Iprintln() is an output function that can send output to anyPrintStream, then print a newline.Iprint() is like println() except that it does not add a finalnewline character.IThe argument to println() or print() should be a stringor something that Java knows how to convert to a string.IIf you want to output a long string, break it onto two lines, asshown. The on line 21 is the concatenate operator. It tellsJava that the second part of the string should be glued to theend of the first one, not treated as a separate object.IA return statement is not necessary because main() is a voidfunction.Java Programming -Week 1. . .23/25

OutlineJava is. . .Let’s get started!Input and OutputMiles Per Hour: ScannerUse the Scanner class, from the java.util package, to do input.IThe stream is opened automatically when you runa program.IInstantiate a new Scanner to work on the stream your scanner to call one of the next functions:nextDouble(), nextInt(), nextLong(),nextBoolean(), nextLine(), and many others.Inext() reads the next whitespace-separated string.Use the Java API documentation to learn details and learn aboutmore possibilities.Java Programming -Week 1. . .24/25

OutlineJava is. . .Let’s get started!Input and OutputMiles Per Hour: Console OutputString output is easy in Java.IThe stream Standard.out is opened automatically when yourun a program.IUse printf() to print a formatted number.IUse print() to print a string and keep the cursor on thesame line.IUse println() to print a string ending in a newline.IIf your string has more then one part, write a between everypair of parts.IIf you try to print a non-string: System.out.print( 35 );Java will automatically call the toString() method.Java Programming -Week 1. . .25/25

JAR Javadoc Java Language jar Security Others Toolkits: FX Java 2D Sound . Java Programming -Week 1. 6/25. Outline Java is. Let’s get started! The JDK The Java Sandbox . into your namespace. java.lang contains the most basic classes in the Java language. It is imported automatically, so

Related Documents:

(prorated 13/week) week 1 & 2 156 week 3 130 week 4 117 week 5 104 week 6 91 week 7 78 week 8 65 week 9 52 week 10 39 week 11 26 week 12 13 17-WEEK SERIES* JOIN IN MEMBER PAYS (prorated 10.94/week) week 1 & 2 186.00 week 3 164.10 week 4 153.16 week 5 142.22 week 6 131.28 week 7 120.34

The Java Platform The Java platform has two components: The Java Virtual Machine (Java VM) The Java Application Programming Interface(Java API) The Java API is a large collection of ready-made software components that provide many useful capa

–‘java’ command launches Java runtime with Java bytecode An interpreter executes a program by processing each Java bytecode A just-in-time compiler generates native instructions for a target machine from Java bytecode of a hotspot method 9 Easy and High Performance GPU Programming for Java Programmers Java program (.

Week 3: Spotlight 21 Week 4 : Worksheet 22 Week 4: Spotlight 23 Week 5 : Worksheet 24 Week 5: Spotlight 25 Week 6 : Worksheet 26 Week 6: Spotlight 27 Week 7 : Worksheet 28 Week 7: Spotlight 29 Week 8 : Worksheet 30 Week 8: Spotlight 31 Week 9 : Worksheet 32 Week 9: Spotlight 33 Week 10 : Worksheet 34 Week 10: Spotlight 35 Week 11 : Worksheet 36 .

3. _ is a software that interprets Java bytecode. a. Java virtual machine b. Java compiler c. Java debugger d. Java API 4. Which of the following is true? a. Java uses only interpreter b. Java uses only compiler. c. Java uses both interpreter and compiler. d. None of the above. 5. A Java file with

besteht aus der Java-API (Java Application Programming Interface) und der Java-VM (Java Virtual Machine). Abbildung 1: Java-Plattform Die Java-API ist eine große Sammlung von Java-Programmen, die in sog. Pakete (packages) aufgeteilt sind. Pakete sind vergleichbar mit Bibliotheken in anderen Programmiersprachen und umfassen u.a.

CORE JAVA TRAINING COURSE CONTENT SECTION 1 : INTRODUCTION Introduction about Programming Language Paradigms Why Java? Flavors of Java. Java Designing Goal. Role of Java Programmer in Industry Features of Java Language. Installing Java Di

Topics such as object oriented programming, multithreading, Java I/O, and Data Access. Basic Java Programming Overview Target Audience Developers with no experience in java Prerequisites Delegates should have a working knowledge in programming language. Objectives ו Create basic java application ו Create java based applications using oop

Introduction to Functional Programming in Java 8 Java 8 is the current version of Java that was released in March, 2014. While there are many new features in Java 8, the core addition is functional programming with lambda expressions. In this section we describe the benefits of functional programming and give a few examples of the programming .

2 Java Applications on Oracle Database 2.1 Database Sessions Imposed on Java Applications 2-1 2.2 Execution Control of Java Applications 2-3 2.3 Java Code, Binaries, and Resources Storage 2-3 2.4 About Java Classes Loaded in the Database 2-4 2.5 Preparing Java Class Methods for Execution 2-5 2.5.1 Compiling Java Classes 2-6

Needed: Java Standard So far there has been no standard integration of Trusted Computing in Java. JSR321 is a Java Specification Request in the Java Community Process for a Trusted Computing API for the Java SE platform. It is aimed to develop a Trusted Computing API for Java providing selected functionality the TCG Software Stack

Java EE Java Platforms Java Card: Smart card version Java ME (Micro Edition): Embedded systems, e.g. Mobile handheld Java SE (Standard Edition): Desktop application development Java EE (Enterprise Edition): Enterprise distributed application software Java EE add standards and libraries to SE for fault- tolerant, distributed, multi-tier based components

We have designed this third edition of Java, Java, Java to be suitable for a typical Introduction to Computer Science (CS1) course or for a slightly more advanced Java as a Second Language course. This edition retains the “objects first” approach to programming and problem solving that was characteristic of the first two editions.

Java Platform, Enterprise Edition (Java EE) is the industry-standard platform for building enterprise-class applications coded in the Java programming language. Based on the solid foundation of Java Platform, Standard Edition (Java SE), Java EE adds libraries and system services that support the scalability, accessibility, security,

Reactive programming in Java Implementing inventory Summary 10. Finalizing Java Knowledge to a Professional Level Java deep technologies Java agent Polyglot programming Polyglot configuration Polyglot scripting Business DSL Problems with polyglot Annotation processing Programming in the en

28 Solving and Graphing Inequalities 29 Function and Arrow Notation 8th Week 9th Week DECEMBER REVIEW TEST WEEK 7,8 and 9 10th Week OCTOBER 2nd Week 3rd Week REVIEW TEST WEEK 1,2 and 3 4th Week 5th Week NOVEMBER 6th Week REVIEW TEST WEEK 4,5 and 6 7th Week IMP 10TH GRADE MATH SCOPE AND SEQUENCE 1st Week

Java Tutorial Java Tutorial or Core Java Tutorial or Java Programming Tutorial is a widely . An application that runs on the server side and creates dynamic page, is called web application. Currently, servlet, jsp, struts, jsf etc. technologies are used for creating web applications in java. 2/20/17 09:58:44 AM 11 .

Today Begin discussing Java Discuss how to run programs in Java Learn about Java syntax Take a closer look at data types in Java Goals of next 4-5 lectures: Understand the key similarities and differences between Python and other programming languages (Java) Review basic features of Python in preparation for final exam Gain confidence in our programming abilities

Java Archive file A Java Archive (JAR) file makes it possible to store multiple bytecode files in a single file. Java Bytecode – The instruction set of the Java virtual machine (JVM). Compiling Java source code results in a Java Bytecode that can be executed on any computer with an installed JVM.

7. What is the name of this sequence of events which results in the production of a protein? 8. What is Reverse Transcription? 9. When does Reverse Transcription occur? 10. How can Reverse Transcription be used in Biotechnology? DESIGNER GENES: PRACTICE –MOLECULAR-GENETIC GENETICS 2 CENTRAL DOGMA OF MOLECULAR GENETICS 1. Where is DNA housed in Eukaryotic Cells? most is stored in the nucleus .