DEV Community

Cover image for Introduction to Java
Madhav Ganesan
Madhav Ganesan

Posted on • Edited on • Originally published at madhavganesan.hashnode.dev

Introduction to Java

History

In June 1991, a small team of engineers at Sun Microsystems led by James Gosling (along with Mike Sheridan and Patrick Naughton) started a project called Green. This is to develop a programming language for small electronic devices such as television, setup-box etc.

In 1993, the HTTP protocol and Mosaic browser arrived which made them to develop the language for the internet.

In 1995, they developer a browser named Webrunner where it is capable of showing HTML content mixed with applets. Sun Microsystems officially announced Java at the SunWorld conference and Netscape agreed to include Java support in their popular Netscape Navigator browser.

In 2009, Sun Microsystems was bought by Oracle.It was initially named as 'OAK' after an oak tree that stood outside his office.Then, it was renamed to 'JAVA' as 'OAK' trademark was already used by Oak Technology.

James Gosling, Patrick Naughton, and Mike Sheridan

Paradigms:

Procedural Programming:

public class Procedural {
    public static void main(String[] args) {
        int sum = add(5, 3);
        System.out.println("Sum: " + sum);
    }

    public static int add(int a, int b) {
        return a + b;
    }
}
Enter fullscreen mode Exit fullscreen mode

Object Oriented Programming:

public class Animal {
    public void makeSound() {
        System.out.println("Animal makes a sound");
    }
}

public class Cat extends Animal {
    @Override
    public void makeSound() {
        System.out.println("Cat meows");
    }
}

public class Main {
    public static void main(String[] args) {
        Animal myAnimal = new Cat();
        myAnimal.makeSound();  // Outputs: Cat meows
    }
}

Enter fullscreen mode Exit fullscreen mode

Functional Programming

import java.util.Arrays;
import java.util.List;

public class FunctionalExample {
    public static void main(String[] args) {
        List<String> names = Arrays.asList("Alice", "Bob", "Charlie");
        names.forEach(name -> System.out.println(name));
    }
}
Enter fullscreen mode Exit fullscreen mode

Concurrent Programming

public class MyThread extends Thread {
    public void run() {
        for(int i = 0; i < 5; i++) {
            System.out.println(i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        MyThread t1 = new MyThread();
        t1.start();
    }
}
Enter fullscreen mode Exit fullscreen mode

Performance

Java is both a compiled and interpreted language. Java source code is compiled into bytecode by the Java compiler (javac), and this bytecode is executed by the Java Virtual Machine (JVM).Java source code is compiled into bytecode, which is platform-independent. This bytecode can run on any device equipped with a JVM, providing the "write once, run anywhere" (WORA) capability. JVM is platform dependent. The JVM uses Just-In-Time (JIT) compilation to convert bytecode into native machine code at runtime, which can lead to optimized performance. It compiles parts of the bytecode that have similar functionality at the same time, and hence reduces the amount of time needed for compilation.

How to run a java file?

1) Open notepad and type java code
2) Save the file in extension .java
3) Run the following commands:

java filename.java
Enter fullscreen mode Exit fullscreen mode

Type System:

Static Typing: Types are checked at compile-time, ensuring that type errors are caught early.

Strong Typing: Strict type rules are enforced, preventing type mismatches.

Static Type Checking: Ensures type correctness before execution, leading to more reliable code.

Abstraction

Only high level abstraction

Important Facts:

All member functions and variables of a class are private by default in nested classes, but for top-level classes, the default access modifier is package-private (no modifier).

Java supports automatic garbage collection, which helps manage memory allocation and deallocation, reducing the risk of memory leaks and other memory-related issues.

Java emphasizes write once, run anywhere (WORA), meaning compiled Java bytecode can run on any platform with a compatible JVM.

Usage

Enterprise Applications: Widely used in building large-scale enterprise applications with frameworks like Spring and Java EE.

Mobile Development: Primary language for Android app development

Web Applications: Utilized in web development with technologies like JavaServer Pages (JSP), Servlets, and frameworks like Spring MVC.

Desktop Applications: Used for developing cross-platform desktop applications with libraries like JavaFX and Swing.

Big Data: Integral part of big data technologies such as Apache Hadoop and Apache Spark.

Embedded Systems: Used in embedded systems development, though not as common as C/C++.

Top comments (3)

Collapse
 
citronbrick profile image
CitronBrick

Never heard that Java was initially named as Oak.
By the way, since Java 10, the java command both compiles & runs the class.

Collapse
 
phlash profile image
Phil Ashby

Wikipedia has your back 😁 en.wikipedia.org/wiki/Oak_(program...

Collapse
 
madgan95 profile image
Madhav Ganesan

Thanks for the info! I wasn't aware of this before..