Core Java Notes
Core Java Notes
Low-level languages:
1. They are easily understood by computers.
2. They are machine dependent languages.
Machine Language:
1. It is a first generation language.
2. Sequence of 1’s and 0’s form an instruction in machine language.
Example: 101010100011
Advantages:
1. It can be directly typed and executed.
2. No translator is required.
Disadvantages:
1. Difficult to remember machine instructions.
2. Difficult to understand, modify and remove errors.
3. Lack of portability.
Assembly Language:
1. It is a second generation programming language.
2. Symbolic words are used in this language called ‘Mnemonics’
Example: ADD for addition
SUB for subtraction
MUL for multiplication
DIV for division
Sample Program : Result = a+b
MOV a, 4
MOV b, 5
ADD a,b
MOV Result, a
Advantages:
1. Easy to remember
2. Easy to understand the program
3. Easy to write, modify and debug the program
Disadvantages:
1. Mnemonics are not standardized
2. Need of translator
3. Machine dependent
3. General purpose high level languages are used in almost all the fields such as
teaching, training, business, art and science.
Example: BASIC, Pascal and C language
4. Specific purpose high level languages are restricted to particular fields.
Example: COBOL for business data processing, Fortran for scientific applications,
C++/JAVA/.NET for web application development, PROLOG/python/R for Artificial
Intelligence.
Introduction to Java:
Features of Java:
1. Simple: Java is one of the simple language as it does not have complex features like
pointers and explicit memory allocation.
2. Secure: Java programs run in an environment that is independent of the operating
system environment which makes java programs more secure.
3. Robust: It is reliable. Checking the errors will be much faster and the java compiler
detects those errors that are not easy to detect by another programming language. Java
is robust because of the features like Garbage collection, Exception handling and
Memory allocation.
4. Distributed: The java programs can be easily distributed on one or more systems that
are connected to each other through an internet connection.
5. Portable: Java code written on one machine can be run on another machine by
carrying the bytecode.
6. Object oriented: Java is an object oriented programming language. Everything in java
is an object. Basic concepts of OOPs are: Object, Class, Inheritance, Polymorphism,
Abstraction and Encapsulation.
7. Machine Independent: A language that can run on any machine is called Machine
Independent language. The JVM can take compiled code for any Java application and
run it on any machine.
8. Architectural Neutral: Java is architecture neutral because there are no
implementation dependent features. Example: the size of primitive types are almost
fixed.
9. Dynamic flexibility:Java being completely object-oriented gives us the flexibility to
add classes, new methods to existing classes, and even create new classes through
sub-classes. Java even supports functions written in other languages such as C, C++
which are referred to as native methods.
10. Multithreaded: thread is like a separate program, executing concurrently. We can
write Java programs that deal with many tasks at once by defining multiple threads.
11. High performance: Java is faster than other traditional interpreted programming
languages because Java bytecode is "close" to native code
Applications of Java:
All desktop applications can easily be developed in Java. Java also provides GUI
development capability through various means, mainly Abstract Windowing Toolkit
(AWT), Swings and JavaFX. Adobe creative cloud is one such which comes as a set
of applications and services from Adobe Inc. that gives subscribers access to a
collection of software used for graphic design, video editing, web development,
photography, along with a set of mobile applications and also some optional cloud
services.
Java is also used to develop web applications. It provides a vast support for web
applications through Servlets, JSPs, Spring and SpringBoot. Most popular
applications such as IRCTC, LinkedIn are developed in Java.
Java is considered as the official programming language for mobile app development.
Most popular apps such as spotify, netflix and twitter were developed using java.
4. Gaming Applications:
Java is widely used by game development companies because it has the support of the
open-source most powerful 3D engine. The most popular games developed in Java are
Minecraft, Mission Impossible III and Asphalt 6 etc.
As many programming languages are available for Big Data Technology but still Java
is the first choice for the same. The tool Hadoop platform for processing and storing
big data applications is written in Java. In big data, Java is widely used in ETL
applications such as Apache Camel, Raptor and Apache Kafka. It is used to extract
and transform data, and load in big data environments.
A cloud application is the on-demand availability of IT resources via the internet. The
cloud-based application provides the service at a low cost. Java provides the
environment to develop cloud-based applications.Various Java cloud development
tools for cloud computing projects like Oracle Java Cloud Service, CloudFoundry,
Google App Engine, Openshift, IBM Smart Cloud, and AWS SDK for Java.
Java Embedded Framework - provides access from java for hardware and one board
computers like Raspberry Pi, Orange Pi, Banana Pi and etc. to control SPI / I2C /
GPIO or Serial ports
8. AI based Applications:
9. Scientific Applications:
Java has enhanced security features which makes it the best option for the
development of scientific applications. It has served as a powerful tool in coding
complex mathematical operations. The programs are designed in a highly secure and
efficient manner. Some of the most widely used applications like MATLAB use Java
as a component of the core system.
There are many software tools written in Java. For example, Netbeans, IntelliJ IDEA,
and Eclipse are all IDEs written and developed in Java.
11. Murex is a financial services company that develops software for trading, treasury,
risk, and post-trade operations in the capital markets. Its software system, also
called Murex, is used by over 60,000 daily users in over 60 countries.
JDK Software:
JDK is an acronym for Java Development Kit. The Java Development Kit (JDK) is a software
development environment which is used to develop java applications
The JDK contains a private Java Virtual Machine (JVM) and a few other resources such as an
interpreter/loader (Java), a compiler (javac), an archiver (jar), a documentation generator
(Javadoc) etc. to complete the development of a Java Application.
The JRE contains a JVM and all the class libraries present in the production environment, as
well as additional libraries useful to developers.
Architecture of JVM:
Java Virtual Machine (JVM) is the heart of entire Java program execution process. First of
all, the .java program is converted into a .class file consisting of byte code instructions by the
java compiler at the time of compilation. Remember, this java compiler is outside the JVM.
This .class file is given to the JVM. Following figure shows the architecture of Java Virtual
Machine.
In JVM, there is a module (or program) called class loader sub system, which performs the
following instructions: ·
Then it verifies whether all byte code instructions are proper or not. If it finds any instruction
suspicious, the execution is rejected immediately
If the byte instructions are proper, then it allocates necessary memory to execute the program.
This memory is divided into 5 parts, called run time data areas, which contain the data and
results while running the program. These areas are as follows: 1. Method area: Method area is
the memory block, which stores the class code, code of the variables and code of the methods
in the Java program. (Method means functions written in a class).
2. Heap: This is the area where objects are created. Whenever JVM loads a class, method
and heap areas are immediately created in it.
3. Java Stacks: Method code is stored on Method area. But while running a method, it needs
some more memory to store the data and results. This memory is allotted on Java Stacks. So,
Java Stacks are memory area where Java methods are executed. While executing methods, a
separate frame will be created in the Java Stack, where the method is executed. JVM uses a
separate thread (or process) to execute each method.
4. PC (Program Counter) registers: These are the registers (memory areas), which contain
memory address of the instructions of the methods.
5. Native Method Stacks: Java methods are executed on Java Stacks. Similarly, native
methods (for example C/C++ functions) are executed on Native method stacks. To execute
the native methods, generally native method libraries (for example C/C++ header files) are
required. These header files are located and connected to JVM by a program, called Native
method interface.
Execution Engine contains interpreter and JIT compiler which translates the byte code
instructions into machine language which are executed by the microprocessor. Hot spot
(loops/iterations) is the area in .class file i.e. executed by JIT compiler. JVM will identify the
Hot spots in the .class files and it will give it to JIT compiler where the normal instructions
and statements of Java program are executed by the Java interpreter.
Java program contains different types of elements like white spaces, comments and tokens. A
token is the smallest program element which is recognized by the compiler and which treats
them as defined for the compiler. A program is a set of tokens which comprise the following
elements:
Identifiers or names:
• It can comprise one or more unicode characters which are characters as well as digits.
Keywords:
These are special words defined in Java and represent a set of instructions.
• These are special tokens that have a predefined meaning and their use is restricted.