What Is Core Java?
The term “Core Java” simply refers to the basic, essential parts of the Java programming language. Java itself is widely used and well-known among programmers. When someone starts learning Java, they typically begin with Core Java before moving on to more advanced topics. Java is a versatile programming language based on the concept of Object-Oriented Programming (OOP).Â
It is platform-independent, meaning code written in Java can run on different types of devices without any need to be changed. This can be defined better by the principle of “Write Once, Run Anywhere” (WORA). Java is designed to be straightforward and easy to grasp.Â
It’s important to note that Core Java is not a separate version of Java; it’s just the starting point for learning Java programming. Java has various editions, and Core Java is one part of those editions, which basically focuses on the foundational concepts of the language.
Java EditionsÂ
Before moving further to the fundamentals and other concepts related to core Java, let us first understand the basic editions supported by Java programming language.
Java SE (Standard Edition):
- This edition is also known as Core Java.
- It includes the foundational elements of the Java language such as basic syntax, data types, control structures, object-oriented programming concepts, and core libraries (like java.lang, java.util, etc.).
- Java SE is suitable for developing desktop applications, command-line tools, and small-scale applications.
- It is considered as a foundation of all other Editions.
Java EE (Enterprise Edition):
- Java EE is focused on developing enterprise-level applications.
- It includes additional APIs and libraries for building web applications, distributed systems, and enterprise solutions.
- Java EE provides features like Servlets, JSP (JavaServer Pages), EJB (Enterprise JavaBeans), JMS (Java Message Service), and JPA (Java Persistence API) for database interaction.
- It also offers support for XML processing, web services, and application servers.
Java ME (Micro Edition):
- Java ME is designed for developing applications for resource-constrained devices such as mobile phones, embedded systems, and IoT (Internet of Things) devices.
- It provides a smaller footprint of the Java platform tailored for devices with limited memory, processing power, and screen size.
- Java ME includes profiles like MIDP (Mobile Information Device Profile) and CLDC (Connected Limited Device Configuration) for mobile and embedded development.
Concepts Covered In Core Java
The following concepts are some of the major basic concepts of Core Java, which every beginner should know before moving to advanced Java. we will be discussing each of the concepts in detail for your better clarity and understanding.
- Java Fundamentals
- OOPs Concepts
- Overloading & Overriding
- Inheritance with Interface and Abstract Class
- Exception Handling
- Packages
- Collections
- Multithreading
Java Fundamentals
The fundamentals below are some of the basic building blocks of Java programming. By understanding these concepts, you can start creating Java programs to solve different problems and build various applications.
- Variables: Variables are like containers that hold information. They can store numbers, text, or other types of data that your program needs to work with.
- Data Types: Java has different types of data, such as numbers, text, true/false values, etc.
Here are the main ones along with their functions:
- int: Used to store whole numbers (positive or negative) without decimal points. Example: 5, -10, 1000.
- double: Used to store numbers with decimal points. Example: 3.14, -0.001, 10.5.
- Boolean: Used to store true/false values.
- char: Used to store a single character. Example: ‘A’, ‘b’, ‘Z’.
- byte: Used to store small integer values. It has a range from -128 to 127.
- Short: Similar to byte but with a larger range, from -32,768 to 32,767.
- Long: Â Used to store large integer values. It has a wider range compared to int. Example: 1000000.
- Float:Â Similar to double but with a smaller range and precision. Example: 3.14159.
- Operators: You can use operators like + for addition, – for subtraction, * for multiplication, / for division, and others to perform calculations and manipulate data.
- Control Structures: These are like decision-making tools for your program. For example, you can use else-if statements to make decisions based on certain conditions.
- Loops: Loops help you repeat actions in your program. A loop can run a set of instructions multiple times until a condition is met.
- Functions: Functions are like mini-programs within your main program. They perform specific tasks and can be reused multiple times.
- Arrays: Arrays are collections of similar items. For instance, you can have an array of numbers or an array of names. Arrays help manage and work with groups of data efficiently.
Let us understand all these terms more clearly by implementing them in a code.
public class BasicJavaExample {
    public static void main(String[] args) {         // Variables and Data Types         int number1 = 10;         double number2 = 3.5;         boolean isJavaFun = true;         char grade = ‘A’;         // Operators         double result = number1 + number2;         int quotient = number1 / 3;         // Control Structures         if (isJavaFun) {             System.out.println(“Java is fun!”);         } else {             System.out.println(“Java is not fun!”);         }         // Loops           for (int i = 0; i < 5; i++) {             System.out.println(“Loop iteration: ” + i);         }         // Functions (Methods)         int squareResult = calculateSquare(number1);         System.out.println(“Square of ” + number1 + ” is ” + squareResult);        // Arrays         int[] numbersArray = {1, 2, 3, 4, 5};         System.out.println(“Array length: ” + numbersArray.length);     }       }          } |
OOPs Concepts
Now we will understand some basic OOPs concepts in brief which will help you to understand the basics of Core Java, Learning OOPs concepts will not only help you with Java but also in many other programming languages like Python, C#, C++, etc.Â
- Object: An object is a real-world entity that has attributes and behavior. For example, a car object may have attributes like color, model, and speed, along with behaviors like accelerating and braking.
- Class: A class is a blueprint or template for creating objects. It defines the attributes and behaviors that objects of that class will have. Using the car example, a Car class would define attributes like color and model, along with methods like accelerate() and brake().
- Inheritance: Inheritance is a concept where a new class can inherit properties and behaviors from an existing class. It promotes code reusability and helps save developers time and effort. For instance, a SportsCar class can inherit from the Car class and gain its attributes and behavior.
- Polymorphism: Polymorphism allows objects to take on multiple forms or behave differently based on the context. It can be achieved through method overriding (where a subclass provides a specific implementation of a method defined in the superclass) and method overloading (where multiple methods have the same name but different parameters).
- Abstraction: Abstraction is the process of hiding complex implementation details and exposing only essential features to the user. It helps in managing complexity and focusing on the essential aspects of an object or class.
- Encapsulation: Encapsulation involves bundling attributes and behaviors together within a class and restricting access to certain components. It helps in data hiding and maintaining the integrity of objects.
Method Overloading
Method overloading in Java means having multiple methods with the same name but different parameters. This is useful because it makes the program easier to read.
For example, let’s say you want to add numbers together, but sometimes you might have two numbers to add, and other times you might have three or more. Instead of naming each method differently, you can use method overloading. This way, you can have a method called “add” that works for any number of arguments.
The advantage of method overloading is that it improves the readability of your program because you can use the same method name for similar operations with different parameters.
In Java, there are two main ways to overload a method:
- By changing the number of arguments (like having add(int a, int b) for two numbers and add(int a, int b, int c) for three numbers).
public class MathOperations {
   // Method to add two numbers     public int add(int a, int b) {         return a + b;     }     // Overloaded method to add three numbers     public int add(int a, int b, int c) {         return a + b + c;     }     public static void main(String[] args) {         MathOperations math = new MathOperations();        // Calling the add method with two arguments         int sum2Numbers = math.add(5, 10);         System.out.println(“Sum of two numbers: ” + sum2Numbers);        // Calling the add method with three arguments         int sum3Numbers = math.add(5, 10, 15);         System.out.println(“Sum of three numbers: ” + sum3Numbers);     } } |
- By changing the data type of the arguments (like having add(int a, int b) for integers and add(double a, double b) for decimals).
public class MathOperations {
    // Method to add two integers     public int add(int a, int b) {         return a + b;     }     // Overloaded method to add two doubles     public double add(double a, double b) {         return a + b;     }     public static void main(String[] args) {         MathOperations math = new MathOperations();         // Calling the add method with two integers     int sumIntegers = math.add(5, 10);         System.out.println(“Sum of two integers: ” + sumIntegers);        // Calling the add method with two doubles         double sumDoubles = math.add(3.5, 2.5);         System.out.println(“Sum of two doubles: ” + sumDoubles);     } } |
Method Overriding
Imagine you have a class called “Animal” with a behavior called “makeSound.” Now, you create a subclass called “Dog” that inherits from “Animal.” If you want the “Dog” class to have its own behavior of “makeSound” (maybe dogs bark differently from other animals), you can override the “makeSound” method in the “Dog” class.
So, method overriding allows you to provide a specific implementation of a method in a subclass that’s different from the method’s implementation in the superclass. This way, you can customize behavior for specific types of objects while still benefiting from the common features provided by the superclass.
Rules For Method Overriding
- The method should have the same name as in the parent class.
- The method should have the same parameter as in the parent class.
Exception Handling
What is an Exception?
An exception is an event that disturbs the normal flow of a program. It can occur due to various reasons, such as invalid input, file not found, network issues, or arithmetic errors.
Why Handle Exceptions?
When an exception occurs, it can cause the program to crash or behave unexpectedly. Exception handling helps in managing these errors, preventing the program from crashing and allowing you to handle the error situation appropriately.
How Exception Handling Works in Java?
Java provides a mechanism for handling exceptions using try-catch blocks. Here’s how it works:
- Try Block: You place the code that is causing a disturbance to the program inside a try block. If an exception occurs within the try block, the control jumps to the catch block.
- Catch Block: The catch block is used to handle the exception. You specify the type of exception that you want to catch in the catch block. If that type of exception occurs in the try block, the corresponding catch block is executed.
Multithreading
Multithreading in Java allows multiple threads to run simultaneously within a program. Threads are lightweight sub-processes, each capable of executing its own tasks independently. Compared to multiprocessing, where each process has its own memory space, threads share memory, making them more memory-efficient and quicker to switch between.
Java Multithreading is commonly used in applications like games and animations, where multiple tasks need to be performed simultaneously without blocking the user. Some advantages of Java Multithreading include:
1) Non-blocking: Threads operate independently, allowing multiple operations to run concurrently without blocking the user or other threads.
2) Time-saving: Concurrent operations save time by executing multiple tasks simultaneously.
3) Fault tolerance: If an exception occurs in one thread, it doesn’t affect other threads, ensuring fault tolerance and stability.
Multitasking, which involves executing multiple tasks simultaneously, can be achieved in two ways:
1) Process-based Multitasking (Multiprocessing): Involves running multiple processes concurrently, each with its own memory space. This method is more resource-intensive but provides better isolation between processes.
2) Thread-based Multitasking (Multithreading): Involves running multiple threads within a single process, sharing memory space. This method is more memory-efficient and faster for context-switching between tasks.
Core Java vs Advanced Java
      Core Java |         Advanced Java |
