0% found this document useful (0 votes)
66 views17 pages

SPOILER Introduction To Java 11

Uploaded by

Doton Dutta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
66 views17 pages

SPOILER Introduction To Java 11

Uploaded by

Doton Dutta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 17

Introduction

to Java

7 JULY 2021
Contents
What is Java
Why should we learn it
Few basic terms
Basic concepts of OOPs
Tokens, Identifiers, Literals
Primitive Data Types, Non-Primitive Data Types
Variables
Addition, subtraction, multiplication
Scanner Class
Few basic programs
What is Java?
Java is a programming language and computing platform first released by Sun Microsystems in
1995. There are lots of applications and websites that will not work unless you have Java installed,
and more are created every day. Java is fast, secure, and reliable. From laptops to data centers,
game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere!
https://java.com/en/download/help/whatis_java.html Click to
See More

Java is Used In -

And Much More


Click to
See More
Mobile App Development Desktop app Web applications Web servers and Games
application servers
Why we use it ?
1 2 3 4
Java is easy to learn. Java is object- Java is platform- Java is open-source
oriented. independent
Java was designed to be This allows you to create One of the most significant It is open source and free as
easy to use and is therefore modular programs and advantages of Java is its well as secure, fast and
easy to write, compile, reusable code. ability to move easily from powerful. It has a huge
debug, and learn than other one computer system to community support.
programming languages. another. The ability to run
the same program on many
systems is crucial to World
Wide Web software,
JDK, JVM, JRE, JIT

JDK JVM JRE JIT

The Java Development Kit Java Virtual machine(JVM) is a Java Runtime Environment The Just-In-Time (JIT) compiler
(JDK) is a software very important part of both (JRE) is an installation is a component of the runtime
development environment JDK and JRE because it is package which provides an environment that improves
used for developing Java contained or inbuilt in both. environment to only run(not the performance of Java™
applications and applets. It Whatever Java program you develop) the Java program(or applications by compiling
includes the Java Runtime run using JRE or JDK goes into application)onto your bytecodes to native machine
Environment (JRE), an JVM and JVM is responsible for machine. JRE is only used by code at run time.
interpreter/loader (Java), a executing the Java program them who only wants to run
compiler (javac), an archiver line by line, hence it is also the Java Programs, i.e. end More On JIT Click to
(jar), a documentation known as interpreter. users of your system. See More
generator (Javadoc) and other
tools needed in Java
development.
Basic concepts
of OOP
Object Oriented programming (OOP) is a programming paradigm that relies on the concept of
classes and objects. It is used to structure a software program into simple, reusable pieces of code
blueprints (usually called classes), which are used to create individual instances of objects.

Object
An entity that has state and behavior is known as an object e.g.,
chair, bike, marker, pen, table, car, etc. It can be physical or logical
(tangible and intangible).

Class
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.
Inheritance Abstraction
Inheritance in Java is a mechanism in which one object Abstraction is a process of hiding the implementation details
acquires all the properties and behaviors of a parent object. and showing only functionality to the user.

Polymorphism Encapsulation
Polymorphism in Java is a concept by which we can perform Encapsulation in Java is a mechanism of wrapping the data
a single action in different ways. Polymorphism is derived (variables) and code acting on the data (methods) together
from 2 Greek words: poly and morphs. The word "poly" as a single unit. In encapsulation, the variables of a class will
means many and "morphs" means forms. So polymorphism be hidden from other classes, and can be accessed only
means many forms. through the methods of their current class. Therefore, it is
There are two types of polymorphism in Java: compile-time also known as data hiding.
polymorphism and runtime polymorphism. We can perform
polymorphism in Java by method overloading and method
overriding.
Hello World Of Java
public class Introduction
{
public static void main(String args[])
{
System.out.println(“Hello World”);
}
}
Tokens
In Java, a program contains classes and methods. Further, the methods contain the expressions and
statements required to perform a specific operation. These statements and expressions are made up of
tokens. In other words, we can say that the expression and statement is a set of tokens. The tokens are
the small building blocks of a Java program that are meaningful to the Java compiler.

