0% found this document useful (0 votes)
2 views41 pages

Lecture 1

The document provides an introduction to Core Java, covering its history, features, and the differences between JDK, JRE, and JVM. It explains Object-Oriented Programming concepts, Java's basic data types, operators, and control statements such as if, switch, and loops. Additionally, it includes example codes and interview questions related to Java programming.

Uploaded by

dayesal322
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views41 pages

Lecture 1

The document provides an introduction to Core Java, covering its history, features, and the differences between JDK, JRE, and JVM. It explains Object-Oriented Programming concepts, Java's basic data types, operators, and control statements such as if, switch, and loops. Additionally, it includes example codes and interview questions related to Java programming.

Uploaded by

dayesal322
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 41

Lecture 1

• Core Java: Introduction


• Operator
• Data type
History of Java

• Java is an Object-Oriented
programming language developed by James
Gosling in the early 1990s.
• The team initiated this project to develop a
language for digital devices such as set-top
boxes, television, etc.
• Originally C++ was considered to be used in the
project but the idea was rejected for several
reasons.
• James Gosling and his team called their project
“Greentalk” and its file extension was .gt and
later became to known as “OAK”.
History of various Java versions
VERSION RELEASE DATE
JDK Beta 1995
JDK 1.0 January 1996
JDK 1.1 February 1997
J2SE 1.2 December 1998
J2SE 1.3 May 2000
J2SE 1.4 February 2002
J2SE 5.0 September 2004
JAVA SE 6 December 2006
JAVA SE 7 July 2011
JAVA SE 8 March 2014
JAVA SE 9 September 2017
JAVA SE 10 March 2018
JAVA SE 11 September 2018
JAVA SE 12 March 2019
Features of Java
• Object Oriented : In java everything is an Object.
• Platform independent: Unlike many other
programming languages including C and C++
when Java is compiled, it is not compiled into
platform specific machine, rather into platform
independent byte code.
• Simple :Java is designed to be easy to learn. If
you understand the basic concept of OOP java
would be easy to master.
• Secure : With Java's secure feature it enables to
develop virus-free, tamper-free systems.
• Architectural- neutral :Java compiler generates an
architecture-neutral object file format which
makes the compiled code to be executable on
many processors.
• Portable :being architectural neutral and having
no implementation dependent aspects of the
specification makes Java portable.
• Robust :Java makes an effort to eliminate error
prone situations by emphasizing mainly on
compile time error checking and runtime checking.
• Multi-threaded : With Java's multi-threaded
feature it is possible to write programs that can do
many tasks simultaneously.
• Interpreted :Java byte code is translated on
the fly to native machine instructions and is
not stored anywhere.
• Distributed :Java is designed for the
distributed environment of the internet.
Difference between JDK, JRE and JVM
JVM
• JVM (Java Virtual Machine) is an abstract
machine. It is a specification that provides
runtime environment in which java byte code
can be executed.
• JVMs are available for many hardware and
software platforms. JVM, JRE and JDK are
platform dependent because configuration of
each OS differs. But, Java is platform
independent.
JRE
• JRE is an acronym for Java Runtime
Environment.
• It is used to provide runtime environment. It is
the implementation of JVM.
• It physically exists.
• It contains set of libraries + other files that
JVM uses at runtime.
JRE
JDK

• JDK is an acronym for Java Development Kit.It physically


exists.It contains JRE + development tools.
Java
• Java is a class based high level object oriented
programming language developed by James gosling and
his friend in 1991.
• The first version of java (jdk1.0) was released on the
year 23rd jan 1996 by sun microsystem.
• Syntax:-
• Class class _name
{ public static void main(String args[])
{
system.out.print(“ ”);
}
}
OOPs (Object Oriented Programming System)

• Object means a real word entity such as pen, chair,


