1 / 43

Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java Training | Edureka

This Edureka 'Java Classes' tutorial will take you through in-depth details of Java classes and different key-components in Java. It is ideal for both beginners and professionals who want to learn or brush up the basics of Java. Below are the topics covered in this tutorial: <br><br>1. Classes in Java <br>2. Constructors <br>3. Structure of a Class <br>4. Overview of Objects <br>5. Working with Objects <br>6. Multiple classes <br>7. OOPS concepts: Inheritance, Encapsulation, Abstraction, Interface

EdurekaIN
Download Presentation

Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java Training | Edureka

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. ` EDUREKA JAVA CERTIFICATION TRAINING What is Hadoop? https://www.edureka.co/java-j2ee-soa-training

  2. Agenda For Today ➢ What is a Class? ➢ Constructors ➢ Structure of a Class ➢ Overview of objects ` ➢ Working with objects ➢ Using Multiple classes ➢ OOPS concepts EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  3. What is a Class? ` EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  4. What is a Class?  A class in java is a blueprint which includes all the data.  It describes the state and behavior of a specific object. Classes Syntax : Example : ` Class name Public class car { Car Color Model Price speedUp(); gearChange(); } Variables Methods EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  5. Member Variables Member variables Member variables are used to store a data value Types ` Local variable Instance variable Class variable EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  6. Types of Variables Local variable Instance variable Class variable ` Instance variable are declared in a class but outside a method, constructor or any block Class / static variable has only one copy that is shared by all the different objects of a class Local variables are declared within the method of a class EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  7. Methods  Describes the behavior of an object.  Collection of statements that are grouped together to perform an operation. Methods ` Name of the method Example : Functionality EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  8. Constructors ` EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  9. Constructors  Block of code used to initialize an object  Must have same name of the class  No return type  Automatically called when an object is created Constructors ` Type of Constructors Parameterized Constructor Default Constructor EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  10. Types of Constructors Default Parameterized ➢ No argument ➢ Accept arguments ➢ Compiler provides default value, automatically created ➢ Provides different value to objects ` Example : Example : EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  11. Access Modifiers ` EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  12. Access Modifiers Public Private Class, methods, variables and constructors can be accessed from any other class. Methods, variables and constructors can only be accessed within the declared class. ` Access Modifiers Protected Default Methods, variables and constructors are declared protected in a superclass can be accessed only by the subclasses. No modifier required. Access class, variables, method in same package but not from outside. EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  13. Access Modifiers Access Modifiers Same Class Same Package Sub Class Other Packages Public Y Y Y Y ` Private Y N N N Protected Y Y Y N Default Y Y N N EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  14. Structure of Classes ` EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  15. Structure of Classes Name of the Class Member variables ` Constructor Method EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  16. Overview of Objects ` EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  17. Overview of Objects  It is an entity that has state and behavior  Instance of a class which can access data Objects ` Class - Car (Blueprint ) ➢ States of a Car : Color - Orange Model - 1 Price - 50000 ➢ Behavior of Car : Speed up Change gear EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  18. Working with Objects ` EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  19. Working with Objects How can you create an object? ` Declaration Initialization Instantiation Call to a constructor, initializes new object Variable name with a data type “New” keyword creates an object EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  20. Working with Objects  Objects to a class is created by using the keyword “new”.  New allocates memory for the object. Syntax : Class Name Keyword ` Student student1 = new Student(); Object Name Constructor EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  21. Working with Objects Store data into object using a constructor Constructor ` Stores data into objects by invoking a method. Method Initialize an object? Stores data into object through reference variable Reference variable EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  22. Working with Multiple Classes ` EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  23. Working with Multiple Classes Output : Constructor of Class A Method of class A ` Constructor of class B Method of class B EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  24. OOPS Concepts ` EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  25. Inheritance  One class acquire properties (methods & fields) of another  Class which inherits the properties – Child class/ derived class/ sub class  Class whose properties are inherited – Parent class/ base class Inheritance ` EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  26. Types of Inheritance Inheritance ` Single Multilevel Hierarchical Hybrid EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  27. Inheritance Single Class B inherits the properties of A Single Syntax: Multilevel ` Class A { ---- } Public class B extends A { ---- ---- } Hierarchical Parent Class Class A Hybrid Child class of A Class B EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  28. Inheritance Class B inherits the properties of A and Class B inherits the properties of B Multilevel Single Syntax: Multilevel ` Class A { ---- } public class B extends A { --- } Public class C extends B { --- } Parent class of B Class A Hierarchical Hybrid Parent class of C Child class of A Class B Child class of B Class C EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  29. Inheritance Hierarchical One class is inherited by many subclasses Single Syntax: Multilevel ` Class A { ---- } public class B extends A { ---- } Public class C extends A { ---- } Hierarchical Parent Class Class A Hybrid Class B Class C Child Classes EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  30. Inheritance  Single + Multiple inheritance  It can only be achieved through Interface. Hybrid Single Multilevel Parent class for class B and class C Class A ` Hierarchical Parent class for class D, Child class of class A Hybrid Class B Class C Class D EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  31. Encapsulation ` EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  32. Encapsulation  Binding the data and code together as a single unit.  Securing data by hiding the implementation details to user. Encapsulation ` Class Methods Variable EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  33. Encapsulation Getter and setter methods ` Output : ABC EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  34. Abstraction ` EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  35. Abstraction  Hides the implementation details and only provides the functionality to the user  You can achieve abstraction using Abstract classes and Interfaces Abstraction Without Abstraction With Abstraction ` EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  36. Abstract Class  Class contains the abstract keyword  If a class is declared abstract, it cannot be instantiated Abstract class Syntax : abstract class <class-name> { } ` How can you use an abstract class? Inherit it from another class and provide implementations to the abstract methods in it. 1 2 If a class has one abstract method, then the class must be declared abstract. EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  37. Interface ` EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  38. Interfaces  Interface in java is a blueprint of a class.  Each method in an interface are implicitly public and abstract.  It does not contain any constructors. Interfaces Example : ` interface Car { void changeGear (int newValue); void speedup (int increment); void applyBrakes (int decrement); } EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  39. Interfaces To implement an interface? class Audi implements Car { int speed = 0; int gear = 1; void changeGear(int newValue) { gear = newValue; } void speedUp(int increment) { speed = speed + increment; } void applyBrakes(int decrement) { speed = speed - decrement; } void printStates() { System.out.println(" speed:" + speed + " gear:" + gear); } } ` EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  40. Summary ` EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

  41. Session In A Minute Constructors Java Classes Access Modifiers ` Structure of a Class Overview of Objects OOPS Concepts EDUREKA JAVA CERTIFICATION TRAINING https://www.edureka.co/java-j2ee-soa-training

More Related