Java Programming Concepts: OOP, Abstraction, Encapsulation, Inheritance

bca 504 java programming n.w
1 / 12
Embed
Share

Explore key Java programming concepts including Object-Oriented Programming, Abstraction, Encapsulation, and Inheritance. Learn about creating classes, objects, and utilizing polymorphism for effective programming. Dive into the structure of a simple program and grasp the fundamentals of Java.

  • Java Programming
  • OOP
  • Abstraction
  • Encapsulation
  • Inheritance

Uploaded on | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. BCA-504 JAVA PROGRAMMING MR. TRIVARNA ASST. PROFESSOR DEPARTMENT OF COMPUTER SCIENCE DR. B.B.HEDGE COLLEGE, KUNDAPURA

  2. OBJECT ORIENTED PROGRAMMING(OOP) Object-Oriented Programming is a paradigm that provides many concepts, such as class, object, abstraction, Encapsulation, polymorphism ,inheritance etc. Java Classes/Objects Class is a blueprint or template from which objects are created. Object is an instance of a class. Object is a real world entity such as pen, laptop, chair etc. Class is a group of similar objects. Create a Class Create a class named MyClass with variable x public class MyClass{ int x = 10; }

  3. Create an Object In Java, an object is created from a class. To create an object of MyClass, specify the class name, followed by the object name, and use the keyword new: Example: Create an object called myObj and print the value x public class MyClass{ int x = 10; public static void main(String[] args){ MyClass myObj = new MyClass(); System.out.println(myObj.x); } }

  4. Abstraction: Abstraction refers to the act of representing essential features without including the background details or explanations. Classes use the concept of abstraction and are defined as a list of abstract attributes such as size, weight and cost, and methods to operate on these attributes. Encapsulation: Encapsulation is a programming mechanism that binds together code and the data it manipulates, and that keeps both safe from outside interference and misuse. Ex: Student name, regno, DOJ, read(), write() Polymorphism: Polymorphism (from Greek, meaning many forms ) is the quality that allows one interface to access a general class of actions. The specific action is determined by the exact nature of the situation. Add() Add(int a.int b)

  5. Inheritance: Inheritance is the process by which one object can acquire the properties of another object. This is important because it supports the concept of hierarchical classification. Ex: classAnimal{ void eat(){ System.out.println( eating ); } } class Dog extendsAnimal{ void bark(){ System.out.println( barking ); } } class TestInheritance{ public static void main(String args[]){ Dog d = new Dog(); d.bark(); d.eat(); } } Types: 1)Single level 2)multi level 3) hierarchical

  6. STRUCTURE OF A SIMPLE PROGRAM /* This is a simple java program. Call this a SampleOne.java */ class SampleOne { //your program begins with call to main method public static void main (String args[ ]) { System.out.println( Hello World ); } } Class Declaration The first line class SampleOne declares a class, which is an object-oriented construct. Java is a true object- oriented language and therefore, everything must be placed inside a class. SampleOne is a Java identifier that specifies the name of the class to be defined.

  7. The main Line, The third line, public static void main (String args[ ]) Defines a method named main. Every Java application program must include the main( ) method. This is the starting point for the interpreter to begin the execution of the program. A Java application can have any number of classes but only one of them must include a main method to initiate the execution. public: The keyword public is an access specifier that declares the main method as unprotected and therefore making it accessible to all other classes. static: which declares this method as one that belongs to the entire class and not a part of any objects of the class. void: The type modifier void states that the main method does not return any value (but simply prints some text to the screen).

  8. Documentation Section: The documentation section comprises a set of comment lines giving the name of the program, the author and other details, which the programmer would like to refer to at a later stage. Comments must explain why and what of classes and how of algorithms. Java permits both the single- line comments and multi-line comments. The single-line comments begin with // and end at the end of the line. For longer comments, we can create long multi-line comments by starting with a /* and ending with */. Java also uses a third style of comment /** */ known as documentation comment. This form of comment is used for generating documentation automatically. Class Definitions: A Java program may contain multiple class definitions. Classes are the primary and essential elements of a Java program. These classes are used to map the objects of real-world problems. The number of classes used depends on the complexity of the problem. Main Method Class: Since every Java stand-alone program requires a main method as its starting point, this class is the essential part of a Java program.

  9. THE JAVA KEYWORDS Keywords are an essential part of a language definition. They implement specific features of the language. Java language has reserved 60 words as keywords. abstract boolean break case cast* catch const* continue default else extends false** float For future* if implements import int interface Long null** operator* outer* protected public rest*

  10. IDENTIFIERS IN JAVA Identifiers are programmer-designed tokens. They are used for naming classes, methods, variables, objects, labels, packages and interfaces in a program. Java identifiers follow the following rules: 1. They can have alphabets, digits, and the underscore and dollar sign characters. 2. They must not begin with a digit. 3. Uppercase and lowercase letters are distinct. 4. They can be of any length.

  11. Java developers have followed some naming conventions. 1. Names of all public methods and instance variables start with a leading lowercase letter. Examples: average, sum 2. When more than one word are used in a name, the second and subsequent words are marked with a leading uppercase letters. Examples: dayTemperature, firstDayOfMonth, totalMarks 3. All private and local variables use only lowercase letters combined with underscores. Examples: length, batch_strength 4. All classes and interfaces start with a leading uppercase letter (and each subsequent word with a leading uppercase letter). Examples: Student, HelloJava, Vehicle, MotorCycle 5. Variables that represent constant values use all uppercase letters and underscores between words. Examples: TOTAL F _MAX, PRINCIPAL_AMOUNT It should be remembered that all these are conventions and not rules Java Class Libraries The println( ) and print( ) methods are members of the System class, which is a class predefined by Java that is automatically included in your programs. The Java environment relies on several built-in class libraries that contain many built-in methods that provide support for such things as I/O, string handling, networking, and graphics.

  12. THANK YOU

More Related Content