table etc. Object-Oriented Programming is a
methodology or paradigm to design a program using
classes and objects. It simplifies the software
development and maintenance by providing some
concepts:
• Object
• Class
• Inheritance
• Polymorphism
• Abstraction
• Encapsulation
Object - Objects have states and behaviors.
Example: A dog has states - color, name, breed
as well as behaviours -wagging, barking,
eating. An object is an instance of a class.
Class - A class can be defined as a template/blue
print that describes the behaviors/states that
object of its type support
Inheritance
When one object acquires all the properties and
behaviours of parent object i.e. known as
inheritance. It provides code reusability. It is
used to achieve runtime polymorphism.
Polymorphism
• When one task is performed by different ways i.e. known as
polymorphism. For example. shape or rectangle etc.
• In java, we use method overloading and method overriding to
achieve polymorphism.
Abstraction
• Hiding internal details and showing functionality is known as
abstraction. For example: phone call, we don't know the internal
processing.
• In java, we use abstract class and interface to achieve abstraction.
Encapsulation
• Binding (or wrapping) code and data together into a single unit
is known as encapsulation. For example: capsule, it is wrapped
with different medicines.
• A java class is the example of encapsulation. Java bean is the fully
encapsulated class because all the data members are private
here.
Interview Questions Asked in different Company
1. What do you understand by Java virtual
machine? [Infosys,TCS,IBM]
2. What is object-oriented programming
system? [TCS]
3. What is the difference between JDK,
JRE, and JVM? [Infosys].
Java Basic Data Types

There are two data types available in Java:


• Primitive Data Types
• Reference/Object Data Types
Primitive Data Types:
• There are eight primitive data types supported
by Java. Primitive data types are predefined by
the language and named by a key word.
byte:
• Minimum value is -128 (-2^7)
• Maximum value is 127 (inclusive)(2^7 -1)
short:
• Minimum value is -32,768 (-2^15)
• Maximum value is 32,767(inclusive) (2^15 -1)
int:
• Minimum value is - 2,147,483,648.(-2^31)
• Maximum value is 2,147,483,647(inclusive).
(2^31 -1)
long:
• Minimum value is -
9,223,372,036,854,775,808.(-2^63)
• Maximum value is 9,223,372,036,854,775,807
(inclusive). (2^63 -1)
Interview Questions Asked in different Company

1. Name some OOPS Concepts in Java?


2. What do you mean by platform
independence of Java?[Infosys Interview]
3. What is JVM and is it platform independent?
4. What is the difference between JDK and
JVM? [Infosys Interview]
5. What is the difference between JVM and JRE?
Operators in java
Operator in java is a symbol that is used to perform
operations. For example: +, -, *, / etc.
There are many types of operators in java which are given
below:
• Unary Operator,
• Arithmetic Operator,
• Relational Operator,
• Logical Operator,
• Incre/decre
• Assignment Operator.
• Ternary Operator and
• Bitwise Operator
Java Unary Operator Example: ++ and --

class OperatorExample{
public static void main(String args[]){
int x=10;
System.out.println(x++);//10 (11)
System.out.println(++x);//12
System.out.println(x--);//12 (11)
System.out.println(--x);//10
}}
Output:
10
12
12
10
class Operator
{
public static void main(String args[])
{
int a=10;
int b=10;
System.out.println(a++ + ++a);//10+12=22
System.out.println(b++ + b++);//10+11=21
}
}
class OperatorExample{
public static void main(String args[]){
int a=10;
int b=5;
System.out.println(a+b);//15
System.out.println(a-b);//5
System.out.println(a*b);//50
System.out.println(a/b);//2
System.out.println(a%b);//0
}}
/* Arirhmetic operator...........................*/
Import java.util.Scanner;
class Operator {
public static void main(String args[]){
int a, b;
System.out.print(“Enter two number”);
Scanner o=new Scanner(System.in);
a=o.nextInt();
b=o.nextInt();
System.out.println(“Addition” +(a+b));
System.out.println(“Sub” +(a-b));
System.out.println(“Multi” +(a*b));
System.out.println(“Div” +(a/b));
System.out.println(“Rem” +(a%b));
}}
/*Relational Operator.................................*/
Import java.util.Scanner;
class Relational {
public static void main(String args[]){
int a, b;
System.out.print(“Enter two number”);
Scanner o=new Scanner(System.in);
a=o.nextInt();
b=o.nextInt();
System.out.println(“True/False” +(a<b));
System.out.println(“True/False” +(a>b));
System.out.println(“True/False” +(a<=b));
System.out.println(“True/False” +(a=>b));
System.out.println(“True/False” +(a==b));
System.out.println(“True/False” +(a!=b));
}}
Java AND Operator Example:
Logical && and Bitwise &

• The logical && operator doesn't check second