The Java compiler breaks the line of code into text or words is called Java tokens. These are the smallest
element of the Java program. The Java compiler identified these words as tokens.
Java tokens includes the following :

a) Keywords: These are the pre-defined reserved words of any programming language. Each keyword
has a special meaning. It is always written in lowercase. For ex – class , char, float etc.

b) Identifier: Identifiers are used to name a variable, constant, function, class, and array. It usually
defined by the user. It uses letters, underscores, or a dollar sign as the first character. We must
remember that the identifier name must be different from the reserved
keywords.
There are some rules to declare identifiers are:
The first letter of an identifier must be a letter, underscore or a dollar sign. It cannot start with digits
but may contain digits.
The whitespace cannot be included in the identifier.
Identifiers are case-sensitive For ex- Phone Number, sum, entry_13 etc,
c) Literals: Literal is a notation that represents a fixed value (constant) in the source code. It can
be categorized as an integer literal, String literal, Boolean literal, etc. Java provides five types of
literals are as follows: integer, floating point, character, string, boolean
For ex – 23 is an int type literal , c is a char type literal , Computer is a String type literal etc.

d) Operators: Operators are the special symbol that tells the compiler to perform a special
operation. Java provides different types of operators that can be classified according to their
functionality. There are eight types of operators in Java, as follows :
Arithmetic, Assignment, Relational, Unary, Logical, Ternary, Bitwise, Shift
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/opsummary.html Click to
See More
Primitive and non-
primitive data types
Primitive Data types - Primitive data types are the basic or fundamental data types used to declare a variable.
For example - char, byte, short, int, long, float, double.

Non-primitive Data Types- A non-primitive data type is one that is derived from Primitive data types. A
number of primitive data types are used together to represent a non-primitive data type. For example - String,
Array.
Variables
A variable is a container which holds the value while the Java program is executed, which is assigned with a data type.
Variable is a name of a memory location.

The Java programming language defines the following kinds of variables:

Instance Variables (Non-Static Fields) Technically speaking, objects store their individual states in "non-static
fields", that is, fields declared without the static keyword. Non-static fields are also known as instance variables
because their values are unique to each instance of a class (to each object, in other words); the currentSpeed of one
bicycle is independent of the currentSpeed of another.

Class Variables (Static Fields) A class variable is any field declared with the static modifier; this tells the compiler
that there is exactly one copy of this variable in existence, regardless of how many times the class has been
instantiated. A field defining the number of gears for a particular kind of bicycle could be marked as static since
conceptually the same number of gears will apply to all instances. The code static int numGears = 6; would create
such a static field. Additionally, the keyword final could be added to indicate that the number of gears will never
change.
Variables
Local Variables Similar to how an object stores its state in fields, a method will often store its temporary state in
local variables. The syntax for declaring a local variable is similar to declaring a field (for example, int count = 0;).
There is no special keyword designating a variable as local; that determination comes entirely from the location in
which the variable is declared — which is between the opening and closing braces of a method. As such, local
variables are only visible to the methods in which they are declared; they are not accessible from the rest of the
class.

Parameters You've already seen examples of parameters, both in the Bicycle class and in the main method of the
"Hello World!" application. Recall that the signature for the main method is public static void main(String[] args).
Here, the args variable is the parameter to this method. The important thing to remember is that parameters are
always classified as "variables" not "fields".

More on Variables Click to


See More
Let's do some coding with
Variables and Operators

Time to make your hands dirty


Scanner Class
Scanner is a class in java.util package used for obtaining the input of the primitive types like int,
double, etc. and strings. It is the easiest way to read input in a Java program, though it's not very
efficient .

It can parse primitive types and strings using regular expressions.

For example, this code allows a user to read a number from System.in:

Scanner sc = new Scanner(System.in); More on Scanner Click to


int i = sc.nextInt() See More
Thank you!

For questions, requests and anything else


we can help you with contact us through the query channel

You might also like