Language-Java

Java is an object-oriented programming language with its runtime environment. It is a combination of features of C and C++ with some essential additional concepts. Java is well suited for both standalone and web application development and is designed to provide solutions to most of the problems faced by users of the internet era.

What is Java?

  1. An object-oriented programming language
  2. Java is a set of features of C & C++. It has obtained its format from C, and OOP features from C++.
  3. Java code that runs on one platform does not need to be recomplied to run on another platform; it’s called write once, run anywhere.
  4. Java Virtual Machine(JVM) executes java code, but it has been written in platform-specific languages such as C/C++/ASM. JVM is not written in Java and hence cannot be platform independent, and Java interpreter is a part of JVM.

Where is Java being used?

  1. JSP: Java Server Pages is used to create dynamic web pages, such as in PHP and ASP.
  2. Applets: Applets are another type of Java programs that are implemented on Internet browsers and are always run as part of a web document.
  3. J2EE: It is a platform-independent environment that is a set of different protocols and APIs and is used by various organizations to transfer data between each other. 4. JavaBeans: This is a set of reusable software components that can be easily used to create new and advanced applications.
  4. Mobile: Many types of games and applications are being made in Java.

Types of Java Applications:

  1. Web Application
  2. Standalone Application
  3. Enterprise Application
  4. Mobile Application

Features of Java:

  1. Object-oriented
  2. Platform independent: Write once, Runs anywhere
  3. Simple: Easy to understand
  4. Secure: It provides a wide range of protection from virues and malicious programs
  5. Portable
  6. Robust
  7. Multi-threaded
  8. Distributed

Structures of Java programs:

  1. Documentation Section: Write a comment here. Comments are beneficial for developer because they help them understand the code.
  2. Package Statements: You can create a package with any name. A package is a group of classes that are defined by a name.

    1
    package package_name
  3. Import Statements: If you want to use a class of another package, then you can do this by importing it directly into your program.

    1
    import calc.add;
  4. Interface Statements: Interfaces are like a class that includes a group of method declarations. It’s an optional section and can be used when programmers want to implement multiple inheritances within a program.

  5. Class Definition: A Java program may contain several class definitions.
  6. Main Method Class: Every Java stand-alone program requires the main method as the starting point of the program.

JVM, JDK, JRE

JVM: Java Virtual Machine
JDK: Java Development Kit(includes JRE plus tools for developing, debugging and monitoring Java applications)
JRE: Java Runtime Environment is used as a package that gives an environment to run the Java program on machines.

Access Control Modifier

default: Scope only inside the same package
public: Scope is visible to world
protected: Scope of the package and all subclasses
private: Scope only within the classes only

Non-Access Modifier

final: modifier to finalizing the implementations of classes, methods, and variables. It means not change for them.
static
abstract: modifier for creating abstract classes and methods
synchronized and volatile: modifiers for using in threads

Data type

Integer:
byte
short
int
long

Rational numbers:
float
double

Characters:
char

Conditional:
boolean

Number

integer
short
byte
float
long
double

Character

char[]
Character

OOP

Major Objectives of OOP

  1. Emphasis is on the data rather than the procedures
  2. Methods that operate on data are tied together in a data structure
  3. Programs are divided into small instance called Objects.
  4. Data remains hidden and cannot be accessed by external functions
  5. Objects may communicate with each other through methods
  6. The programs follow the bottom-up approach

Basic terms and features

  1. Classes and Objects
  2. Data abstraction
  3. Data encapsulation
  4. Inheritance
  5. Polymorphism
  6. Dynamic binding

Advantages of OOP

  1. Code recycle and reuse
  2. Wrapping up of data into a single unit
  3. Easy to partition the work in a project based on objects
  4. Software complexity can be easily handled and managed
  5. Use fo inheritane can eliminate redundant codes in a program

Constructors

It is treated as a special member function because its name is the same as the class name. Java constructors are invoked when their objects are created.

Characterstics

  1. An interface cannot have the constructor
  2. Constructors cannot be private
  3. A constructor cannot be abstract, static, final, native, strictfp, or synchronized
  4. A constructor can be overloaded
  5. Constructors cannot return a value
  6. Constructors don’t hava a return type; not even void
  7. An abstract class can have the constructor

Two types of Constructor

  1. Default

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    import java.util.*;
    import java.lang.*;
    import java.io.*;
    class clerk{
    int roll=101;
    String grade="Manager";
    void display(){System.out.println(roll+" "+grade);}
    public static void main(String args[]){
    clerk c1=new clerk();
    clerk c2=new clerk();
    c1.display();
    c2.display();
    }
    }
  2. Parameterized

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    import java.util.*;
    import java.lang.*;
    import java.io.*;
    class paramC{
    paramC(int a, int b){
    System.out.print("Parameterized Constructor");
    System.out.println(" having Two parameters");
    }
    paramC(int a, int b, int c){
    System.out.print("Parameterized Constructor");
    System.out.println(" having Three parameters");
    }
    public static void main(String args[]){
    paramC pc1 = new paramC(12, 12);
    paramC pc2 = new paramC(1, 2, 13);
    }
    }

Reference

Java tutorials