You are on page 1of 13

CORE JAVA NOTES

HISTORY OF JAVA LANGUAGE:


a) The author of java is James Gosling who joined sun microsystem in 1991 as a core
writer(programmer).
b) The author is port of project controlling electronics setup boxes using remote.
c) In the process of code writing the author identifies the existing language are platform
dependent language. In order to prove the platform dependent code, the author started
writing a new code which platform independent code which is named as Java & release
his first version by 1995.
VERSIONS OF JAVA LANGUAGE:
1995 -- JAVA alpha &beta
1996 -- JDK 1.0 2004 – JAVA 5 (Tiger Java)
1997 -- JDK 1.1 - JDK 1.5
1998 -- JDK 1.2 - JRE 1.5
2000 -- JDK 1.3 2006 – JAVA 6
2002 – JDK 1.4 - JDK 1.6
2014 – JAVA 8 - JRE 1.6
 JDK 1.8 2011 – JAVA 7
 JRE 1.8 - JDK 1.7
2017 – JAVA 9 - JRE 1.7
 JDK 1.9 2018 – JAVA 10
 JRE 1.9

INSTALLATION PROCESS FOR JAVA


o Download java software (JDK 1.8) from Oracle website
o Install the JDK 1.8
o After installation process successful, we can find folder with name Java in program files
folder
o Set the java path in “Environment Variable”, then right click on “my computer” =>
choose properties => Advanced system settings => Environment variables => click new
from system variables
o New window appears
VARIABLE NAME: PATH
VARIABLE VALUE: java path up to bin then add “;” at end.
o Click OK for 3 times
o Open CMD and type “javac and “Java” commands are not working or not.
javac => Compilation process
java => Execution Process
INTERVIEW QUESTION:
What is the difference between JDK, JRE and JVM?
Ans:
JDK: is stands for Java Development Kit which is having both java compiler and JVM. Java
compiler is for compilation and JVM is for execution process.
 This JDK is used by core Java Developers
JRE: Java Run-Time Environment, which provides only JVM for execution.
 JRE is used by webservices and application servers to run or execute server
application.
JVM: Java Virtual Machine, which is part of both JDK and JRE, JVM will execute JAVA
byte Code.
 JVM runs independently in the process of executing java byte code.

 What is Virtual machine?


Ans: The software component which is internally having the behaviour like machine is
known as virtual machine. It is using for executing your java byte code.

 Define Class?
Ans: It is a structures layout used for generating Objects. OR A class is a collection of
variables, methods and main().

 Define Objects?
Ans: Object is memory related to class, which holds the component of class.

2
JVM ARCHITECTURE

 JVM internally contains loader


 JVM internally divided into the following components
a) Class Loader Subsystem:
This will load the java byte code onto JVM, while loading process the class loader
subsystem will use the following components.
 Loader: Loader will load the required files into current running program. This
loader also used the following three sub-loaders.
i) Bootstrap class loader: It will load the required files available from java
library.
ii) Extension class loader: This will load the required files available from ext
folder of JDK.
iii) Application class loader: It will load the required files available from
“class path” of environment variable.
 Linker: It will link the loaded files into current running program where they are
needed, while linking process the linker will use the following 3 components.
i) Verify: This component will check the loaded files and the required files
are same or not.
ii) Prepare: Prepare component will decode and identify the type of
component for example: variable, method etc.
iii) Resolve: this component identifies which component belong to class and
which component belongs to object using keyword “static”.
 Initiate (Initialization): In initialization process them memory generated is know as
run-time data area and this runtime data area is loaded with class for execution.
Note:
 Based on Java language the components from the program are categorises into two types
i) Static programming component which are declared with static keyword.
ii) Non-static programming component which are declared without static keyword.
iii) In java main method are always static.
 Class object is seen overall by the project, whereas the object is local.
 The Static programming components will get this memory within the class
 Non- static programming components will get the memory within the object.
 Static programming components are accessed with the class name and non-static are accessed
with object name.
 If static is declared variable get address with in the class. If static is not declared the variable
get address within the object.

3
b) Run-time data area:
This Run-time data area is internally divided into the following blocks:
i) Method area: the memory block where the class code is loaded is known as
method area.
Note:
 While class loading the static programming components will get the memory within
the class.
 In this process main will get the memory within the class.
 Once main got the memory within the class, then it is automatically copied into the
stack area to start the execution.
 Once main method copied into the stack area then execution control will come to
java stack area to check the main format as “public static void main (String args
[])”
 If the format is available then the execution starts.

ii) Heap area: the memory block where the objects are created is know as heap area.
Note: while object creation, the non-static members of the class will get memory
within the object.
iii) Java stack area: The memory block where main is copied to start the execution.
In the execution process the main will call remaining methods for execution.
Note: This is area where all methods are executed.
 “.” In java refers to or belongs to same class, package etc.
iv) PC register area (Program- counter Register Area):
 This will record the states of method execution in java stack area.
 Every method executing in java stack area will have its own PC register.
 All these PC registers are opened in separate memory block known as PC
register area.
v) Native method area:
 The method a from JavaLib which are using native keyword are known as
