Chapter1

Introduction To Java

  • Java is a platform independent multi-paradigm programming language. Note:-Multi-paradigm means it supports multiple styles of Programming.
  • Java Supports:-
  • (i)Object-Oriented Programming [from beginningversion 1.0]
  • (ii)Functional Programming [from java 8v]
  • (iii)Modular Programming [from java 9v]
  • (iv)Data-Oriented Programming [from java 17v]
  • (v)Procedural Programming [from java 22v]

Who invented Java and why ?

  • Java is invented by Mr.James Gosling in Sun Microsystems in the year 1991,and it is released in the year 1995.The version is released only for testing purpose.
  • The first version for project development is released in the year 1996 as java 1.0.The latest version of java is 22,and it is released on March 19th 2024.
  • Currently java is with Oracle Corporation.In the year 2010,Oracle Corporation acquired java and all other products of Sun Microsystems.
  • Java is invented to achieve Platform independency for developing internet based business applications.

Types of Applications

In computer world all softwares or projects or applications are basically divided into two types:-

(i)Stand-alone Application:-
An application that is installed in one system and if it is accessible only within this system with a local call,and can't be accessible from other systems with a network via internet then we call it as Stand-alone application. A stand-alone application is a single user and single computer application.
For example:-Calculator,Notepad,Antivirus,MS-office,Game softwares,browser,mobile apps etc..

(ii)Internet Application:-
An application that is installed in one system and if it is accessible from other systems with a network via internet is called as Internet Application. An internet application is a multi user and multi computer application.
For example:-Youtube,Instagram,Facebook,Amazon,Zoom etc...

What is Platform,PD,PI ?

Platform:-
A platform is an environment in which programs are loaded and executed and generate output. A platform can be a software only platform or hardware only platform or both.

  • The computer platform is Processor+Hardware devices+OS.
  • C and C++ programs platform is OS.C and C++ programs are directly exceuted by OS.
  • Java Programs platform is JVM(Java Virtual Machine). Java Programs are excuted by JVM,but not by OS. JVM's platform is OS.The OS executes JVM, JVM executes Java Program.
  • Python program's platform is PVM(Python Virtual Machine).Python Programs are executed by PVM,but not by OS. PVM's platform is OS. The OS executes PVM, PVM executed Python Program.
  • HTML page platform is browser.
  • Audio and Video files platform is media player(vlc).
  • .NET program platform is CLR(Common Language Runtime).

Platform Dependency:-
A program's compiled code of one OS,if it can not be executed in different OS we call it as Platform Dependency.The programming language using which we develop this program is called as Platform Dependent Language.
For Example:C and C++ programs

Platform Independency:-
A program's compiled code of one OS, if it can be executed in different OS we call it as Platform Independency.The Programming language using which we develop this program is called as Platform Independent Language.
For example:Java,Python Programs

Why C and C++ programs are PD ?

In C and C++ languages programs are compiled targeting to one OS. Hence the compiled code contains ML(Machine Language)of a Particular OS directly.One OS machine language format is not understandable to another OS.Hence the C and C++ programs compiled code can not be executed by other OS.Hence the C and C++ programs are Platform Dependent.
Not only C program, C software is also platform dependent, because all it's components Compiler, Linker & Library are Platform Dependent.So, we will have separate C software for every OS.

How java achieved PI ?

In java,programs are not compiled into Machine Language of a Particular OS.It means in Java,Programs are not compiled targeting to one OS.In java,programs are compiled into one common languages code called byte code then later that byte code is converted into ML of a particular OS by JVM in which it is running.We have to separate JVM for OS for converting the same bytecode into a particular OS ML.