Core Java generally covers the basic concepts related to Java Programming Language. | Advanced Java covers the advanced concepts and topics of Java programming language. |
Core Java is used for Developing computing and desktop applications. | It is used for developing enterprise applications. |
Core Java is considered the first step to begin Java. | It is to be considered after completing Core Java. |
Core Java comes under Java Standard Edition. | Advanced Java comes under Java Enterprise Edition and J2EE. |
Core Java covers topics like- OOPs, Overloading, Overriding, Exception handling, and multiple inheritance. | It covers topics like- Servlets, JSP, Web services, etc. |
Learn Java with PW Skills
Embark on an exciting journey to master Java with PW Skills! Our self-paced comprehensive Java with DSA course offers a dynamic learning experience, allowing you to learn Java at your own pace, from basic concepts to advanced programming techniques. What makes our course unique is our working on real-world projects to gain in-depth knowledge of Java and guidance in building job-ready portfolios that showcase your expertise to potential employers.Â
Moreover, we understand the importance of soft skills in today’s competitive job market, so our course includes modules dedicated to enhancing your communication, problem-solving, and teamwork abilities.Â
Get ready to unlock your potential and shape a successful career in Java with PW Skills!
Core Java FAQs
What is Core Java?
Core Java refers to the fundamental parts of the Java programming language, covering basic concepts like data types, variables, control structures, and object-oriented programming principles.
What is the difference between Core Java and Advanced Java?
Core Java covers the basics of the language which are necessary for beginners, while Advanced Java dives into more specialized topics like web development (Servlets, JSP), database connectivity, and enterprise-level programming.
Is Core Java suitable for beginners?
Yes, Core Java is beginner-friendly and serves as a starting point for learning Java programming. It introduces essential concepts and principles that are applicable across various Java applications.