native methods.
Eg: public final native void wait()
Public final native void notify()
 While these native methods are used in program construction then these
methods are separated & loaded onto separate memory block known as
native method because these are constructed using C/C++ code.

c) Executing engine:
 Execution engine internally contains two translators (interpreter and JIT
compiler).

4

The execution control will come to java stack area starts the execution with
main-method.
 The execution process will be started by interpreter (this interpreter will
execute line by line) and executes normal instructions.
 When interpreter finds stream instructions then the execution engine transfer
to JIT compiler.
 This JIT compiler will execute stream instructions (bulk instruction).
 Java language is interpreter language because execution control internally
uses interpreter.
 Why do we use interpreter in execution?
Ans: When we use interpreter in execution process then the application can accept request in the
middle of execution, which is preferrable in internet application development.
 Define Environment variable?
Ans: Environment variable are parts of Operating system. The variables which are part of
operating system which control and manages the resources of computer system. These
environment variables are categorized into two types
a) User variables: The variables which can be used by the individual users.
b) System variables: These system variables can be used by all the users in the computer
system.
Note: According to java language the variables path of user variables & system variables
can be two types
a) Path: the value in “path” is used by javac and java commands prompt.
b) Class path: The value in class path is used by application class loader part of JVM.
Simple structure of Java programs
In java language all the programming components are binded within the “class” because of this
because of this reason we cannot write a program without class in java.
public class Class_name {
//variable
// methods
public static void main(String args[]) {
//set of instructions
}
}
i) Public: makes the main access outside the class
ii) Static: makes the main available within the class or the main get the memory within
the class.

5
iii) void: makes the main “non-return type” method. (Which does not return any value
after execution)
iv) main() must be passed with String array as parameter because which is ready to
accept any type of data value.

 Define Javalib?
Ans: Java library is represented using word “java” and is a collection of variables and methods.
 Package are collection of classes and interfaces
 Classes and interfaces are collections of variables and methods.

CLASSES AND
JAVA PACKAGES VARIABLES &
INTERFACES
METHODS

 Define instruction?
The line of the program which specifies the action to be performed is known as instruction.
These instructions are part of program must be terminated suing ‘;’.
Note: In the process of constructing instruction in java program we use import statement.
Syntax: import java. package-cname.method-name();
 Define print method?
i) print method is a build in method, which is used to display messages or result or
combination of both.
ii) Print method is accessed using system class. This system class internally having 3
streams (connections). i.e., in-input, out-output, err-error.
iii) System class belongs to “lang” package
iv) “lang” package belongs to java library.
v) While program coding this “import” statement is divided onto 2 parts
a) Part-1: java library & package (this part must be declared above the class)
import java.lang.*;
b) Part-2: Classname and method name. (this part must be declared within the class)
System.out.print("msg");
Example program:
import java.lang.*;
class Welcome {
public static void main(String[] args) {
System.out.print("Welcome to java");} }

6
 Writing, saving, compiling and executing java program
Step-1: Create folder part of any drive.
Step-2: Open any text editor and type the program before typing browse the folder.
Step-3: After typing, save the file with .java extension.
Step-4: Go to destination folder and type cmd in address path & press enter.
Step-5: Compile the program as javac class-name.java.
Step-6: Execute the program as command java class-name.
Example program-2:
Write a program to add tow number and display the result?
import java.lang.*;
class ADD {
int a, b;
void add(){
System.out.println(a+b);
}
public static void main(String[] args) {
ADD ob=new ADD();
ob.a=1;
ob.b=2;
ob.add();
}
}

 Define new Operator?


“new” operator in java is used to generate objects from class.
Syntax: class-name object-name= new class-name();
Object creation behaviour: while object creation process, the execution control transfer to the
heap area and generate reference (object reference). This object reference is binded with the non-
static members of the class (all these non-static members will get the memory at this reference).
 Define Variables?
Variables are the data holders. Bases on the static keyword the variable care categorized into
types
i) Non-static variables: The variables which are declared without static keyword are
know as non-static keywords. Bases on the declaration and memory allocation the

7
non-static variables are categorised into two types.
a) Instance variables: The non-static variables which are declared outside the
methods are known as instance variables. This instance variables will get the memory
within the object while object creation.
 Memory location: This instance variable will get the memory within
the object while object creation.
 Scope & visibility: these instance variables are accesses by the
methods of same objects.
 Lifetime: These instance variables are available until object is available
b) Local variables: The non-static variables which are declared inside the methods
are known as local variables.
 Memory location: These local variables will get memory within the
method or method frame, while method execution.
 Scope & visibility: These local variables are accessed only within the
method or method frame.
 Lifetime: these local variables are available until method is available.

Note:
a) Define Method frame?
Ans: The partition of java stack area where the method is executed is known as Method
frame.
 Behaviour of method frame: After method execution completed the method frames
will be destroyed automatically from java stack area.
b) Define object?
Ans: Object is a memory created as part of heap area related to a class holding non-static
members of the class.
c) The instance variables which are not initiated with any value, while memory generation
are assigned with default values.

 Behaviour of non-static execution:


While non-static method execution, the execution control will check the required variables
within the method from 1st. if not available checks the object and if not available check the class
finally.
 Naming conventions in java
The rules to be followed by the java program in typing a java program are known as naming
convention in java.
i) Packages: packages must be in lower case.
ii) Classes and interfaces: In class and interfaces the starting letter of every word must
be capital.

8
Ex: BufferReader, InputStreamReader
iii) Variables and methods: In variables and methods, the first word must be in lower
case and from second word onwards the starting letter must be capital.
Ex: getSalary(), toUpperCase(), rollNo, empId.

 Data Types in java:


The type of data that we are expecting as input to java program are known as data types in
java
Datatypes are of two types i.e., Primitive datatypes and non-primitive datatypes.
 Primitive Datatypes: The datatypes which are existing in the form of “single values data
format” are known as primitive datatypes.
These primitive datatypes are categized into 4 types:
a) Integer datatypes:
byte 2bytes
short 2 bytes
int 4 bytes
long 8 bytes

b) Float datatypes:
float 4 bytes
double 8 bytes

c) Character datatypes: char-2 bytes


d) Boolean datatypes: Boolean-(true/false) or (0/1) – 1 byte
Note: When we use primitive datatypes variables will generate “field storage”
Define Field Storage?
Ans: The memory which is generated part of java program to hold single data value is known as
field storage.
 Non-Primitive Datatypes:
The datatypes which are existing in the form of group values data format are know as
non-primitive data types.
The following are the non-primitive data types
Class
Interfaces
Arrays
Enum
Note:

9
 These non-primitive datatypes will generate object storage.
 Define Object Storage?
Ans: The memory which is generated part of java program to hold “group non-static
members of the class” is known as object storage.
 Based on javaLang the variables of primitive data types will hold values and non-
primitive datatypes will hold reference.

OBJECT ORIENTED PROGRAMMING


 The process of controlling and managing non- primitive datatypes is known as object-
oriented programming.
 These non-primitive datatypes are also known as referential datatypes.

 Class:
 Class is a structural layout generating objects.
 Class is loaded on to method area of jvm.
 Class is a collection of variables, methods and main
Variables will hold the data
Method will give actions
Main will start the program
 Class which is holds main is main class.
 Class which does not hold main is classed sub-class (holds variables and methods).
 The application development we have only one main class but we can have any
number of subclasses.
 Classes are divided into two types
 User Defined classes: the classes which are defined by the programmer
 Build-in classes: The classes which are already existing with the JavaLib are
known as building classes.
Ex: Scanner Class
Scanner class:
 It is used to read the data into java program by considering the console input
keyboard.
 Scanner class is available from JavaLib.
 The following are some non-static methods from scanner class.
 Public byte nextByte();
 Public short nextShort();
 Public int nextInt();
 Public float nextFloat();
 Public double nextDouble();
 Public boolean nextBoolean();

10
 Public long nextLong();
 Public String nextLine();
Note:
 All these methods are return type non-static methods & will get the memory
within the Scanner class object & accessed with the object reference variable
(object name).
 Scanner class is used in the java program when we want to read the data from data
input.
 Syntax of object creation for Scanner Class:
Scanner s= new Scanner (System,.in);

 Operators in java:
The following are some operators in java
Relational operators
Arithmetic operators
Operator Meaning
Operator Meaning
> Greater than
+ Addition >= Greater than or
- Subtraction equal
< Less than
* Multiplication
<= Less than or equal
/ Division == Is equal
% Modulus division != Not equal

Logical operators
Operator Meaning Incremental/ decremental operators
&& Logical AND Operator Meaning
|| Logical OR ++ Increment
! Logical NOT -- Decrement

 Control Structures in java:


 The process of controlling and managing the partition of program based on the condition
is known as control structures.
 These control structures are categorized into 3 types:
a) Selection structures: The statements which are used to select partition of program on
some condition is known as selection statement.
Selection statement types

11
simple if
if else
nested if
ladder if else
switch case

b) Iterative statements: The statements which are used to repeat the set of lines if the
program on some conditions is known as Iterative statement.
Iterative statement types
while loop
do while loop
for loop

c) Branching statement: The statement which are used to transfer the control from one
location to another location of the program.
Branching statement types
break
continue
return
exit
Note: there is not concept of goto function in java.

 Methods:
 Methods are the actions performed on the variable.
 According to java methods are categorised into two types
i) Instance methods:
 The methods which are declared without static keywords are known as
instance methods or non-static methods.
 Instance methods will get memory within object whether it may be
variable or method.
 These instance methods will get the memory within the object, while
object creation and accessed with the object names.
 These instance methods are categorized into 2 types:
a) Build-in instance methods: The instance methods which are already
existing within the java library are known as build-in instance
methods.
Note: we use javap command to view all the building methods from
the class or interface.

12
b) User-defined instance methods: The instance methods which are
defined by programmer are know as user-defined instance methods.
Syntax:
return-type method-name(parameter-list) {
//body}

ii) Static methods

13

You might also like