Downloading and installing JDK Software

  • JDK stands for Java Development Kit
  • JDK is the java Software
    It provides :-
    (i)Development Tools
    (ii)Runtime Environment
    (iii)Java Library(API-Application Programming Interface)
  • Development tools means small softwares for compiling java program, reading byte code, generating documentation, preparing jar files etc... opeartions performing softwares are called Development Tools.
    Runtime Environment means the platform for running java program. The JVM is called Runtime Environment of Java Program for executing java programs.
    Java Library means the predefined classes provided by SUN(Oracle) as part of JDK for reusing and developing our new programs. In java we will calls library as API.
  • Hence we can say by installing JDK software we will get (compiler,JVM and API) for developing,compiling and executing a java program.
  • Downloading and installing JDK22 software:-
  • (1)Open browser
    (2)Search jdk 22 download
    (3)Click java downloads
    (4)Scroll down ->Click windows
    (5)Click jdk.exe file
    (6)Downloading will be start
    (7)After Downloading is completed
    (8)Click on jdk.exe file on browser download
    (9)Click yes to give permission to start installing
    (10)Click next in the first window
    (11)Click change in the next window
    (12)And make installing path as "C:\jdk-22\" (13)Click Ok ->Next ->Close (14)JDK installation is completed in the folder "C:\jdk-22"
  • Steps to develop a java program
    a java program development, compilation and execution comes under & steps:- (1)Open Notepad
    (2)Type java code/program
    (3)Save this program
    (4)Open cmd prompt software
    (5)Change drive and directory path in cmd prompt to our project drive and directory in which our program is saved. (6)Compiler java program by using javac tool.(javac ) (7)Execute java byte code by using java tool .(java )

Essential Statements to develop Java

To develop, compile, execute and display some message in java we have three essential Statements.
(i)Class :-
Class is essential because, Java is an OOP language so every program must starts with a class.
(ii)Main method :-
Main method is essential because,main method is the initial point of class logic execution.JVM executes a class starts with main method. If a class doesnot have main method, JVM will not execute it , will throw error.
(iii)System.out.println(); :-
System.out.println(); is essential in java. We can display any message on console only by using System.out.println(_);

First Hello World Program

Step#1 : Open notepad [press window key->type notepad ->press enter key]
Steps#2 : Type java program

                        class FirstProgram {
                            public static void main(String[] args){
                                System.out.println("Hello World")
                            }
                        }
                    
Step#3 : Save the above program with the name "Example.java" in the folder "D:\FSJD\01CJ\01JB"
Step#4 : Open cmd prompt
Step#5 : Change drive and directory path by running below commands.
Step#6 : Compile Example.java by using javac tool as shown in below.
Step#7 : Execute the class FirstProgram by using java tool as shown below.
                        C:\Users\Puspanjali>D: <--
                        D:\cd D:\FSJD\01CJ\01JB <--
                        D:\FSJD\01CJ\01JB>javac Example.java <--
                        D:\FSJD\01CJ\01JB>java FirstProgram
                        output:Hello World
                    

Develop a program to print your name on console

                    class Nameprinter {
                        public static void main(String[] args) {
                            System.out.println("Puspanjali Parida")
                        }
                    }
                

Save the above program with the NamePrinter.java in the folder D:\FSJD\01CJ\01JB.

                        C:\Users\Puspanjali>D: <--
                        D:\cd D:\FSJD\01CJ\01JB <--
                        D:\FSJD\01CJ\01JB>javac NamePrinter.java <--
                        D:\FSJD\01CJ\01JB>java NamePrinter
                        output:Puspanjali Parida
                    

Escape Sequence Characters

(i)A character preceded by \ is called esc seq character.
(ii)The \ either adds or removes the special meaning to the character placed after \.
(iii)The \ adds the special meaning to the letter n,t and s.
(iv)The \ removes the special meaning to the letters ", ' and \.
(v)After \ we can not place a letter or a digit or special character randomly as we like .From one programming language to another PL the list will be changed.
(vi)The java supports below 18 esc seq Characters(9+8+1):-
1.Letter based esc seq Characters(9):-
(i)\n - inserts one new line (ii)\t - inserts one tap spaces[<=8spaces]
(iii)\r - inserts one carriage return
(iv)\s - inserts one space
(v)\f - inserts one form feed
(vi)\b - inserts one back space
(vii)\' - inserts one single quote '
(viii)\" - inserts one double quote "
(ix)\\ - inserts one \

2.Octal digits based esc seq Characters(8):-
(i)\0 - inserts one null character(it is not empty char)
(ii)\1 - start of heading, used in data transmission
(iii)\2 - start of Text, used in data transmission
(iv)\3 - End of text, used in data transmission
(v)\4 - End of transmission, used in data transmission
(vi)\5 - Enquiry, used in data transmission
(vii)\6 - Acknowledge, used in data transmission
(viii)\7 - Bell, used for an audible alert or notification.

