1 / 14

The University of Akron Summit College

The University of Akron Summit College. 2440: 160 Java Programming Java Fundamentals Instructor: Enoch E. Damson. Basic Java Programming Tips. Java is case-sensitive All Java programs must be stored in a file with a .java extension Comments are ignored by the compiler

emil
Download Presentation

The University of Akron Summit College

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The University of AkronSummit College 2440: 160Java Programming Java Fundamentals Instructor: Enoch E. Damson

  2. Basic Java Programming Tips • Java is case-sensitive • All Java programs must be stored in a file with a .java extension • Comments are ignored by the compiler • A .java file may contain many classes, but may only have one public class Java Fundamentals

  3. Basic Java Programming Tips… • In a .java file with a public class, the class must have the same name as the file • Every Java application program must have a method named main • For every opening brace { or parenthesis (, there must be a corresponding closing brace { or parenthesis ) in Java • Java statements are terminated with semicolons (;), except comments, method headers, or braces Java Fundamentals

  4. The Java Application Programmer Interface (API) • A standard library of prewritten classes for performing specific operations such as standard input and output • The classes and their methods are available to all Java programs • Some classes/methods are available automatically in all Java programs • Other classes/methods have to be “imported” into Java programs Java Fundamentals

  5. Parts of a Java Application Program • Below is a simple Java application Java Fundamentals

  6. Parts of a Java Application Program… • The first line is a non-executable program comment • There are three comments used on Java and they include: • // Line commend • /* Paragraph comment */ • /** Javadoc generated paragraph comment */ Java Fundamentals

  7. Parts of a Java Application Program… • The second line defines a class named Hello • Everything used within a Java program must be part of a class • A class can be defined using any name or identifier as long as it satisfies the following criteria: • A class name must begin with a letter of the alphabet (Unicodes etc), an underscore, or a dollar sign • A class name can contain only letters, digits, underscores, or dollar signs • A class name cannot be a Java programming reserved word Java Fundamentals

  8. Parts of a Java Application Program… • In Java, standards are employed in the naming of classes to improve readability • This involves using uppercase letters to begin class names, and emphasizing each word put together as a class name with an uppercase letter • E.g., Employee, UnderGradStudent, InventoryItem, Year2000 • It is recommended that established naming conventions be used in order for other programmers to interpret and follow a program • Some valid, but unconventional class names include: • employee, Undergradstudent, Inventory_Item, YEAR2000 • The reserved word public in public class Hello is an access modifier that defines the circumstances under which a class can be accessed • public access is the most liberal type of access that allows other programs to access a class (also used to define methods, and data variables Java Fundamentals

  9. Parts of a Java Application Program… • Lines #3 and #8 indicate the beginning and ending scopes of the class • Contents of all classes are enclosed in curly brackets { } which can contain any number of data items and methods Java Fundamentals

  10. Parts of a Java Application Program… • Line #4 has the method header, public static void main (String[] args) • public – is the access modifier that allows public access to members of the HelloWorld class • static – is also a modifier that represents uniqueness (a class method) – only one main() method for the HelloWorld class will ever be stored in the computer memory • void – means the main() method returns no value when it is called • main() – all Java applications must have a main() method because that is the first method to be executed by a Java compiler, upon execution of an application • (String[] args) – is the argument passed to the main() method • String[] represents a Java class that can be used to represent a string of characters or array of string objects • args is the identifier used to hold any strings passed to the main() methods Java Fundamentals

  11. Parts of a Java Application Program… • Lines #5 and #7 indicate the beginning and ending scopes of the main() method • Contents of all methods are enclosed in curly brackets { } Java Fundamentals

  12. Parts of a Java Application Program… • Within the statement in line #6 has the statement: System.out.println(“Hello World”); • System – a class defining the attributes of a collection of similar System objects like out, in. and err • Within, System.out.println(“Hello World”);, • out – is an object that represents the screen and several methods like println( ) are available with the out object • println() – is a method in Java programming that prints a line of output on the screen, and positions the cursor on the next line, and stands ready to accept any additional input • print() also prints a line of output on the screen, but it positions the cursor on the same line as the output, after printing the message • Method names are usually referenced followed by their parenthesis in order to distinguish them from variable names Java Fundamentals

  13. Parts of a Java Application Program… • The dots (.) in the statement System.out.println(“Hello World”); are used to separate the names of the class, object, and method • The text “Hello World” is a literal string of characters that is meant to appear exactly as entered • Any literal string in Java programming appears between double quotation marks • The string “Hello World” appears within parenthesis because the string is an argument to a method (in this case the println() method) • Arguments consist of information that a method requires for performing its task Java Fundamentals

  14. Special Java Characters Java Fundamentals

More Related