[10 Feb 2020] Java API

Java API


  • Library of well-tested classes
  • Java 8 - 4240 classes
  • Part of JDK 

Packages:-

java.lang

  1. String
  2. class..
  3. Object

java.util

  1. ArrayList
  2.  HashMap

java.io
- File

Why Packages ?

  • Meaningful organization
  • Name Scoping java.util.Date != java.sql.Date
  • Security

Java API: Important Packages

  • java.lang : Fundamental classes
  • java.util : Data structure
  • java.io: Reading and Writing
  • java.net : Networking
  • java.sql : Databases

Google for java8 API

Item 47 - API Benefits

  • Focus on writing new logic
  • APIs improves performance over time
  • Gain new functionality too

Accessing Classes

  • Same packages: direct access
  • Different Package  (import, fully qualified name of class)       

import java.util.ArrayList

Import all classes in a packages
    import java.util.*;
*import can break code

import java.util.*;
import java.sql*;

Date date; //compiler error as both of above packages contain Date class

The below gives the compiler error.
import java.util.Date
import java.sql.Date

import statement 

  • does not make your class bigger
  • Does not affect runtime performance
  • saves from typing fully-qualified name ~ compiler does this

java.lang package is imported by default


Package is directory on file system
com->semanticsquare->basics

package statement


  • package package-name
  • package com.semanticsquare.basics;
  • must be first statement above any import


















































































Comments

Popular posts from this blog

Very Basic Java Programs

[08 Feb 2020] Minimum number of platforms required for a railway station

Interview Questions asked in Goldman sach interview