0% found this document useful (0 votes)
32 views

Computer Science - Java - C3 - Note 1

This document provides an overview of the Java programming language course. It defines Java as a programming language and platform, originally developed by Sun Microsystems. The document outlines key features of Java like being simple, object-oriented, portable, platform independent, secure, robust, architecture neutral, interpreted, high-performance, multithreaded, and distributed. It also compares Java to C++ and describes data types, the Java virtual machine, the differences between JDK, JRE, and JVM, objects, classes, and ways to create objects in Java.

Uploaded by

Abhishek Gorai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Computer Science - Java - C3 - Note 1

This document provides an overview of the Java programming language course. It defines Java as a programming language and platform, originally developed by Sun Microsystems. The document outlines key features of Java like being simple, object-oriented, portable, platform independent, secure, robust, architecture neutral, interpreted, high-performance, multithreaded, and distributed. It also compares Java to C++ and describes data types, the Java virtual machine, the differences between JDK, JRE, and JVM, objects, classes, and ways to create objects in Java.

Uploaded by

Abhishek Gorai
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

COMPUTER SCIENCE (C-III): Programming in Java

COURSE CODE: SH /CSC/ 201/C-3

 What is Java?
Java is a programming language and a platform. Java is a high level, robust,
object-oriented and secure programming language.

Java was developed by Sun Microsystems in the year 1995. James


Gosling is known as the father of Java. Before Java, its name was Oak. Since
Oak was already a registered company, so James Gosling and his team changed
the Oak name to Java.

Platform: Any hardware or software environment in which a program runs, is


known as a platform. Since Java has a runtime environment (JRE) and API, it is
called a platform.

 Features of Java:
The primary objective of Java programming language creation was to make it
portable, simple and secure programming language.

A list of most important features of Java language is given below:

1. Simple: Java is very easy to learn, and its syntax is simple, clean and
easy to understand. According to Sun, Java language is a simple
programming language because:

 Java syntax is based on C++ (so easier for programmers to learn it


after C++).
 There is no need to remove unreferenced objects because there is
an Automatic Garbage Collection in Java.

2. 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

Department Of Computer Science, Sonamukhi College Page 1


 Encapsulation

3. Portable: Java is portable because it facilitates you to carry the Java byte
code to any platform. It doesn't require any implementation.
4. Platform independent: Java is platform independent because it is
different from other languages like C, C++, etc. which are compiled into
platform specific machines while Java is a write once, run anywhere
language. A platform is the hardware or software environment in which a
program runs.
5. Secured: Java is best known for its security. With Java, we can develop
virus-free systems.
6. Robust: Robust simply means strong. Java is robust because:

o It uses strong memory management.


o There is a lack of pointers that avoids security problems.

7. Architecture neutral: Java is architecture neutral because there are no


implementation dependent features, for example, the size of primitive
types is fixed.
8. Interpreted: Java is an interpreted language that is why it is slower than
compiled languages, e.g., C, C++, etc.
9. High Performance: Java is faster than other traditional interpreted
programming languages because Java byte code is "close" to native code.
It is still a little bit slower than a compiled language (e.g., C++).
10.Multithreaded: A thread is like a separate program, executing
concurrently. We can write Java programs that deal with many tasks at
once by defining multiple threads. Threads are important for multi-media,
Web applications, etc.
11.Distributed: Java is distributed because it facilitates users to create
distributed applications in Java. This feature of Java makes us able to
access files by calling the methods from any machine on the internet .
12.Dynamic: Java is a dynamic language. It supports dynamic loading of
classes. It means classes are loaded on demand.

Department Of Computer Science, Sonamukhi College Page 2


 Difference between C++ and Java:

C++ JAVA
i) C++ is platform-dependent. i) Java is platform-independent.
ii) C++ is mainly used for system programming. ii) Java is mainly used for application programming.

iii) C++ supports multiple inheritances. iii) It doesn't support multiple inheritance.

iv) C++ supports operator overloading. iv) It doesn't support operator overloading.

V) C++ supports structures and union. V) Does not support structures and unions.

First Java Program | Hello World Example


Let's create the hello java program:

class Simple{
public static void main(String args[]){
System.out.println("Hello Java");
}
}
save this file as Simple.java

To compile: javac Simple.java

To execute: java Simple

Output: Hello Java

 Data Types in Java:


There are two types of data types in Java:

o Primitive data types: The primitive data types include boolean, char,
byte, short, int, long, float and double.
o Non-primitive data types: The non-primitive data types
include Classes, Interfaces, and Arrays.

 Java virtual machine(JVM):


Java Virtual Machine is a virtual machine that enables the computer to
run the Java program. JVM acts like a run-time engine which calls the
main method present in the Java code. JVM is the specification which
must be implemented in the computer system. The Java code is compiled

Department Of Computer Science, Sonamukhi College Page 3


by JVM to be a Byte code which is machine independent and close to the
native code.
 What is the difference between JDK, JRE, and JVM?

JVM
JVM is an acronym for Java Virtual Machine; it is an abstract machine which
provides the runtime environment in which Java bytecode can be executed. It is
a specification which specifies the working of Java Virtual Machine. JVMs are
available for many hardware and software platforms (so JVM is platform
dependent). It is a runtime instance which is created when we run the Java class.

JRE
JRE stands for Java Runtime Environment. It is the implementation of JVM.
The Java Runtime Environment is a set of software tools which are used for
developing Java applications. It is used to provide the runtime environment. It
physically exists.

JDK
JDK is an acronym for Java Development Kit. It is a software development
environment which is used to develop Java applications and applets. It
physically exists. It contains JRE + development tools.

 What is an object in Java?


An entity that has state and behaviour is known as an object e.g., chair, bike,
marker, pen, table, car, etc. It can be physical or logical (tangible and
intangible). The example of an intangible object is the banking system.

An object is an instance of a class.

An object has three characteristics:

o State: represents the data (value) of an object.


o Behaviour: represents the behaviour (functionality) of an object such as
deposit, withdraw, etc.
o Identity: An object identity is typically implemented via a unique ID.
The value of the ID is not visible to the external user. However, it is used
internally by the JVM to identify each object uniquely.

For Example, Pen is an object. Its name is Reynolds; colour is white,


known as its state. It is used to write, so writing is its behaviour.

Department Of Computer Science, Sonamukhi College Page 4


 What is a class in Java?
A class is a group of objects which have common properties. It is a template or
blueprint from which objects are created. It is a logical entity. It can't be
physical.

A class in Java can contain:

o Fields
o Methods
o Constructors
o Blocks
o Nested class and interface

 What are the different ways to create an object in Java?


There are many ways to create an object in java. They are:

o By new keyword
o By new Instance() method
o By clone() method
o By factory method etc.

Subhajit Dey

Guest Lecturer

Department of Computer Science

Sonamukhi College

Department Of Computer Science, Sonamukhi College Page 5

You might also like