Vinod Sebastian – B.Tech, M.Com, PGCBM, PGCPM, PGDBIO

Hi I'm a Web Architect by Profession and an Artist by nature. I love empowering People, aligning to Processes and delivering Projects.

Tag: Java

Java

  • Notes

    Java Programming Notes

    Identifiers and Class Members

    • Identifiers in Java must start with a letter, a currency character ($), or an underscore (_).
    • Class members are initialized with default values of binary 0s for primitive types and null for objects.

    Modifiers in Java

    • Default: Scope limited to the same package.
    • Public: Scope visible everywhere.
    • Protected: Scope within the package and all subclasses.
    • Private: Scope limited to the class.


    Static modifiers are used to create class variables and methods that can be accessed without an instance of the class. The static keyword is also used for static blocks to initialize static data members. These blocks execute before the main() method.


    Synchronized is used to ensure that a method can only be accessed by one thread at a time, which is crucial in multithreading scenarios.

    Interfaces and Polymorphism

    • Interfaces can be implemented by a class or extended by another interface, while classes can only be extended.
    • Polymorphism can be achieved through overloading or overriding methods.

    Constructor and Static Methods

    • Constructors should always have a call to super or this. If a constructor is provided in the base class, a call to super must be included in the derived class constructor.
    • Static methods are called by class name, while instance methods are called by objects.

    Nested Classes in Java


    Nested classes in Java can be divided into inner classes and static nested classes. Inner classes have an association with an instance of their enclosing top-level class, while static nested classes exist independently. Anonymous inner classes are useful for on-the-fly object creation without defining a separate top-level class.

    String Handling and Serialization

    • Strings in Java are immutable, and StringBuffer is used for thread safety while StringBuilder is faster for string concatenation.
    • Serialization in Java stores objects in a serialized form, excluding transient and static variables. Serialization involves methods like readObject and writeObject.

    Exception Handling and Threads

    • Exceptions in Java are categorized into unchecked exceptions (subclass of RuntimeException) and checked exceptions. Errors are at the same level as unchecked exceptions.
    • Threads can be created by inheriting from the Thread class or implementing the Runnable interface. Various thread operations like wait, notify, yield, and sleep are used for synchronization.

    Comparator and Comparable Interfaces

    • The Comparator interface is used for custom sorting logic, while the Comparable interface provides default sorting behavior.
    • Both interfaces offer methods for comparing objects based on specific criteria.

    Importing Classes and JAR Files

    • Normal import declarations import classes from packages, while static import declarations import static members from classes for direct usage.
    • JAR files are checked in specific locations to resolve classpath dependencies.

    Additional Concepts

    • Garbage collection in Java handles memory management by removing unreferenced objects in a non-deterministic manner.
    • Assertions are used to validate invariants in the code by triggering an AssertionException if the condition is false.

    Overview of Java Collections

    • Java provides various collection types like Lists, Sets, Maps, and Queues for storing and manipulating data.
    • Features like ordering, sorting, and thread safety are inherent properties of specific collection types like Linked, Tree, and Vector.

    Conclusion

    Java programming encompasses a wide range of concepts and features that are essential for developing robust and efficient applications. By understanding the core principles discussed in these notes, developers can enhance their skills in Java programming and build scalable and reliable software solutions.