Presentation is loading. Please wait.

Presentation is loading. Please wait.

GC101 Introduction to computer and program

Similar presentations


Presentation on theme: "GC101 Introduction to computer and program"— Presentation transcript:

1 GC101 Introduction to computer and program
Lecture3 Sara Alhajjam

2 Why Java? One of the most popular programming languages in use.
Java enables users to develop and deploy applications on the Internet for servers, desktop computers, and small hand-held devices. "write once, run anywhere": code that runs on one platform does not need to be recompiled to run on another. Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM).

3 Characteristics of Java
Java is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. was originally developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation). derives much of its syntax from C and C++.

4 Popular Java IDEs NetBeans https://netbeans.org/ Eclipse
JCreator

5 Processing a Java Program
A Java program undergoes several stages : 1. Editing: use Java code and save in a text file named className .java ( source program ). 2. Compiling: the compiler checks the source program for any syntax errors then translates the program into code understood by interpreter called bytecode saved in a file named className.class 3. Loading: the .class file is loaded into computer main memory for execution, and connected to all classes. 4. Verifying: to validate and secure against damage . 5. Interpreting: the Interpreter reads and translates each bytecode instruction into machine language and then executes it , one instruction at a time .

6 Processing a Java Program

7 Anatomy of a Java Program
Class name Main method Statements Statement terminator Reserved words Comments Blocks

8 Class Name Every Java program must have at least one class.
Each class has a name. By convention, class names start with an uppercase letter. In the following example, the class name is Welcome: //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); }

9 Main Method Line 2 defines the main method.
In order to run a class, the class must contain a method named main. The program is executed from the main method. //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); }

10 Statement A statement represents an action or a sequence of actions.
The statement System.out.println("Welcome to Java!") in the program is a statement to display the greeting "Welcome to Java! ". //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); }

11 Statement Terminator Every statement in Java ends with a semicolon (;). //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); }

12 Reserved words Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used for other purposes in the program. Example, when the compiler sees the word class, it understands that the word after class is the name for the class. //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); }

13 Blocks A pair of braces in a program forms a block that groups components of a program.

14 Special Symbols

15 Programming Errors Syntax Errors Runtime Errors Logic Errors
Detected by the compiler Runtime Errors Causes the program to abort Logic Errors Produces incorrect result

16 Syntax Errors public class ShowSyntaxErrors {
public static main(String[] args) { System.out.println("Welcome to Java); }

17 Runtime Errors public class ShowRuntimeErrors {
public static void main(String[] args) { System.out.println(1 / 0); }

18 Logic Errors public class ShowLogicErrors {
public static void main(String[] args) { for (i=1; i<=10; i++) ; {    System.out.println("Number is " + i);  } }

19 Java Identifiers They are names that we introduce in our program
public class Message { public static void main(String[] arg) System.out.println("This is a message"); } They are names that we introduce in our program The name of the class, variables, objects, and methods. Some are predefined; others are defined by the user. Consists of: Letters: (a  z) ( A  Z) Digits (0  9) The underscore character (_) Must begin with a letter, underscore, or the dollar sign. It cannot start with a digit. .

20 Java Identifiers Java identifiers can be any length.
An identifier cannot be a reserved word. An identifier cannot be true, false, or null. Names should be descriptive: • Message – the name of a program that prints out a message. • System.out.println – the name for a part of Java that prints a line of output to the screen.

21

22 Illegal Identifiers


Download ppt "GC101 Introduction to computer and program"

Similar presentations


Ads by Google