Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1: Java Fundamentals 1 (c) Gary R. Smith, MS.

Similar presentations


Presentation on theme: "Chapter 1: Java Fundamentals 1 (c) Gary R. Smith, MS."— Presentation transcript:

1 Chapter 1: Java Fundamentals 1 (c) Gary R. Smith, MS.

2  Know the history and philosophy of Java  Understand Java’s contribution to the Internet  Understand the importance of bytecode  Know the Java buzzwords  Understand the foundational principles of object-oriented programming  Create, compile, and run a simple Java program 2 (c) Gary R. Smith, MS.

3  Use the if and for control statements  Create blocks of code  Understand how statements are positioned, indented, and terminated  Know the Java keywords  Understand Java identifiers 3 (c) Gary R. Smith, MS.

4  Conceived by James Gosling, Patrick Naughton, Chris Warth, Ed Frank and Mike Sheridan at Sun Microsystems in 1991.  Originally designed as a platform-independent language to control embedded consumer electronic devices.  Based on C and C++ languages.  The advent of the Internet promoted the change from consumer electronics to the Internet programming. 4 (c) Gary R. Smith, MS.

5  Java’s syntax is inherited from C.  Java’s object model is adapted from C++.  Java was developed by programmers for programmers.  Java is not upwardly or downwardly compatible with C++.  Designed to solve a different set of problems.  C#’s syntax and structure are similar to Java.  C# was designed for a different computing platform. 5 (c) Gary R. Smith, MS.

6  Java Applets – special type of program that gets automatically executed by a Web browser.  Intended to be small programs.  Is downloaded upon demand.  Use to display data, handle input, and provide simple functions.  Executes locally rather than on a server. 6 (c) Gary R. Smith, MS.

7  Security – Applets are confined to the Java execution environment.  Cannot access other parts of the computer.  Reduces the likelihood of malicious code or breaches of security. 7 (c) Gary R. Smith, MS.

8  Portability  Java can run on a variety of different platforms using the same code called Bytecode.  Bytecode  Not executable code.  Is interpreted by the Java Virtual Machine run-time environment.  Highly optimized for the interpretive process. 8 (c) Gary R. Smith, MS.

9 SimpleHas a concise, cohesive set of features that makes it easy to learn and use. SecureProvides a secure means of creating Internet applications. PortablePrograms can execute in any environment for which there is a Java run- time system. Object-orientedEmbodies the modern, object-oriented programming philosophy. RobustEncourages error-free programming by being strictly typed and performing run-time checks. MultithreadedProvides integrated support for multithreaded programming. Architecture-neutralIs not tied to a specific machine or operating system architecture. InterpretedSupports cross-platform code through the use of Java bytecode. High performanceBytecode is highly optimized for speed of execution. DistributedDesigned with the distributed environment of the Internet. DynamicPrograms carry with them substantial amounts of run-time type information that is used to verify and resolved accesses of objects at run time. 9(c) Gary R. Smith, MS.

10  Object-Oriented Programming is a programming model that focuses on data and the code that manipulates that data.  Key Features:  Encapsulation – programming mechanism that binds together code and the data it manipulates.  Polymorphism – programming mechanism that allows a single interface to have many forms.  Inheritance – the process by which one object can acquire the properties of another object. 10 (c) Gary R. Smith, MS.

11  Class – Java’s basic unit of encapsulation.  Often referred to as a program.  May contain both data members (aka instance fields or instance variables) and code members (aka methods).  A class is the blueprint to construct an object. A class is not the object. Objects are instances of a class.  Data and methods can be private (known only within the class) or public (known to other classes). 11 (c) Gary R. Smith, MS.

12 // Program: AJavaProgram.java  Inline comment // Author: Gary R. Smith  Inline comment // Date Written: 8/16/2014  Inline comment /* This program displays a message  Block comment (multi-line) on the monitor */ (/* begins comment, */ ends comment) public class AJavaProgram  Class header (name of the class) {  Starts a block of code (class) // This is where the program starts and ends.  Inline comment public static void main(String args[])  Method header {  Starts a block of code (method) // Displays a message on the monitor  Inline comment System.out.println(“Java is fun!”);  Executable statement }  Ends a block of code (method) }  Ends a block of code (class) 12(c) Gary R. Smith, MS.

13  // (two slashes) indicates an inline comment.  Not compiled as part of the program  Provides in-program documentation  Comment goes to the end of the line  /* and */ indicates a block comment  Everything between /* and */ are comments  Not compiled as part of the program  Can be as long as you want.  Don’t be stingy on comments! 13 (c) Gary R. Smith, MS.

14  Class header (public class AJavaProgram) defines the name of the program.  Public is an access modifier that defines whether or not outside classes can access the class.  Must be the same name as the file name  public class AJavaProgram must have a file name of  AJavaProgram.java 14 (c) Gary R. Smith, MS.

15  Curly braces: { }  Denotes a block of code treated as a unit.  Encapsulates classes  Encapsulates methods  Encapsulates program elements supporting multiple statements. 15 (c) Gary R. Smith, MS.