condition if first condition is false. It checks second
condition only if first one is true.
• The bitwise & operator always checks both conditions
whether first condition is true or false.
• Java OR Operator Example: Logical || and Bitwise |
• The logical || operator doesn't check second condition
if first condition is true. It checks second condition only
if first one is false.
• The bitwise | operator always checks both conditions
whether first condition is true or false.
/*Logical Operator.................................*/
class Logical {
public static void main(String args[]){
System.out.println(“Logical AND”);
System.out.println((10>5) && (2>1));
System.out.println((10>5) && (2<1));
System.out.println((10<5) && (2<1));
System.out.println(“Logical OR”);
System.out.println((10>5) || (2>1));
System.out.println((10>5) || (2<1));
System.out.println((10<5) || (2<1));
System.out.println(“Logical Not”);
System.out.println(!(10>5) );
System.out.println(!(10<5) );
}}
/*Incre/Decrement Operator...................*/
class PrePost {
public static void main(String args[]){
Int a=10;
System.out.println(a);
System.out.println(“PrePost Increment......”);
System.out.println(a++);
System.out.println(++a);
System.out.println(“PrePost Decrement......”);
System.out.println(a--);
System.out.println(--a);

}}
/*Assignment Operator...................*/
class Assignment
{
public static void main(String args[])
{
Int a;
a=10; //simple assignment
System.out.println(a);
a+=10; // compound assignment
System.out.println(a);
a-=10; // compound assignment
System.out.println(a);

}}
Java Ternary Operator
class OperatorExample{
public static void main(String args[]){
int a=2;
int b=5;
int min=(a<b)?a:b;
System.out.println(min);
}}
Output:
2
Java Bit wise Operator
class Bitwise {
public static void main(String[] args)
{
int a=5,b=7;
System.out.println(“AND” +(a&b));
System.out.println(“OR” +(a|b));
System.out.println(“XOR” +(a^b));
}
}
Java IF Statement
class simple
{
public static void main(String[] args)
{
int age;
System.out.print(“Enter age”);
Scanner r=new Scanner(System.in);
age=r.nextInt();
If(age>=18)
{
System.out.println(“Eligible for vote”);
}
System.out.print(“Thank you”);
}}
Java IF-Else Statement
Import java.util.Scanner;
class IFElse
{
public static void main(String[] args)
{
int n;
System.out.print(“Enter any number”);
Scanner r=new Scanner(System.in);
n=r.nextInt();
If(age>=0)
{
System.out.println(“Positive number”);
}
else
{
System.out.print(“- number”);
}
}}
Java ElseIF-ladder Statement
Import java.util.Scanner;
class ElseIF
{
public static void main(String[] args)
{
int marks;
System.out.print(“Enter marks”);
Scanner r=new Scanner(System.in);
marks=r.nextInt();
If(marks>90)
{
System.out.println(“Topper”);
}
elseif(marks<90 && marks>=60)
{
System.out.print(“First”);
}
else
{
System.out.print(“Second”);
}
}}
Java Nested if statement
• The nested if statement represents the if block within another if block. Here, the
inner if block condition executes only when outer if block condition is true.
• //Java Program to demonstrate the use of Nested If Statement.
• public class JavaNestedIfExample2 {
• public static void main(String[] args) {
• //Creating two variables for age and weight
• int age=25;
• int weight=48;
• //applying condition on age and weight
• if(age>=18){
• if(weight>50){
• System.out.println("You are eligible to donate blood");
• } else{
• System.out.println("You are not eligible to donate blood");
• }
• } else{
• System.out.println("Age must be greater than 18");
• }
• } }
• Java Switch Statement
• The Java switch statement executes one statement from multiple
conditions. It is like if-else-if ladder statement. The switch statement
works with byte, short, int, long, enum types, String and some wrapper
types like Byte, Short, Int, and Long. Since Java 7, you can use strings in
the switch statement.
• In other words, the switch statement tests the equality of a variable
against multiple values.
• There can be one or N number of case values for a switch expression.
• The case value must be of switch expression type only. The case value
must be literal or constant. It doesn't allow variables.
• The case values must be unique. In case of duplicate value, it renders
compile-time error.
• The Java switch expression must be of byte, short, int, long (with its
Wrapper type), enums and string.
• Each case statement can have a break statement which is optional. When
control reaches to the break statement, it jumps the control after the
switch expression. If a break statement is not found, it executes the next
case.
• The case value can have a default label which is optional.
public class SwitchExample {
public static void main(String[] args) {
//Declaring a variable for switch expression
int number=20;
//Switch expression
switch(number){
//Case statements
case 10: System.out.println("10");
break;
case 20: System.out.println("20");
break;
case 30: System.out.println("30");
break;
//Default case statement
default:System.out.println("Not in 10, 20 or 30");
}
}
}

You might also like