Java Programming Notes
1. Introduction to Java
Java is a high-level, class-based, object-oriented programming language that is designed to have as few
implementation dependencies as possible.
Example:
public class HelloWorld {
public static void main(String[] args) {
[Link]("Hello, World!");
2. Data Types and Variables
Java supports several data types like int, float, double, char, boolean, etc.
Example:
int age = 25;
double salary = 50000.50;
boolean isEmployed = true;
3. Control Statements
Java has control statements like if, if-else, switch, for, while, and do-while.
Example:
int number = 10;
Java Programming Notes
if(number > 0) {
[Link]("Positive number");
4. Object-Oriented Programming
Java supports OOP concepts: Class, Object, Inheritance, Polymorphism, Encapsulation, and Abstraction.
Example:
class Animal {
void sound() {
[Link]("Animal sound");
class Dog extends Animal {
void sound() {
[Link]("Bark");
5. Arrays and Strings
Arrays store multiple values in a single variable.
Strings are objects that represent sequences of characters.
Example:
Java Programming Notes
int[] nums = {1, 2, 3};
String name = "Java";
6. Exception Handling
Exception handling in Java is managed via try, catch, throw, throws, and finally.
Example:
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
[Link]("Cannot divide by zero");
7. File Handling
Java provides [Link] and [Link] packages for file operations.
Example:
FileWriter writer = new FileWriter("[Link]");
[Link]("Hello File");
[Link]();
8. Collections Framework
Java Collections include List, Set, Map, etc.
Java Programming Notes
Example:
List<String> list = new ArrayList<>();
[Link]("Apple");
[Link]("Banana");
9. Multithreading
Java supports multithreading using the Thread class or Runnable interface.
Example:
class MyThread extends Thread {
public void run() {
[Link]("Thread running");
10. Java 8 Features
Java 8 introduced features like Lambda expressions, Stream API, Functional interfaces.
Example:
List<String> names = [Link]("John", "Jane", "Jack");
[Link](name -> [Link](name));