Presentation is loading. Please wait.

Presentation is loading. Please wait.

INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?

Similar presentations


Presentation on theme: "INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?"— Presentation transcript:

1 INTRODUCTION TO JAVA PROGRAMMING Chapter 1

2 What is Computer Programming?

3 Computer Programming  is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs.  This source code is written in one or more programming languages.

4 Computer Programming  The purpose of programming is to create a set of instructions that computers use to perform specific operations or to exhibit desired behaviors.  The process of writing source code often requires expertise in many different subjects, including knowledge of the application domain, specialized algorithms and formal logic.

5 What is Programming Language?

6 Programming Language  is an artificial language designed to communicate instructions to a machine, particularly a computer.  can be used to create programs that control the behavior of a machine and/or to express algorithms precisely.

7 Examples of Programming Languages:  Delphi  C  C++  JAVA  Visual Basic etc.

8 What is Object- Oriented Programming Language?

9 Object-Oriented Programming Language  Is an extension of procedural programming.  It involves creating program components as objects that are similar to concrete objects in the real world that are manipulated to achieve a desired result.

10 Object-Oriented Programming Language  When writing object-oriented programs, it involves both creating objects and creating applications that use those objects.

11 Object-Oriented Programming Language  With this approach, data and the program(or procedure) can be packaged into a single unit called object.  Object- is an item that can contain both data, which are known as attributes or variables, and procedures, which contain activities that read or manipulate the data.

12 Object-Oriented Programming Language  Is a conceptual approach to designing programs.  Languages like C++ and JAVA have intrinsic features which apply this approach.

13 Principle of OOP  ENCAPSULATION  INHERITANCE  POLYMORPHISM

14 Encapsulation  Is a mechanism that binds together attributes and methods into a single object, and keeps both safe from interference or misuse, that is, the details of the object are encapsulated or hidden, from the user.

15 Encapsulation  It hides the details of the object, it sometimes called information hiding.

16 Inheritance  An object may be part of a large category of objects called class. Every object in a class shares similar methods and attributes as the original object. Each class can have one or more lower levels called subclasses.

17 Inheritance  Low levels inheriting methods and attributes of higher levels.  The higher-level class is called a superclass. Each subclass inherits the methods and attributes of the object in its superclass.

18 Polymorphism  Is a feature that allows one interface to be used for a general class of action, that is, the ability of an object to take many forms or identities.

19 Benefits of OOP  The ability to reuse the defined objects and modify existing objects.  Saves programming time  Adaptability- it is able to fit in different environment.  Reliability- it is able to operate correctly under all conditions

20 JAVA PROGRAMMING LANGUAGE

21  originally developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform.

22 JAVA PROGRAMMING LANGUAGE  Java was originally designed for interactive television, but it was too advanced for the digital cable television industry at the time.

23 JAVA PROGRAMMING LANGUAGE  The language was initially called Oak after an oak tree that stood outside Gosling's office; it went by the name Green later, and was later renamed Java, from Java coffee, said to be consumed in large quantities by the language's creators.OakoakJava coffee

24 Structure of a JAVA Program //import packages public class classname { //instance variables access specifier data type variablename1; access specifier data type variablename2; ………… //methods access specifier data type methodname1(parameter list) {//function body1 } access specifier data type methodname2(parameter list) {//function body 2 } …… }

25 The following is an example of a basic JAVA Application: public class First { public static void main(String[]args) { //this function outputs Hello World System.out.println(“Hello World”) }

26 Explanation:  Line 1: The keyword class defines a new class and First is the name of the class. public class First  Line 3: It defines a method called main().  public- this keyword is an access modifier, which allows the main() method to be accessed by codes outside this class. public static void main(String[]args)

27 Explanation:  static- This keyword allows the main() method to be access directly, without needing to create a particular instance of the class. This is necessary since the main() is called by the Java interpreter before any objects are made. public static void main(String[]args)

28 Explanation:  void- this keyword tells the compiler that the main() method does not return any value when it is called. The main() method produce outputs that does not send any value back to any other method that might use it. public static void main(String[]args)

29 Explanation:  String[]args- This represents an argument passed to the main() method. String- represents a Java class that can be used to represent character strings. Identifier args- is used to hold any Strings that might be sent to the main() method. The identifier need not be named args– it could be any legal Java identifier– but the name args is traditional.

30 Explanation:  Line 5: The ‘//’ double slash signs signals comment.  Line 6: This statement displays the string “Hello World” and position the cursor on the next line and stands ready for additional output.  System- a predefined class that provides access to the system  out- one of the System objects which represents the screen  println()- a method that displays the string which is passed to it on the screen.

31 Explanation:  Dots(periods) in the statement are used to separate the names of the class, object and the method  The entire class definition, including all its members, will be placed between’ { ‘ and ‘ } ‘. The use of ‘ { ‘ and ‘ } ‘ (curly parenthesis) can be used to separate program blocks.

32 Access Specifier  defines the circumstances under which a class or class member in programs can be accessed.  Public- can be accessed by any class  Private- can only be accessed by members of its own class  Default- similar to the public access level, where it is visible to all classes in the same package  Protected- can be access by all subclasses of this class in any package

33 PublicProtectedDefaultPrivate Same classYes Subclass in the same package Yes No Non subclass in the same package Yes No Subclass in a different package Yes No Non subclass in a different package YesNo


Download ppt "INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?"

Similar presentations


Ads by Google