Core Java Course - Report
Core Java Course - Report
Submitted by
Subhransu Sekhar Swain ECE201810346
2020-2021
ABSTRACT
JAVA is Object Oriented Programing Language that is class based and designed
to have few implementation dependencies as possible. One thing that distinguished java
from other language is its ability to run the same compile code across multiple operating
system. In java JVM is a software implementation that execute program like real
machine. JAVA programs are compiled by the java compiler into byte code. The jvm
interprets this byte code and executes the java program. There are many applications of
java in real world. It is used in android apps, server apps, software tools, trading
applications, big data technologies high frequency trading space etc.
There are three access modifiers key words available in java they are (1)Public
(2)Private (3)Protected and four access levels (1)Public (2)Private (3)Protected
(4)Default. They define how the corresponding elements is visible to other components.
i
B.Tech. 2018-2022
ACKNOWLEDGEMENT
We would also like to extend our heartfelt gratitude to our parents and friends for
their unflinching support and help.
ii
B.Tech. 2018-2022
TABLE OF CONTENTS
1. INTRODUCTION TO JAVA
1. 1. CHARACTERISTICS
1. 2. JVM
1. 3. APPLICATIONS OF JAVA
2. PREREQUISITES
2.1. PACKAGES
2.2. CLASS AND OBJECT
2.3. VARIABLES AND METHODS
2.4. ACCESS MODIFIERS AND IMPORT STATEMENTS
2.5. CONSTRUCTOR
3. INHERITANCE
3.1. WHAT IS INHERITANCE?
3.2. WHY IT IS USED?
3.3. WHERE IT IS USED?
3.4. HOW IT IS DONE?
4. PROS AND CONS OF JAVA
5. CONCLUSION
6. REFERENCE
iii
B.Tech. 2018-2022
INTRODUCTION
Simple and easy to use - Java's creators tried to design it so code could be
written efficiently and easily.
iv
B.Tech. 2018-2022
Java does have some drawbacks. Since it has automated garbage collection, it
can tend to use more memory than other similar languages. There are often
implementation differences on different platforms, which have led to Java being
described as a "write once, test everywhere" system. Lastly, since it uses an
abstract "virtual machine", a generic Java program doesn't have access to the
Native API's on a system directly. None of these issues are fatal, but it can mean
that Java isn't an appropriate choice for a particular piece of software.
Java programs are compiled by the Java compiler into bytecode. The Java
virtual machine interprets this bytecode and executes the Java program.
The Java runtime environment (JRE) consists of the JVM and the Java class
libraries and contains the necessary functionality to start Java programs.
v
B.Tech. 2018-2022
The JDK contains in addition the development tools necessary to create Java programs.
The JDK consists therefore of a Java compiler, the Java virtual machine, and the Java class
libraries.
Application Of Java :-
There are many places where Java is used in real world, starting from commercial e-
commerce website to android apps, from scientific application to financial applications like
electronic trading systems, from games like Minecraft to desktop applications like Eclipse,
Netbeans, and IntelliJ, from an open source library to J2ME apps etc. Let's see each of them in
more detail.
1) Android Apps
If you want to see where Java is used, you are not too far away. Open your Android
phone and any app, they are actually written in Java programming language, with Google's
Android API, which is similar to JDK. Couple of years back Android has provided much needed
boost and today many Java programmers are Android App developer. By the way android uses
different JVM and different packaging, as we have seen in our previous article about how
Android app works, but code is still written in Java.
Java is very big in Financial Services. Lots of global Investment banks like Goldman
Sachs, Citigroup, Barclays, Standard Charted and other banks use Java for writing front and back
office electronic trading system, writing settlement and confirmation systems, data
processing projects and several others. Java is mostly used to write server side application, mostly
without any front end, which receives data form one server (upstream), process it and sends it
other process (downstream). Java Swing was also popular for creating thick client GUIs for
traders, but now C# is quickly gaining market share on that space and Swing is out of its breath.
Java is also big on E commerce and web application space. You have a lot of RESTfull
services being created using Spring MVC, Struts 2.0 and similar frameworks. Even simple
Servlet, JSP and Struts based web applications are quite popular on various government projects.
vi
B.Tech. 2018-2022
Many of government, healthcare, insurance, education, defense and several other department have
their web application built in Java.
4) Software Tools
Many useful software and development tools are written and developed in Java e.g.
Eclipse, InetelliJ Idea and Netbans IDE. I think they are also most used desktop .applications
written in Java. Though there was time when Swing was very popular to write thick client, mostly
in financial service sector and Investment banks. Now days, Java FX is gaining popularity but still
it is not a replacement of Swing and C# has almost replaced Swing in Finance domain.
5) Trading Application
Third party trading application, which is also part of bigger financial services industry,
also use Java. Popular trading application like Murex, which is used in many banks for front to
bank connectivity, is also written in Java.
6) J2ME Apps
Though advent of iOS and Android almost killed J2ME market, but still there is large
market of low end Nokia and Samsung handset which uses J2ME. There was time when almost
all games, application, which is available in Android are written using MIDP and CLDC, part of
J2ME platform. J2ME is still popular on products like Blu-ray, Cards, Set top boxes etc. One of
the reason of WhatsApp being so popular is because it is also available in J2ME for all those
Nokia handset which is still quite big.
7) Embedded Space
Java is also big in the embedded space. It shows how capable the platform is, you only
need 130 KB to be able to use Java technology (on a smart card or sensor). Originally Java was
designed for embedded devices. In fact, this is the one area, which was part of Java's initial
campaign of "write once, run anywhere" and looks like it is paying up now.
Hadoop and other big data technologies are also using Java in one way or other e.g.
Apache's Java-based HBase and Accumulo (open source), and ElasticSearch as well. By the Java
is not dominating this space, as there are technologies like MongoDB which is written in C++.
Java has potential to get major share on this growing space if Hadoop or ElasticSearch goes big.
vii
B.Tech. 2018-2022
Java platform has improved its performance characteristics a lot and with modern JITs, its
capable of delivering performance at C++ level. Due to this reason, Java is also popular on
writing high performance systems, because Though performance is little less compared to native
language, but you can compromise safety, portability and maintainability for more speed and it
only takes one inexperienced C++ programmer to make an application slow and unreliable.
Nowadays Java is often a default choice for scientific applications, including natural
language processing. Main reason of this is because Java is more safe, portable, maintainable and
comes with better high-level concurrency tools than C++ or any other language.
viii
B.Tech. 2018-2022
PREREQUISITES:-
Package
Java groups classes into functional packages.
Packages are typically used to group classes into logical units. For example all graphical
views of an application might be placed in the same package called
com.vogella.webapplication.views.
It is common practice to use the reverse domain name of the company as top level
package. For example the company might own the domain, vogella.com and in this example the
Java packages of this company starts with com.vogella.
Other main reason for the usage of packages is to avoid name collisions of classes. A
name collision occurs if two programmers give the same fully qualified name to a class. The
fully qualified name of a class in Java consists out of the package name followed by a dot (.) and
the class name.
Without packages, a programmer may create a Java class called Test. Another
programmer may create a class with the same name. With the usage of packages you can tell the
system which class to call. For example if the first programmer puts the Test class into package
report and the second programmer puts his class into package xmlreader you can distinguish
between these classes by using the fully qualified name, e.g. xmlreader.Test or report.Test.
Class
Def.: Template that describes the data and behavior associated with an instance of that class.
In Java source code a class is defined by the class keyword and must start with a capital
letter. The body of a class is surrounded by {}.
package test;
class MyClass {
ix
B.Tech. 2018-2022
}
The data associated with a class is stored in variables ; the behavior associated to a class
or object is implemented with methods.
A class is contained in a Java source file with the same name as the class plus the .java
extension.
Object
The object is the real element which has data and can perform actions. Each
object is created based on the class definition.
Instance variable
Instance variable is associated with an instance of the class (also called object).
Access works over these objects.
Instance variables can have any access control and can be marked final or transient.
Instance variables marked as final can not be changed after assigned to a value.
x
B.Tech. 2018-2022
Local variable
Local (stack) variable declarations cannot have access modifiers.
final is the only modifier available to local variables. This modifier defines that the
variable can not be changed after first assignment.
Local variables do not get default values, so they must be initialized before use.
Methods
A method is a block of code with parameters and a return value. It can be called on
the object.
System.out.println("Hello World");
Method can be declared with var-args. In this case the method declares a parameter
which accepts from zero to many arguments (syntax: type .. name;) A method can only
have one var-args parameter and this must be the last parameter in the method.
xi
B.Tech. 2018-2022
Main method
A public static method with the following signature can be used to start a Java
application. Such a method is typically called main method.
Constructor
A class contains constructors that are invoked to create objects based on the class
definition. Constructor declarations look like method declarations except that they use the
name of the class and have no return type. A class can have several constructors with
different parameters. Each class must define at least one constructor. In the following
example the constructor of the class expects a parameter.
package com.vogella.javaintro.base;
String s;
public MyConstructorExample2(String s) {
this.s = s;
}
xii
B.Tech. 2018-2022
In the following example the definition of the constructor without parameters (also
known as the empty constructor) is unnecessary. If not specified the compiler would
create one.
package com.vogella.javaintro.base;
public MyConstructorExample() {
Every object is created based on a constructor. This constructor method is the first
statement called before anything else can be done with the object.
Access modifiers
There are three access modifiers keywords available in Java. public, protected and
private. There are four access levels: public, protected, default and private. They define
how the corresponding element is visible to other components. If something is declared
public, e.g. classes or methods can be freely created or called by other Java objects. If
something is declared private, e.g. a method, it can only be accessed within the class in
xiii
B.Tech. 2018-2022
which it is declared. protected and default are similar. A protected class can be accessed
from the package and sub-classes outside the package while a default class can get only
accessed via the same package. The following table describes the visibility:
Public Y Y Y Y
protected Y Y Y N
no
Y Y N N
modifier
Private Y N N N
Import statements
Usage of import statements
In Java you have to access a class always via its full-qualified name, e.g. the package
name and the class name. You can add import statements for classes or packages into your class
file, which allow you to use the related classes in your code without the package qualifier.
Static imports
Static import is a feature that allows members (fields and methods) which are
defined in a class with the public static access modifier to be used in Java code without
specifying the class in which the member is defined. The feature provides a typesafe
xiv
B.Tech. 2018-2022
mechanism to include constants into code without having to reference the class that
originally defined the field.
xv
B.Tech. 2018-2022
INHERITANCE :-
What is inheritance?
A class can be derived from another class. In this case this class is called a
subclass. Another common phrase is that a class extends another class.
Inheritance allows a class to inherit the behavior and data definitions of another
class. The following codes demonstrates how a class can extend another class. In Java a
class can extend a maximum of one class.
package com.vogella.javaintro.base;
class MyBaseClass {
void hello(){
xvi
B.Tech. 2018-2022
In java, by default, the Object class is the parent class. In Java inheritance is
declared using the extends keyword.
Important terminology:
Super Class: The class whose features are inherited is known as super class(or a
base class or a parent class).
Sub Class: The class that inherits the other class is known as sub class(or a
derived class, extended class, or child class). The subclass can add its own fields
and methods in addition to the superclass fields and methods.
How it is done?
On the basis of class, there can be three types of inheritance in java: single,
multilevel and hierarchical. In java programming, multiple and hybrid inheritance is
supported through interface only. We will learn about interfaces later.
xvii
B.Tech. 2018-2022
1. Single Inheritance : In single inheritance, subclasses inherit the features of one
superclass. In image below, the class A serves as a base class for the derived class
B.
import java.util.*;
import java.lang.*;
xviii
B.Tech. 2018-2022
import java.io.*;
class one
{
System.out.println("Geeks");
}
{
System.out.println("for");
}
// Driver class
{
xix
B.Tech. 2018-2022
g.print_geek();
g.print_for();
g.print_geek();
}
Output:
Geeks
for
Geeks
xx
B.Tech. 2018-2022
import java.util.*;
import java.lang.*;
import java.io.*;
class one
{
System.out.println("Geeks");
}
xxi
B.Tech. 2018-2022
{
System.out.println("for");
}
{
System.out.println("Geeks");
}
// Drived class
xxii
B.Tech. 2018-2022
{
g.print_geek();
g.print_for();
g.print_geek();
}
Output:
Geeks
for
Geeks
xxiii
B.Tech. 2018-2022
import java.util.*;
import java.lang.*;
import java.io.*;
class one
{
System.out.println("Geeks");
}
{
System.out.println("for");
}
xxiv
B.Tech. 2018-2022
/*............*/
// Drived class
{
g.print_geek();
t.print_for();
g.print_geek();
}
Output:
Geeks
xxv
B.Tech. 2018-2022
for
Geeks
xxvi
B.Tech. 2018-2022
ADVANTAGES OF JAVA
Simple: Java was designed to be easy to use, write, compile, debug, and learn than other
programming languages. Java is much simpler than C++ because Java uses automatic
memory allocation and garbage collection.
Platform-Independent: Java offers the comfort of write program once and run on any
hardware and software platform and any Java compatible browser. This gives the ability to
move easily from one computer system to another.
Secure: Java is the first programming language to include security an integral part of the
design. Java’s compiler, interpreter, and runtime environment were each developed with
security in mind. Java Virtual Machine has a unique identifier that identifies the bytecode and
verifies it before running it.
Allocation: Java has the feature of Stack allocation system. It follows LIFO (Last in First
Out) which helps the data to be stored and retrieved easily.
Rich APIs: Java offers various APIs for application development. Java APIs (Application
Programming Interface) is the set of commands or methods of communication among various
activities like Database connection, networking, I/O, XML parsing, utilities, and much more.
xxvii
B.Tech. 2018-2022
Powerful Open source Rapid Development Tools: Over the year’s several open source
development tools i.e., IDEs such as Eclipse and Netbeans, have been created with Java as a
base which makes Java more powerful for application development. IDEs makes application
development simpler with powerful coding and debugging features.
Robust: Java is one of the most robust programming languages, that is Java is more reliable.
Java compilers can detect any errors in the coding. There are also other features like
exception handling and garbage collection which makes Java more robust.
Resource Availability: There are tons of online java training courses available to learn java.
You don’t have to spend a fortune to learn java programming.
DISADVANTAGES OF JAVA
Look and feel: The default look and feel of GUI applications written in Java using the Swing
toolkit is very different from native applications.
xxviii
B.Tech. 2018-2022
CONCLUSION
This report covers the common advantages and disadvantages to give you an
overview of the Java programming language. Understanding this will help you to learn Java
programming easily. In our Java programming tutorial, we discuss more on how to utilize
these advantages to create wonderful front-end of back-end applications using Java. To learn
more about Java, select from a list of Online Java training courses available and listed below
are some of the best java programming books for beginners and advanced users to maximize
the advantages of Java Programming.
xxix
B.Tech. 2018-2022
REFERENCES
[1] Horstmann, Cay S., and Gary Cornell. Core Java 2: Volume I, Fundamentals. Pearson Education,
2002.
[2] Jeffrey, Alan, and Julian Rathke. "Java Jr: Fully abstract trace semantics for a core Java language."
In European symposium on programming, pp. 423-438. Springer, Berlin, Heidelberg, 2005.
[3] DeCarmo, Linden. Core Java media framework. Prentice Hall PTR, 1999.
[4] Tyagi, Sameer. Core java data objects. Prentice Hall Professional, 2003.
xxx