Posts

Showing posts from March, 2023

Super Keyword

Image
  Super Keyword The super keyword is used to call the constructor of the super class from a sub class. The super keyword always calls the super class. All the methods and variables of the super class can be accessed from the sub class using the super keyword. Figure 1: Super keyword   Example As Figure 1 shows, the super keyword can be used to retrieve the output of all methods or only one method from the super class. When the super keyword is called to the constructor, the object is created for it and the corresponding output is executed.

Method Overriding

Image
Method Overriding Changing the body that inherits from a super class to a sub class happens in Method Overriding.  Only the method related to the created object is always executed.  When the object is created, the object inherits the same method from the superclass but gives a different output than the output given by inheritance. Figure 1: Method Overriding  Example As shown in Figure 1, object "M" is created for class "Man". Therefore, when the method called "climb" is called, only the method of the "Man" class will be executed. Therefore, the output is "using ladder". Method Overloading vs Method Overriding High school students are taught by teachers in a professional manner, but Kindergarten students are taught by teachers in a different way. Therefore, the same action "teach" will have different behaviors in different situations with different inputs. The same will happen in "Method Overloading". Simply put, a c

Inheritance

Image
  Inheritance Figure 1:  Inheritance example There is a company called "A". Some of the features and functions present in its older car models have been inherited by the new car models currently in the market. Both the car models are different but the new car model has some features and functions which are included in the old car model. Therefore, the new car model inherits the features and functions of the old car model. That is an example for inheritance. Inheriting things that belonged to one class to another class is called inheritance in Java.  The first class is called super class (parent) and the new class is called sub class (child). To inherit , there must be a relationship between the two classes. For that, Java uses the keyword "extends" with super class and sub class to make.   Also, a class can inherit many classes. Figure 2:  Inheritance Java example

Method Overloading

Image
Method Overloading Figure 1 : Method Overloading The concept of method overloading is used when creating the same method repeatedly in the same class. This can be done by changing the parameter, which is called the method signature. Figure 2 : Method Overloading Example Access Modifiers The security which is used to access classes, methods and variables, is called modifiers. there are 4 types of modifiers. Public Project, class in the project and other related classes can access. Protected Class, package and sub classes can access. Default Class and package can access. Private Only the class can access. Static Static is a keyword that cannot be changed but used as a modifier. Variables, methods, classes in a class can be accessed from anywhere in it using the "static" keyword. Figure 3 : static keyword Example

Parameters, Arguments & Constructors

Image
Parameters, Arguments & Constructors Generally Java program is executed line by line. Therefore, in order to run any code, if there are other codes required for that, they should be mentioned beforehand. Generally Java program is executed line by line. Therefore, in order to run any code, if there are other codes required for that, they should be mentioned beforehand. Also, there are 4 essential elements to run a Java code. They are,  Class Constructor Main method Object Figure 1:  Simple java code Parameters & Arguments A method requires 2 main elements. They are, return type and method name with a parameter list. The return type is used to return the output values and has 2 types. Void is Java's default return type. It can be used with any data type. String or any other data type can also be used as a return type with the "return" keyword. The "return" keyword is used to indicate that the return type of the code is a type. It can only return values of

Object Creation & Data Types

Image
Object Creation & Data Types Object Creation Only a class can be converted to an object. So to generate an object, a class must exist. in Java. The advantage of object creation is that many objects can be generated in relation to one class, so the process can be done using only one class. Figure 1 : Object Creation Figure 1 shows the code used for object creation.  "Code" is the class that the object belongs to and "java" is the variable name of the new object which is created in that class. "new" is the object generate keyword and by using the parameter list, the variable assignment or storing the new object is done. Primitive Data Types Formats that are used to store data are called Data Types. There are 3 main Data Types. integer float (decimals) binary (1/0, true/false) In Java, there are 8 main Primitive Data Types. They are, byte char short int long float double boolean Out of these 8 primitive data types, byte, char, short, int and long are inte

Java Standards, Class & Object

Image
Java Standards, Class & Object Java is a popular programming language widely used for application development. One of the key features of Java is its support for templates, the powerful mechanism for creating objects through its class system. Objects are created from classes, which are like blueprints that define the properties and behavior of objects. Overall, Java's support for standards and its class system make it a powerful and versatile language for building a wide range of applications. Standards Class, variable, method can be mentioned as the parts that can be seen mainly in a java code. They have unique characteristics that make them easily recognizable in Java code. The first letter to start a class is always uppercase. The first letter initializing a variable is always lowercase. The first letter starting a method is always lowercase, and parentheses must be used at the end. Figure 1 :   Example According to the simple code shown in Figure 1,  class - Code, String va