Java notes on object oriented programming concepts, Cheat Sheet of Java Programming

This pdf contains notes for java object oriented programming concepts

Typology: Cheat Sheet

2022/2023

Uploaded on 03/31/2023

beast-pegasus
beast-pegasus 🇮🇳

1 document

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Java
Definition: 1. Programming Language : Java is a platform-independent, HIGH LEVEL , Object oriented,
robust programming language
. Java is a platform because java has its own runtime environment (JRE)
History: -> Company : Sun Microsystems (now Oracle)
-> Created By : James Gosling & team
Idea : Java idea came because designers wanted to create a language which should be platform
independent based on write once, run anywhereconcept, tight coded programming language etc
-> Name : Oak -> Year : 1991 (development)
Name: Java (on Indonesia famous ‘Java’ coffee)-> 1995 (release)
Editions:
1. J2SE : -> Java 2 Standard Edition (Core Java) -> In this edition we learn java fundamentals
2. J2EE : -> Java 2 Enterprise Edition (Advance Java) -> In this edition we learn server-side
programming -> Projects : Enterprise Applications
3. J2ME : -> Java 2 Micro Edition (it has been replaced by Android) -> In this edition we learn micro
programming
Applications
Desktop based applications(media player, antivirus, opera mini, video games etc)
Web-based applications
Mobile applications
Embedded systems
Game development
Enterprise applications
Features
Simple – because of combination of C and c++, it simple, easily understandable. Also concept
of ‘pointer’ is eliminated here.
Totally OOPs based, so makes code modular, easily recoverable and error identifiable .
Platform independent and Portable- Unlike C or C++, once java application is written onto a
platform can run any other different platforms.
Dynamic – classes are loaded only when needed at runtime. As anything happened in
runtime is dynamic so java is dynamic.
Robust – errors occur in C, C++ is eliminated here
Secure- secured program which are very efficient to reduce attacks and cyber threats can be
written in java.
Multithreading – thread is the smallest unit of process or a single operation. Java’s
Multithreading concept can run multiple tasks parallelly. Increases multitasking.
** Java naming conventions
pf3
pf4

Partial preview of the text

Download Java notes on object oriented programming concepts and more Cheat Sheet Java Programming in PDF only on Docsity!

Java

Definition: 1. Programming Language : Java is a platform-independent, HIGH LEVEL , Object oriented, robust programming language

. Java is a platform because java has its own runtime environment (JRE) History: - > Company : Sun Microsystems (now Oracle) - > Created By : James Gosling & team Idea : Java idea came because designers wanted to create a language which should be platform independent based on “ write once, run anywhere” concept, tight coded programming language etc - > Name : Oak - > Year : 1991 (development) Name: Java (on Indonesia famous ‘Java’ coffee)-> 1995 (release) Editions:

  1. J2SE : - > Java 2 Standard Edition (Core Java) - > In this edition we learn java fundamentals
  2. J2EE : - > Java 2 Enterprise Edition (Advance Java) - > In this edition we learn server-side programming - > Projects : Enterprise Applications
  3. J2ME : - > Java 2 Micro Edition (it has been replaced by Android) - > In this edition we learn micro programming Applications  Desktop based applications(media player, antivirus, opera mini, video games etc)  Web-based applications  Mobile applications  Embedded systems  Game development  Enterprise applications Features  Simple – because of combination of C and c++, it simple, easily understandable. Also concept of ‘pointer’ is eliminated here.  Totally OOPs based, so makes code modular, easily recoverable and error identifiable.  Platform independent and Portable- Unlike C or C++, once java application is written onto a platform can run any other different platforms.  Dynamic – classes are loaded only when needed at runtime. As anything happened in runtime is dynamic so java is dynamic.  Robust – errors occur in C, C++ is eliminated here  Secure- secured program which are very efficient to reduce attacks and cyber threats can be written in java.  Multithreading – thread is the smallest unit of process or a single operation. Java’s Multithreading concept can run multiple tasks parallelly. Increases multitasking.

** Java naming conventions

Explain Java program structure A java code has 5 main sections-

  1. Documentation Section :- - > It contains the basic information about java program for eg. author's name, date of creation, version, program name, company name, client name etc
  • This part is OPTIONAL - > To create documentation section we use comments - > There are 3 types of comments :-  Single Line Comment (//)  Multi-Line Comment (/* ----- */)  Documentation Comment

  1. Package Statement :- - > It is a group of similar type of classes or interfaces or packages - > Types of packages :- 1. Predefined Package (which are already created by java for eg. lang, awt, swing, util, sql etc) 2. User Defined Package (which are created by the developer) - > Syntax : package package_name;
  2. Import Statement :- - > Import statements is used to make available the classes or interfaces which we are going to use in present java file
    • Syntax : 1. import <packagename.sub-package_name.ClassName>;

  3. import packagename.*;
  • if we use "import packagename.*;" only classes or interfaces will be imported, not the subpackage. - > If we dont want to use import statement then we can directly write the packagename.ClassName to use that class. - > This line is written after the package line. 4. Interface/Class Section :

  • Variables & Methods

 JIT compiler o Interpreter – it decodes and executes each statement of code one by one. o JIT compiler: While the interpreted program is being run, the JIT compiler determines the most frequently used code and compiles it to machine code. It is used when required at runtime only, thts why it is Just In-Time compiler. It improves the performance of execution. JIT compiler executes only for repetitively executed code. JIT, or Dynamic Translation, is compilation that is being done during the execution of a program. JIT compiler will compile the bytecode into machine instructions of the running machine means, that the resulting machine code is optimized for the running machine’s CPU architecture. Datatypes

  1. Primitive datatype: Already defined(pre-defined). For these datatypes size is fixed. 8 main primitive datatypes are- Boolean, char, byte, short, int, long, float, double. o To find the range of Integer primitive data type we can use the formula i.e. - 2 (n-1)^ to 2(n-1)^ - 1 (where n is no of bits) o To find the range (minimum and maximum value) of primitive data types (excluding boolean) we can use static int variables i.e. MIN_VALUE & MAX_VALUE
  2. Non-Primitive Data Types: these are User Defined Data Type or Derived Data Type.Non- Primitive data types are not pre-defined data types but are created by the coder or programmer. These are sometimes known as "reference variable" or "object reference" - The size of non-primitive data type is not fixed Examples :- String, Array, Collection, Class, Abstract Class, Interface etc.  What are Wrapper Classes – The classes which are used to convert primitive into objects and objects into primitive are called Wrapper class. There are 8 wrapper classes :- Boolean, Character, Byte, Short, Integer, Long, Float & Double
  • Java introduced autoboxing and unboxing in J2SE 5.0 version. which coverts primitive into object and object into primitive datatype automatically.

 What is Autoboxing & Auto-unboxing?

  • When boxing(conversion of primitive data type into its corresponding wrapper classes) is done automatically by java compiler, that thing is called autoboxing.

  • Auto-unboxing is opposite conversion of autoboxing, the automatic conversion of an object of wrapper type to its corresponding primitive value by java compiler. Example : class HelloWorld { public static void main(String[] args) { int a=5; Integer A= new Integer(a); // boxing or wrapping int b= A.intValue(); // unboxing or unwrapping //Integer A= a; //autoboxing //int b= A; //autounboxing System.out.println(b); } }