3.UNICODE based esc seq character(1):- (i)\UXXXX

What is User Defined Method and Pre Defined Method ?

User Defined Method:-
Developer defined method is called User Defined Method or Custom method.
Pre defined method:- Already defined methods are called predefined method. These methods are may be developed by SUN Microsystem develpers, or some other developers.
Example:- println() method is predefined.

What is User Defined Class and Pre Defined Class ?

User Defined Class:-
Developer defined class is called as User defined class or custom class.
Predefined class :-
Already defined class is called as Predefined Class.These class may be developed by SUN Microsystem developers, or some other developers.
Example:- System,String are predefined classes and FirstProgram,Employee are user defined class.

Chapter2

What is Comment and why ?

Comment:-
A comment is a special syntax.A comment is used for telling to compiler for ignoring some part of the code compilation.The code placed in the comment will not be compiled by compiler,byte code is not generated. It means the code placed in the comment will not be available in .class file.

When must use a comment ?"

We must use Comment:-When the existing code is temporarily not required.
or
When we need to provide description to a program.

How many types of comments Java supports ?

Java Supports 3 types of Comments
(i)Single Line Comment (//)
(ii)Mutli Line Comment (/* */)
(iii)Document Comment (/** */)
Single line and Multi line comments are used for commenting programming Statements such as variable, methods, Sopln(),conditions,loops etc...
Document Comment is used for providing description to programming elements such as class, variable, method, constructor, block, inner classes.

What is Identifier ?

A name of a Programming element is technically called as an Identifier. A class name, variable name and method name are called as Identifier.

Rules in Creating Identifier

(a)Identifier must contain only
(i)letters ->A-Z or a-z
(ii)digits ->0-9
(iii)special Characters ->only $ and _

(b)Identifier can not be started with a digit. We can use a digit only from second character onwards.
(c)Identifier can not have special Characters except $ and _.
(d)Identifier can not have space in the middle of the words. If we need to provide spaces, we must connect by using _. Hence _ is called as Connector symbol.
(e)Identifier is case sensitive (a!=A) we can create two variables with the name 'a' and 'A'.
(f)The keyword and reserved words can not be used as an user defined Identifier. But predefined class name, variable name and method name can be used as User defined Identifier.

Types of Identifier

We will provide name to below programming element:-
(i)Module Name
(ii)Package Name
(iii)Class Name
(iv)Variable Name
(v)Method Name
(vi)Lebel Name
(vii)Generic Parameter Name

Reserved Words in Java

01.Package creation and usage(2)
01.package
02.import

02.class creation(3)
03.class
04.Interface
05.enum(1.5)

03.Data types and Return types(8+1)
06.byte
07.short
08.int
09.long
10.float
11.double
12.char
13.boolean
14.void

04.Memory allocation(2)
15.static
16.new

05.Control Flow Statements(11)
01.Conditional or Decision making(5)
17.if
18.else
19.switch
20.case
21.default
02.Loop or Iterative(3)
22.while
23.do
24.for
03.Transfer or Branching(3)
25.break
26.continue
27.return

06.Accessibily Modifier(4)
28.private
default /package-private
29.protected
30.public

07.Execution Level Modifiers(8)
static
31.final
32.abstract
33.native
34.transient
35.volatile
36.synchronized
37.strictfp

08.Establishing inheritance relationship(2)
38.extends
39.implements

09.Representing object and it's members(3)
40.this
41.super
42.instance of

10.Exception Handling Statements (5+1)
43.throw
44.throws
45.try
46.catch
47.finally
48.assert

11.Unimplemented Keywords(2)
49.goto
50.const

12.Java 9v new keyword(1)
51._(underscore)

13.Default/Reserved Literals(3)
-boolean literals(2)
52.true
53.false
-null literal(1)
54.null

14.Java 9v Restricted Keywords(10)
55.module
56.requires
57.transitive
58.exports
59.open
60.opens
61.to
62.provides
63.with
64.uses

15.Special Identifiers or Restricted Identifiers(6)
65.var
66.yield
67.record
68.sealed
69.non-sealed
70.permits
71.when