DEV Community

Mane Khachatryan
Mane Khachatryan

Posted on

Java fundaments

Java is an Object-oriented programming language created by James Gosling in 1990. Java's syntax is derived from C and C++, making it familiar to those with a background in these languages. The language is designed to be readable and writable, promoting a clean and organized coding style. The basic structure of a Java program involves classes, methods, and statements, providing a foundation for building complex software. The Java Development Kit (JDK) is a cross-platform software development environment that offers a collection of tools and libraries necessary for developing Java-based software applications and applets. The JDK is the cornerstone of Java development, providing a comprehensive set of tools and libraries necessary for building Java applications. It encompasses everything a developer needs to write, compile, and debug Java code. It contains JVM, JRE, JAVAC, and many more. Compilation is a crucial step in the Java development cycle. JAVAC is the Java compiler that translates human-readable source code into bytecode, a low-level representation of the source code similar to machine code but not tied to any specific hardware. This bytecode is then executed by the JVM. The Java Virtual Machine is the runtime engine that executes Java bytecode. One of Java's key strengths is its platform independence, and the JVM plays a pivotal role in achieving this.

Image description

Java has two main categories of data type: primitive and non-primitive. Primitive types are boolean, char, int, short, byte, long, float, and double. A primitive data type specifies the size and type of variable values, and it has no additional methods. Unlike primitive data types, which store simple values, non-primitive data types store references to objects in memory, such as String, Array, objects, classes, and interfaces.
Image description

The main differences between primitive and non-primitive data types are:

  1. Primitive data types are already predefined. Non-primitive types are created by the programmer and are not defined by Java (except for String).
  2. Primitive data types start with lowercase letters, whilst non-primitive ones start with uppercase letters.
  3. Non-primitive types can be used to call methods to perform certain operations, while primitive types cannot.
  4. A primitive type always has a value, while non-primitive types can be null.

Java stands as a prominent representative of OOP principles. In Java, objects are instances of classes, and they encapsulate data and behavior. The properties of objects in Java refer to the characteristics or attributes that define the state of an object. These properties are typically represented by instance variables within a class. Objects are seen by the viewer or user, performing tasks assigned by you. Object-oriented programming aims to implement real-world entities like inheritance, abstraction, polymorphism, etc. In Java, methods are blocks of code that perform a specific task and can be called or invoked to execute that task. Methods are essential for code organization, reuse, and modular design. The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function. Objects communicate with one another by sending and receiving information to each other. A message for an object is a request for execution of a procedure and will invoke a function in the receiving object that generates the desired results. Message passing involves specifying the name of the object, the name of the function, and the information to be sent. In Java, a class is a user-defined data type that encapsulates attributes and methods. Objects are instances of a class representing a real-world entity with its unique state and behavior.
Image description

The four pillars of OOP are one of the main concepts in Java.

  1. Encapsulation involves bundling data (attributes) and methods that operate on the data into a single unit known as a class. Access to the internal details of the object is restricted, and interactions occur through well-defined interfaces. In Java, access modifiers like private, protected, and public facilitate encapsulation.

  2. Inheritance allows a class (subclass or child class) to inherit the properties and behaviors of another class (superclass or parent class). This promotes code reuse and establishes an "is-a" relationship between classes. Java supports single and multiple inheritance through classes and interfaces, enhancing code organization and extensibility.

  3. Polymorphism enables objects to take on multiple forms. In Java, polymorphism is achieved through method overloading and method overriding. Method overloading allows a class to have multiple methods with the same name but different parameters, while method overriding involves providing a specific implementation for a method defined in a superclass.

  4. Abstraction involves simplifying complex systems by modeling classes based on relevant characteristics and ignoring irrelevant details. In Java, abstraction is achieved through abstract classes and interfaces. Abstract classes can have abstract methods that are implemented by subclasses, while interfaces define a contract for classes to implement, promoting code flexibility and maintainability.

In conclusion, exploring Java reveals a language rooted in strong fundamentals and Object-Oriented Programming (OOP) principles.

Top comments (0)