The length field of an array returns the size of the array
Object-oriented
Built on the foundation laid by structured programming concepts
Components of a method
Access Modifier
Return type
Method Name
Parameter list
Exception list
Method body
Access Modifiers in Java
Default
Private
Protected
Public
Constructor in Java
A special method used to initialize objects
Types Of Constructor
Default Constructor
Parameterized Constructor - it accepts a specific number of parameters
this keyword in Java
Represents the current instance of a class
Java package
A group of similar types of classes, interfaces, and sub-packages
Advantages of Java Package
Java package is used to categorize the classes and interfaces so that they can be easily maintained
Java package provide access protection
Java package removes naming collision
Built-in Packages
java.lang: contains language support classes
Java.io: contains classes for supporting input/output operations
Java.util: contains utility classes which implement data structures like linked list, dictionary and support for date/time operations
java.applet: contains classes for creating Applets
java.awt: contain classes for implementing the components for graphical user interface
java.net: contains classes for supporting networking operations
Static import
Feature introduced in Java programming language that allows members (files and methods) defined in a class as public static to be used in java code without specifying the class in which the field is defined
Encapsulation
Defined as the wrapping up of data under a single unit
Advantages of Encapsulation
Data hiding
Increased flexibility reusability
Testing code is easy
Get and Set
The get method returns the value of the variable name
The set method takes a parameter (newName) and assigns it to the name variable. This keyword is used to refer to the current object. However, as the name variable is declared as private, we cannot access it from outside this class
Java Inheritance
Means creating new classes based on existing ones. A class that inherits from another class can reuse the methods and fields of that class
Types of Inheritance
Single Inheritance: subclasses inherit the features of one superclass
Multilevel Inheritance: a class is extended to another class and extended to another class
Hierarchical Inheritance: in which the same class is inherited by more than one class