16  Method header (public static void main(String args[]) defines a named block of code.  Public is an access modifier.  Static means the method belongs to the class itself and not an instance of the class.  Void (return type) means the method does not return any value.  main() is the name of the method which must include the parenthesis, which hold parameters.  String args[] is the parameter of the main() method.  Methods may have zero or any number of parameters. String args[] is a parameter of the main() method. 16 (c) Gary R. Smith, MS.

17  System.out.println(“Java is fun!”); is an executable statement.  System is a predefined class  out is an object of the System class  println() is a method of the System.out object  “Java is fun!” is a parameter that is passed to the println() method. Note it is String data.  The semicolon ‘;’ terminates an executable statement. 17 (c) Gary R. Smith, MS.

18  Syntax errors: violations of the language rules.  Caught by the compiler  Incorrect punctuation  Misspelled keywords and identifiers  Not specifying balanced (open and/or closing) parenthesis, curly braces, or square brackets. 18 (c) Gary R. Smith, MS.

19  Data types define:  How data is stored in memory  The minimum and maximum values a data item can hold  The amount of memory allocated for the data item.  Each data type is based on a class.  Java primitive data types are:  Integer types: byte, short, int, long  Floating point types: float, double  Boolean type: boolean  Character type: char 19 (c) Gary R. Smith, MS.

20  Field - An area of a database record, graphical user interface form, data item, or memory into which a particular item of data is stored.  Can be subdivided into two general categories:  Variables: Those data items which can be programmatically changed.  Constants: Those data items which cannot be programmatically changed.  A field is associated with a data type. (c) Gary R. Smith, MS. 20

21 abstractassertbooleanbreakbytecase catchcharclassconstcontinuedefault dodoubleelseenumextendsfinal finallyfloatforgotoifimplements importinstanceofintinterfacelongnative newpackageprivateprotectedpublicreturn shortstaticstrictfpsuperswitchsynchronized thisthrowthrowstransienttryvoid volatilewhile* true* false* null Keywords have special meaning to the Java compiler. These keywords cannot be used as names for variables, classes, or methods. * Although not keywords, true, false and null are also reserved words. 21(c) Gary R. Smith, MS.

22  Identifiers are names given to classes, objects, methods, variables, and other user-defined items.  Can start with any letter, the underscore character, or dollar sign.  May contain (after the first character) letters, numbers, the underscore character, or dollar sign  Cannot have any embedded spaces.  Are case sensitive. 22 (c) Gary R. Smith, MS.

23  Class identifiers  Begin each word with an upper case letter.  All other letter are lower case.  Example: AJavaProgram, Employee  Variable/object/method identifiers  Begin the first word with a lower case letter.  All other words begin with an upper case letter.  Use camel casing/Hungarian notation.  Example: employeeNumber, calculateInvoiceTotal  Note: This is a convention, not a language requirement. 23 (c) Gary R. Smith, MS.

24  Java contains hundreds of predefined classes stored in libraries.  System is a class library automatically included in every Java program.  You can create your own class libraries. 24 (c) Gary R. Smith, MS.

25 25 Java source programs end with a.java extension. Compiled Java programs end with a.class extension.

26 (c) Gary R. Smith, MS.26 Analyze the requirements Develop an algorithm Code the program Test the program Implement the program Maintain the program

27  Analyze the requirements  What is the expected result?  What data is needed to yield the expected result?  What actions are to take place  What output, if any, is to be produced?  Clarify calculations with the user.  What are the objects? (c) Gary R. Smith, MS. 27

28  Develop an algorithm (solution to the problem)  Pseudocode  Flowchart  IPO (Input/Process/Output) Diagram  Decision Trees  Truth Tables  Object Dictionaries  Develop testing criteria (c) Gary R. Smith, MS. 28

29  Code the program  What standards does the organization have?  Naming conventions  Program structure  Libraries  Internal documentation (c) Gary R. Smith, MS. 29

30  Test the program  Unit tests - testing a single method  Program tests – testing the operation of the program  System tests – testing to insure all programs work properly together  Acceptance tests – testing by the user to verify everything works as specified. (c) Gary R. Smith, MS. 30

31  Implement the program  File/data conversion  User/system documentation  Performance tuning  Types of implementations  Phased  Pilot  Parallel  Direct cut over (c) Gary R. Smith, MS. 31

32  Maintain the program  Changes to programs are inevitable.  Governmental regulations  Changes in business practices  Technological changes  Acquisitions and mergers  Follows the first 5 steps of the program development cycle. (c) Gary R. Smith, MS. 32

33  Tutorials:  http://docs.oracle.com/javase/tutorial/index.html http://docs.oracle.com/javase/tutorial/index.html  Java™ Platform, Standard Edition 8 API Specification  http://docs.oracle.com/javase/8/docs/api/index.h tml http://docs.oracle.com/javase/8/docs/api/index.h tml 33 (c) Gary R. Smith, MS.


Download ppt "Chapter 1: Java Fundamentals 1 (c) Gary R. Smith, MS."

Similar presentations


Ads by Google