SlideShare a Scribd company logo
CORE JAVA
PRESENTRED BY:
PRIYANKA PRADHAN
ASSISTANT PROFESSOR
MJPRU,BAREILLY.
Priyanka Pradhan 1
What is Java?
โ€ข Java is a high-level programming language originally developed by Sun Microsystems and
released in 1995.
Java is:
๏ƒผ Object Oriented
๏ƒผ Platform independent:
๏ƒผ Simple
๏ƒผ Secure
๏ƒผ Architectural- neutral
๏ƒผ Portable
๏ƒผ Robust
๏ƒผ Multi-threaded
๏ƒผ Interpreted
๏ƒผ High Performance
๏ƒผ Distributed
๏ƒผ Dynamic
Priyanka Pradhan 2
Tools You Will Need
You will need the following softwares:
โ€ข Linux 7.1 or Windows xp/7/8 operating system
โ€ข Java JDK 8
โ€ข Microsoft Notepad or any other text editor
Priyanka Pradhan 3
Setting Up the Path for Windows
Assuming you have installed Java in c:Program
Filesjavajdk directory:
โ€ข Right-click on 'My Computer' and select 'Properties'.
โ€ข Click the 'Environment variables' button under the
'Advanced' tab.
โ€ข Now, alter the 'Path' variable so that it also contains
the path to the Java executable. Example, if the path is
currently set to 'C:WINDOWSSYSTEM32', then
change your path to read
'C:WINDOWSSYSTEM32;c:Program
Filesjavajdkbin'.
Priyanka Pradhan 4
Popular Java Editors
To write your Java programs, you will need a text editor.
โ€ข Notepad: On Windows machine, you can use any
simple text editor like Notepad (Recommended for this
tutorial), TextPad.
โ€ข Netbeans: A Java IDE that is open-source and free,
which can be downloaded from
http://www.netbeans.org/index.html.
โ€ข Eclipse: A Java IDE developed by the eclipse open-
source community and can be downloaded from
http://www.eclipse.org/.
Priyanka Pradhan 5
how to save the file, compile, and run
the program
โ€ข Open notepad and add the code.
โ€ข Save the file as: MyFirstJavaProgram.java.
โ€ข Open a command prompt window and go to the directory where you saved the class. Assume it's
C:.
โ€ข Type 'javac MyFirstJavaProgram.java' and press enter to compile your code. If there are no errors in
your code, the command prompt will take you to the next line (Assumption : The path variable is
set).
โ€ข Now, type ' java MyFirstJavaProgram ' to run your program.
โ€ข You will be able to see ' Hello World ' printed on the window.
C:> javac MyFirstJavaProgram.java
C:> java MyFirstJavaProgram
Hello World
Priyanka Pradhan 6
Basic Syntax
โ€ข Case Sensitivity - Java is case sensitive, which means identifier Helloand hello would have different
meaning in Java.
โ€ข Class Names - For all class names the first letter should be in Upper Case. If several words are used
to form a name of the class, each inner word's first letter should be in Upper Case.
โ€ข Example: class MyFirstJavaClass
โ€ข Method Names - All method names should start with a Lower Case letter. If several words are used
to form the name of the method, then each inner word's first letter should be in Upper Case.
Example: public void myMethodName()
โ€ข Program File Name - Name of the program file should exactly match the class name. When saving
the file, you should save it using the class name (Remember Java is case sensitive) and append
'.java' to the end of the name (if the file name and the class name do not match, your program will
not compile).
โ€ข Example: Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as
'MyFirstJavaProgram.java'
โ€ข public static void main(String args[]) - Java program processing starts from the main() method
which is a mandatory part of every Java program.
Priyanka Pradhan 7
Java Identifiers
โ€ข All Java components require names. Names used for classes,
variables, and methods are called identifiers.
โ€ข In Java, there are several points to remember about identifiers.
They are as follows:
โ€ข All identifiers should begin with a letter (A to Z or a to z), currency
character ($) or an underscore (_).
โ€ข After the first character, identifiers can have any combination of
characters.
โ€ข A key word cannot be used as an identifier.
โ€ข Most importantly, identifiers are case sensitive.
โ€ข Examples of legal identifiers: age, $salary, _value, __1_value.
โ€ข Examples of illegal identifiers: 123abc, -salary.
Priyanka Pradhan 8
Java Modifiers
It is possible to modify classes, methods, etc., by
using modifiers. There are two categories of
modifiers:
โ€ข Access Modifiers: default, public , protected,
private
โ€ข Non-access Modifiers: final, abstract, strictfp
Priyanka Pradhan 9
Java Variables
Following are the types of variables in Java:
โ€ข Local Variables
โ€ข Class Variables (Static Variables)
โ€ข Instance Variables (Non-static Variables)
Priyanka Pradhan 10
Java Arrays
โ€ข Arrays are objects that store multiple variables
of the same type. However, an array itself is
an object on the heap.
Priyanka Pradhan 11
Java Enums
โ€ข Enums were introduced in Java 5.0. Enums restrict a
variable to have one of only a few predefined values.
The values in this enumerated list are called enums.
โ€ข With the use of enums it is possible to reduce the
number of bugs in your code.
โ€ข For example, if we consider an application for a fresh
juice shop, it would be possible to restrict the glass size
to small, medium, and large. This would make sure that
it would not allow anyone to order any size other than
small, medium, or large.
Priyanka Pradhan 12
Java Keywords
These reserved words may not be used as constant
or variable or any other identifier names.
โ€ข abstract
โ€ข assert
โ€ข boolean
โ€ข break
โ€ข byte
โ€ข case
โ€ข catch
โ€ข char
Priyanka Pradhan 13
Comments in Java
โ€ข Java supports single-line and multi-line comments very similar to C
and C++. All characters available inside any comment are ignored by
Java compiler.
public class MyFirstJavaProgram{
/* This is my first java program.
* This is an example of multi-line comments.
*/
public static void main(String []args){
// This is an example of single line comment
System.out.println("Hello World");
}
}
Priyanka Pradhan 14
Inheritance
โ€ข In Java, classes can be derived from classes.
Basically, if you need to create a new class and
here is already a class that has some of the code
you require, then it is possible to derive your new
class from the already existing code.
โ€ข This concept allows you to reuse the fields and
methods of the existing class without having to
rewrite the code in a new class. In this scenario,
the existing class is called the superclass and the
derived class is called the subclass.
Priyanka Pradhan 15
Interfaces
โ€ข In Java language, an interface can be defined
as a contract between objects on how to
communicate with each other. Interfaces play
a vital role when it comes to the concept of
inheritance.
โ€ข An interface defines the methods, a deriving
class (subclass) should use. But the
implementation of the methods is totally up
to the subclass.
Priyanka Pradhan 16
Java โ€“ Objects & Classes
Java is an Object-Oriented Language. As a language that has
the Object-Oriented feature, Java supports the following
fundamental concepts:
โ€ข Polymorphism
โ€ข Inheritance
โ€ข Encapsulation
โ€ข Abstraction
โ€ข Classes
โ€ข Objects
โ€ข Instance
โ€ข Method
โ€ข Message Parsing
Priyanka Pradhan 17
Contdโ€ฆ
โ€ข Object - Objects have states and behaviors.
Example: A dog has states - color, name, breed as
well as behaviors โ€“ wagging the tail, barking,
eating. An object is an instance of a class.
โ€ข Class - A class can be defined as a
template/blueprint that describes the
behavior/state that the object of its type support.
Priyanka Pradhan 18
Objects in Java
โ€ข If we consider the real-world, we can find many
objects around us, cars, dogs, humans, etc. All
these objects have a state and a behavior.
โ€ข Software objects also have a state and a behavior.
A software object's state is stored in fields and
behavior is shown via methods.
โ€ข in software development, methods operate on
the internal state of an object and the object-to-
object communication is done via methods.
Priyanka Pradhan 19
Classes in Java
โ€ข A class is a blueprint from which individual objects are created.
public class Dog{
String breed;
int ageC;
String color;
void barking(){
}
void hungry(){
}
void sleeping(){
}
}
Priyanka Pradhan 20
Contdโ€ฆ
A class can contain any of the following variable types.
โ€ข Local variables: Variables defined inside methods,
constructors or blocks are called local variables. The
variable will be declared and initialized within the method
and the variable will be destroyed when the method has
completed.
โ€ข Instance variables: Instance variables are variables within a
class but outside any method. These variables are initialized
when the class is instantiated. Instance variables can be
accessed from inside any method, constructor or blocks of
that particular class.
โ€ข Class variables: Class variables are variables declared
within a class, outside any method, with the static keyword.
Priyanka Pradhan 21
Constructors
โ€ข Every class has a constructor.
โ€ข If we do not explicitly write a constructor for a class, the Java compiler
builds a default constructor for that class.
โ€ข Each time a new object is created, at least one constructor will be invoked.
The main rule of constructors is that they should have the same name as
the class. A class can have more than one constructor.
example of a constructor:
public class Puppy{
public Puppy(){
}
public Puppy(String name){
// This constructor has one parameter, name.
}
}
Priyanka Pradhan 22
Creating an Object
โ€ข In Java, the new keyword is used to create new
objects.
There are three steps when creating an object from
a class:
โ€ข Declaration: A variable declaration with a
variable name with an object type.
โ€ข Instantiation: The 'new' keyword is used to
create the object.
โ€ข Initialization: The 'new' keyword is followed by a
call to a constructor. This call initializes the new
object.
Priyanka Pradhan 23
Contdโ€ฆ
example of creating an object:
public class Puppy{
public Puppy(String name){
// This constructor has one parameter, name.
System.out.println("Passed Name is :" + name );
}
public static void main(String []args){
// Following statement would create an object myPuppy
Puppy myPuppy = new Puppy( "tommy" );
}
}
If we compile and run the above program, then it will produce the following result:
Passed Name is :tommy
Priyanka Pradhan 24
Accessing Instance Variables and
Methods
Instance variables and methods are accessed via created
objects.
/* First create an object */
ObjectReference = new Constructor();
/* Now call a variable as follows */
ObjectReference.variableName;
/* Now you can call a class method as follows */
ObjectReference.MethodName();
Priyanka Pradhan 25
how to access instance variables and
methods of a class
public class Puppy{
int puppyAge;
public Puppy(String name){
System.out.println("Name chosen is :" + name );
}
public void setAge( int age ){
puppyAge = age;
}
public int getAge( ){
System.out.println("Puppy's age is :" + puppyAge );
return puppyAge;
}
public static void main(String []args){
Puppy myPuppy = new Puppy( "tommy" );
myPuppy.setAge( 2 );
myPuppy.getAge( );
System.out.println("Variable Value :" + myPuppy.puppyAge );
}
Priyanka Pradhan 26
Java Package
โ€ข it is a way of categorizing the classes and
interfaces. When developing applications in
Java, hundreds of classes and interfaces will
be written, therefore categorizing these
classes is a must as well as makes life much
easier.
Priyanka Pradhan 27
Import Statements
โ€ข In Java if a fully qualified name, which includes
the package and the class name is given, then the
compiler can easily locate the source code or
classes. Import statement is a way of giving the
proper location for the compiler to find that
particular class.
โ€ข For example, the following line would ask the
compiler to load all the classes available in
directory java_installation/java/io:
โ€ข import java.io.*;
Priyanka Pradhan 28
Java โ€“ Basic Datatypes
There are two data types available in Java:
โ€ข Primitive Datatypes
โ€ข Reference/Object Datatypes
Priyanka Pradhan 29
Ad

More Related Content

What's hot (20)

Introduction to basics of java
Introduction to basics of javaIntroduction to basics of java
Introduction to basics of java
vinay arora
ย 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
mahir jain
ย 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programming
Elizabeth Thomas
ย 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
ย 
Training on Core java | PPT Presentation | Shravan Sanidhya
Training on Core java | PPT Presentation | Shravan SanidhyaTraining on Core java | PPT Presentation | Shravan Sanidhya
Training on Core java | PPT Presentation | Shravan Sanidhya
Shravan Sanidhya
ย 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
Ravi Kant Sahu
ย 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
arvind pandey
ย 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
Ram132
ย 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
Mahika Tutorials
ย 
Basic of Java
Basic of JavaBasic of Java
Basic of Java
Ajeet Kumar Verma
ย 
Java Programming
Java ProgrammingJava Programming
Java Programming
Elizabeth alexander
ย 
Lecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMLecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVM
manish kumar
ย 
Summer training presentation on "CORE JAVA".
Summer training presentation on "CORE JAVA".Summer training presentation on "CORE JAVA".
Summer training presentation on "CORE JAVA".
SudhanshuVijay3
ย 
Core java slides
Core java slidesCore java slides
Core java slides
Abhilash Nair
ย 
Introduction to Java -unit-1
Introduction to Java -unit-1Introduction to Java -unit-1
Introduction to Java -unit-1
RubaNagarajan
ย 
Setting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation FrameworkSetting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation Framework
valuebound
ย 
Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat Shahriyar
Abir Mohammad
ย 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
Sujit Majety
ย 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
Saba Ameer
ย 
The Evolution of Java
The Evolution of JavaThe Evolution of Java
The Evolution of Java
Fu Cheng
ย 
Introduction to basics of java
Introduction to basics of javaIntroduction to basics of java
Introduction to basics of java
vinay arora
ย 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
mahir jain
ย 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programming
Elizabeth Thomas
ย 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
ย 
Training on Core java | PPT Presentation | Shravan Sanidhya
Training on Core java | PPT Presentation | Shravan SanidhyaTraining on Core java | PPT Presentation | Shravan Sanidhya
Training on Core java | PPT Presentation | Shravan Sanidhya
Shravan Sanidhya
ย 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
Ravi Kant Sahu
ย 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
arvind pandey
ย 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
Ram132
ย 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika TutorialsCore Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
Mahika Tutorials
ย 
Lecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMLecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVM
manish kumar
ย 
Summer training presentation on "CORE JAVA".
Summer training presentation on "CORE JAVA".Summer training presentation on "CORE JAVA".
Summer training presentation on "CORE JAVA".
SudhanshuVijay3
ย 
Core java slides
Core java slidesCore java slides
Core java slides
Abhilash Nair
ย 
Introduction to Java -unit-1
Introduction to Java -unit-1Introduction to Java -unit-1
Introduction to Java -unit-1
RubaNagarajan
ย 
Setting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation FrameworkSetting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation Framework
valuebound
ย 
Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat Shahriyar
Abir Mohammad
ย 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
Sujit Majety
ย 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
Saba Ameer
ย 
The Evolution of Java
The Evolution of JavaThe Evolution of Java
The Evolution of Java
Fu Cheng
ย 

Similar to Core Java (20)

cs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptxcs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptx
mshanajoel6
ย 
Top 100 Java Interview Questions with Detailed Answers
Top 100 Java Interview Questions with Detailed AnswersTop 100 Java Interview Questions with Detailed Answers
Top 100 Java Interview Questions with Detailed Answers
Whizlabs
ย 
Presentation2.ppt java basic core ppt .
Presentation2.ppt  java basic core ppt .Presentation2.ppt  java basic core ppt .
Presentation2.ppt java basic core ppt .
KeshavMotivation
ย 
Java
JavaJava
Java
Zeeshan Khan
ย 
Java_notes.ppt
Java_notes.pptJava_notes.ppt
Java_notes.ppt
tuyambazejeanclaude
ย 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
sureshkumara29
ย 
Basic syntax
Basic syntaxBasic syntax
Basic syntax
Ducat India
ย 
Power Point Presentation on Core Java For the Beginers
Power Point Presentation on Core Java For the BeginersPower Point Presentation on Core Java For the Beginers
Power Point Presentation on Core Java For the Beginers
SHAQUIBHASAN2
ย 
Viva file
Viva fileViva file
Viva file
anupamasingh87
ย 
Lectupopplkmkmkkpompom-0ookoimmire 2.pdf
Lectupopplkmkmkkpompom-0ookoimmire 2.pdfLectupopplkmkmkkpompom-0ookoimmire 2.pdf
Lectupopplkmkmkkpompom-0ookoimmire 2.pdf
rtreduanur247
ย 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
DhanalakshmiVelusamy1
ย 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
apoorvams
ย 
Basic online java course - Brainsmartlabs
Basic online java course  - BrainsmartlabsBasic online java course  - Brainsmartlabs
Basic online java course - Brainsmartlabs
brainsmartlabsedu
ย 
UNIT 3- Java- Inheritance, Multithreading.pptx
UNIT 3- Java- Inheritance, Multithreading.pptxUNIT 3- Java- Inheritance, Multithreading.pptx
UNIT 3- Java- Inheritance, Multithreading.pptx
shilpar780389
ย 
Object Oriented Programming unit 1 content for students
Object Oriented Programming unit 1 content for studentsObject Oriented Programming unit 1 content for students
Object Oriented Programming unit 1 content for students
ASHASITTeaching
ย 
123 JAVA CLASSES, OBJECTS AND METHODS.ppt
123 JAVA CLASSES, OBJECTS AND METHODS.ppt123 JAVA CLASSES, OBJECTS AND METHODS.ppt
123 JAVA CLASSES, OBJECTS AND METHODS.ppt
mcjaya2024
ย 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Ayes Chinmay
ย 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept it
lokeshpappaka10
ย 
JAVA PPT -3 BY ADI.pdf
JAVA PPT -3 BY ADI.pdfJAVA PPT -3 BY ADI.pdf
JAVA PPT -3 BY ADI.pdf
Prof. Dr. K. Adisesha
ย 
Java Programming Fundamentals
Java Programming Fundamentals Java Programming Fundamentals
Java Programming Fundamentals
Dr. Rosemarie Sibbaluca-Guirre
ย 
cs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptxcs213Lecture_1 java programming oopsss.pptx
cs213Lecture_1 java programming oopsss.pptx
mshanajoel6
ย 
Top 100 Java Interview Questions with Detailed Answers
Top 100 Java Interview Questions with Detailed AnswersTop 100 Java Interview Questions with Detailed Answers
Top 100 Java Interview Questions with Detailed Answers
Whizlabs
ย 
Presentation2.ppt java basic core ppt .
Presentation2.ppt  java basic core ppt .Presentation2.ppt  java basic core ppt .
Presentation2.ppt java basic core ppt .
KeshavMotivation
ย 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
sureshkumara29
ย 
Basic syntax
Basic syntaxBasic syntax
Basic syntax
Ducat India
ย 
Power Point Presentation on Core Java For the Beginers
Power Point Presentation on Core Java For the BeginersPower Point Presentation on Core Java For the Beginers
Power Point Presentation on Core Java For the Beginers
SHAQUIBHASAN2
ย 
Lectupopplkmkmkkpompom-0ookoimmire 2.pdf
Lectupopplkmkmkkpompom-0ookoimmire 2.pdfLectupopplkmkmkkpompom-0ookoimmire 2.pdf
Lectupopplkmkmkkpompom-0ookoimmire 2.pdf
rtreduanur247
ย 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
apoorvams
ย 
Basic online java course - Brainsmartlabs
Basic online java course  - BrainsmartlabsBasic online java course  - Brainsmartlabs
Basic online java course - Brainsmartlabs
brainsmartlabsedu
ย 
UNIT 3- Java- Inheritance, Multithreading.pptx
UNIT 3- Java- Inheritance, Multithreading.pptxUNIT 3- Java- Inheritance, Multithreading.pptx
UNIT 3- Java- Inheritance, Multithreading.pptx
shilpar780389
ย 
Object Oriented Programming unit 1 content for students
Object Oriented Programming unit 1 content for studentsObject Oriented Programming unit 1 content for students
Object Oriented Programming unit 1 content for students
ASHASITTeaching
ย 
123 JAVA CLASSES, OBJECTS AND METHODS.ppt
123 JAVA CLASSES, OBJECTS AND METHODS.ppt123 JAVA CLASSES, OBJECTS AND METHODS.ppt
123 JAVA CLASSES, OBJECTS AND METHODS.ppt
mcjaya2024
ย 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Ayes Chinmay
ย 
Complete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept itComplete PPT about the Java lokesh kept it
Complete PPT about the Java lokesh kept it
lokeshpappaka10
ย 
Ad

More from Priyanka Pradhan (19)

Tomato disease detection using deep learning convolutional neural network
Tomato disease detection using deep learning convolutional neural networkTomato disease detection using deep learning convolutional neural network
Tomato disease detection using deep learning convolutional neural network
Priyanka Pradhan
ย 
Applet
AppletApplet
Applet
Priyanka Pradhan
ย 
Servlet
ServletServlet
Servlet
Priyanka Pradhan
ย 
Css
CssCss
Css
Priyanka Pradhan
ย 
Javascript
JavascriptJavascript
Javascript
Priyanka Pradhan
ย 
XML
XMLXML
XML
Priyanka Pradhan
ย 
programming with python ppt
programming with python pptprogramming with python ppt
programming with python ppt
Priyanka Pradhan
ย 
Image Processing Based Signature Recognition and Verification Technique Using...
Image Processing Based Signature Recognition and Verification Technique Using...Image Processing Based Signature Recognition and Verification Technique Using...
Image Processing Based Signature Recognition and Verification Technique Using...
Priyanka Pradhan
ย 
GrayBox Testing and Crud Testing By: Er. Priyanka Pradhan
GrayBox Testing and Crud Testing By: Er. Priyanka PradhanGrayBox Testing and Crud Testing By: Er. Priyanka Pradhan
GrayBox Testing and Crud Testing By: Er. Priyanka Pradhan
Priyanka Pradhan
ย 
The agile requirements refinery(SRUM) by: Priyanka Pradhan
The agile requirements refinery(SRUM) by: Priyanka PradhanThe agile requirements refinery(SRUM) by: Priyanka Pradhan
The agile requirements refinery(SRUM) by: Priyanka Pradhan
Priyanka Pradhan
ย 
Social tagging and its trend
Social tagging and its trendSocial tagging and its trend
Social tagging and its trend
Priyanka Pradhan
ย 
Behavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka PradhanBehavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka Pradhan
Priyanka Pradhan
ย 
software product and its characteristics
software product and its characteristicssoftware product and its characteristics
software product and its characteristics
Priyanka Pradhan
ย 
EDI(ELECTRONIC DATA INTERCHANGE)
EDI(ELECTRONIC DATA INTERCHANGE)EDI(ELECTRONIC DATA INTERCHANGE)
EDI(ELECTRONIC DATA INTERCHANGE)
Priyanka Pradhan
ย 
collaborative tagging :-by Er. Priyanka Pradhan
collaborative tagging :-by Er. Priyanka Pradhancollaborative tagging :-by Er. Priyanka Pradhan
collaborative tagging :-by Er. Priyanka Pradhan
Priyanka Pradhan
ย 
Deploying java beans in jsp
Deploying java beans in jspDeploying java beans in jsp
Deploying java beans in jsp
Priyanka Pradhan
ย 
SOFTWARE PROCESS MONITORING AND AUDIT
SOFTWARE PROCESS MONITORING AND AUDITSOFTWARE PROCESS MONITORING AND AUDIT
SOFTWARE PROCESS MONITORING AND AUDIT
Priyanka Pradhan
ย 
Pcmm
PcmmPcmm
Pcmm
Priyanka Pradhan
ย 
s/w metrics monitoring and control
s/w metrics monitoring and controls/w metrics monitoring and control
s/w metrics monitoring and control
Priyanka Pradhan
ย 
Tomato disease detection using deep learning convolutional neural network
Tomato disease detection using deep learning convolutional neural networkTomato disease detection using deep learning convolutional neural network
Tomato disease detection using deep learning convolutional neural network
Priyanka Pradhan
ย 
programming with python ppt
programming with python pptprogramming with python ppt
programming with python ppt
Priyanka Pradhan
ย 
Image Processing Based Signature Recognition and Verification Technique Using...
Image Processing Based Signature Recognition and Verification Technique Using...Image Processing Based Signature Recognition and Verification Technique Using...
Image Processing Based Signature Recognition and Verification Technique Using...
Priyanka Pradhan
ย 
GrayBox Testing and Crud Testing By: Er. Priyanka Pradhan
GrayBox Testing and Crud Testing By: Er. Priyanka PradhanGrayBox Testing and Crud Testing By: Er. Priyanka Pradhan
GrayBox Testing and Crud Testing By: Er. Priyanka Pradhan
Priyanka Pradhan
ย 
The agile requirements refinery(SRUM) by: Priyanka Pradhan
The agile requirements refinery(SRUM) by: Priyanka PradhanThe agile requirements refinery(SRUM) by: Priyanka Pradhan
The agile requirements refinery(SRUM) by: Priyanka Pradhan
Priyanka Pradhan
ย 
Social tagging and its trend
Social tagging and its trendSocial tagging and its trend
Social tagging and its trend
Priyanka Pradhan
ย 
Behavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka PradhanBehavioral pattern By:-Priyanka Pradhan
Behavioral pattern By:-Priyanka Pradhan
Priyanka Pradhan
ย 
software product and its characteristics
software product and its characteristicssoftware product and its characteristics
software product and its characteristics
Priyanka Pradhan
ย 
EDI(ELECTRONIC DATA INTERCHANGE)
EDI(ELECTRONIC DATA INTERCHANGE)EDI(ELECTRONIC DATA INTERCHANGE)
EDI(ELECTRONIC DATA INTERCHANGE)
Priyanka Pradhan
ย 
collaborative tagging :-by Er. Priyanka Pradhan
collaborative tagging :-by Er. Priyanka Pradhancollaborative tagging :-by Er. Priyanka Pradhan
collaborative tagging :-by Er. Priyanka Pradhan
Priyanka Pradhan
ย 
Deploying java beans in jsp
Deploying java beans in jspDeploying java beans in jsp
Deploying java beans in jsp
Priyanka Pradhan
ย 
SOFTWARE PROCESS MONITORING AND AUDIT
SOFTWARE PROCESS MONITORING AND AUDITSOFTWARE PROCESS MONITORING AND AUDIT
SOFTWARE PROCESS MONITORING AND AUDIT
Priyanka Pradhan
ย 
s/w metrics monitoring and control
s/w metrics monitoring and controls/w metrics monitoring and control
s/w metrics monitoring and control
Priyanka Pradhan
ย 
Ad

Recently uploaded (20)

Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
ย 
"Client Partnership โ€” the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership โ€” the Path to Exponential Growth for Companies Sized 50-5..."Client Partnership โ€” the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership โ€” the Path to Exponential Growth for Companies Sized 50-5...
Fwdays
ย 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
ย 
Learn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step GuideLearn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step Guide
Marcel David
ย 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
ย 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
ย 
Leading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael JidaelLeading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael Jidael
Michael Jidael
ย 
Datastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptxDatastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptx
kaleeswaric3
ย 
"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko
Fwdays
ย 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
ย 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
ย 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
ย 
Automation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From AnywhereAutomation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From Anywhere
Lynda Kane
ย 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
ย 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
ย 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
ย 
Drupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Drupalcamp Finland โ€“ Measuring Front-end Energy ConsumptionDrupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Drupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Exove
ย 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
ย 
Salesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docxSalesforce AI Associate 2 of 2 Certification.docx
Salesforce AI Associate 2 of 2 Certification.docx
Josรฉ Enrique Lรณpez Rivera
ย 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
ย 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
ย 
"Client Partnership โ€” the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership โ€” the Path to Exponential Growth for Companies Sized 50-5..."Client Partnership โ€” the Path to Exponential Growth for Companies Sized 50-5...
"Client Partnership โ€” the Path to Exponential Growth for Companies Sized 50-5...
Fwdays
ย 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
ย 
Learn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step GuideLearn the Basics of Agile Development: Your Step-by-Step Guide
Learn the Basics of Agile Development: Your Step-by-Step Guide
Marcel David
ย 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
ย 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
ย 
Leading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael JidaelLeading AI Innovation As A Product Manager - Michael Jidael
Leading AI Innovation As A Product Manager - Michael Jidael
Michael Jidael
ย 
Datastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptxDatastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptx
kaleeswaric3
ย 
"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko"Rebranding for Growth", Anna Velykoivanenko
"Rebranding for Growth", Anna Velykoivanenko
Fwdays
ย 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
ย 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
ย 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
ย 
Automation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From AnywhereAutomation Dreamin': Capture User Feedback From Anywhere
Automation Dreamin': Capture User Feedback From Anywhere
Lynda Kane
ย 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
ย 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
ย 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
ย 
Drupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Drupalcamp Finland โ€“ Measuring Front-end Energy ConsumptionDrupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Drupalcamp Finland โ€“ Measuring Front-end Energy Consumption
Exove
ย 
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical DebtBuckeye Dreamin 2024: Assessing and Resolving Technical Debt
Buckeye Dreamin 2024: Assessing and Resolving Technical Debt
Lynda Kane
ย 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
ย 

Core Java

  • 1. CORE JAVA PRESENTRED BY: PRIYANKA PRADHAN ASSISTANT PROFESSOR MJPRU,BAREILLY. Priyanka Pradhan 1
  • 2. What is Java? โ€ข Java is a high-level programming language originally developed by Sun Microsystems and released in 1995. Java is: ๏ƒผ Object Oriented ๏ƒผ Platform independent: ๏ƒผ Simple ๏ƒผ Secure ๏ƒผ Architectural- neutral ๏ƒผ Portable ๏ƒผ Robust ๏ƒผ Multi-threaded ๏ƒผ Interpreted ๏ƒผ High Performance ๏ƒผ Distributed ๏ƒผ Dynamic Priyanka Pradhan 2
  • 3. Tools You Will Need You will need the following softwares: โ€ข Linux 7.1 or Windows xp/7/8 operating system โ€ข Java JDK 8 โ€ข Microsoft Notepad or any other text editor Priyanka Pradhan 3
  • 4. Setting Up the Path for Windows Assuming you have installed Java in c:Program Filesjavajdk directory: โ€ข Right-click on 'My Computer' and select 'Properties'. โ€ข Click the 'Environment variables' button under the 'Advanced' tab. โ€ข Now, alter the 'Path' variable so that it also contains the path to the Java executable. Example, if the path is currently set to 'C:WINDOWSSYSTEM32', then change your path to read 'C:WINDOWSSYSTEM32;c:Program Filesjavajdkbin'. Priyanka Pradhan 4
  • 5. Popular Java Editors To write your Java programs, you will need a text editor. โ€ข Notepad: On Windows machine, you can use any simple text editor like Notepad (Recommended for this tutorial), TextPad. โ€ข Netbeans: A Java IDE that is open-source and free, which can be downloaded from http://www.netbeans.org/index.html. โ€ข Eclipse: A Java IDE developed by the eclipse open- source community and can be downloaded from http://www.eclipse.org/. Priyanka Pradhan 5
  • 6. how to save the file, compile, and run the program โ€ข Open notepad and add the code. โ€ข Save the file as: MyFirstJavaProgram.java. โ€ข Open a command prompt window and go to the directory where you saved the class. Assume it's C:. โ€ข Type 'javac MyFirstJavaProgram.java' and press enter to compile your code. If there are no errors in your code, the command prompt will take you to the next line (Assumption : The path variable is set). โ€ข Now, type ' java MyFirstJavaProgram ' to run your program. โ€ข You will be able to see ' Hello World ' printed on the window. C:> javac MyFirstJavaProgram.java C:> java MyFirstJavaProgram Hello World Priyanka Pradhan 6
  • 7. Basic Syntax โ€ข Case Sensitivity - Java is case sensitive, which means identifier Helloand hello would have different meaning in Java. โ€ข Class Names - For all class names the first letter should be in Upper Case. If several words are used to form a name of the class, each inner word's first letter should be in Upper Case. โ€ข Example: class MyFirstJavaClass โ€ข Method Names - All method names should start with a Lower Case letter. If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case. Example: public void myMethodName() โ€ข Program File Name - Name of the program file should exactly match the class name. When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and the class name do not match, your program will not compile). โ€ข Example: Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as 'MyFirstJavaProgram.java' โ€ข public static void main(String args[]) - Java program processing starts from the main() method which is a mandatory part of every Java program. Priyanka Pradhan 7
  • 8. Java Identifiers โ€ข All Java components require names. Names used for classes, variables, and methods are called identifiers. โ€ข In Java, there are several points to remember about identifiers. They are as follows: โ€ข All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_). โ€ข After the first character, identifiers can have any combination of characters. โ€ข A key word cannot be used as an identifier. โ€ข Most importantly, identifiers are case sensitive. โ€ข Examples of legal identifiers: age, $salary, _value, __1_value. โ€ข Examples of illegal identifiers: 123abc, -salary. Priyanka Pradhan 8
  • 9. Java Modifiers It is possible to modify classes, methods, etc., by using modifiers. There are two categories of modifiers: โ€ข Access Modifiers: default, public , protected, private โ€ข Non-access Modifiers: final, abstract, strictfp Priyanka Pradhan 9
  • 10. Java Variables Following are the types of variables in Java: โ€ข Local Variables โ€ข Class Variables (Static Variables) โ€ข Instance Variables (Non-static Variables) Priyanka Pradhan 10
  • 11. Java Arrays โ€ข Arrays are objects that store multiple variables of the same type. However, an array itself is an object on the heap. Priyanka Pradhan 11
  • 12. Java Enums โ€ข Enums were introduced in Java 5.0. Enums restrict a variable to have one of only a few predefined values. The values in this enumerated list are called enums. โ€ข With the use of enums it is possible to reduce the number of bugs in your code. โ€ข For example, if we consider an application for a fresh juice shop, it would be possible to restrict the glass size to small, medium, and large. This would make sure that it would not allow anyone to order any size other than small, medium, or large. Priyanka Pradhan 12
  • 13. Java Keywords These reserved words may not be used as constant or variable or any other identifier names. โ€ข abstract โ€ข assert โ€ข boolean โ€ข break โ€ข byte โ€ข case โ€ข catch โ€ข char Priyanka Pradhan 13
  • 14. Comments in Java โ€ข Java supports single-line and multi-line comments very similar to C and C++. All characters available inside any comment are ignored by Java compiler. public class MyFirstJavaProgram{ /* This is my first java program. * This is an example of multi-line comments. */ public static void main(String []args){ // This is an example of single line comment System.out.println("Hello World"); } } Priyanka Pradhan 14
  • 15. Inheritance โ€ข In Java, classes can be derived from classes. Basically, if you need to create a new class and here is already a class that has some of the code you require, then it is possible to derive your new class from the already existing code. โ€ข This concept allows you to reuse the fields and methods of the existing class without having to rewrite the code in a new class. In this scenario, the existing class is called the superclass and the derived class is called the subclass. Priyanka Pradhan 15
  • 16. Interfaces โ€ข In Java language, an interface can be defined as a contract between objects on how to communicate with each other. Interfaces play a vital role when it comes to the concept of inheritance. โ€ข An interface defines the methods, a deriving class (subclass) should use. But the implementation of the methods is totally up to the subclass. Priyanka Pradhan 16
  • 17. Java โ€“ Objects & Classes Java is an Object-Oriented Language. As a language that has the Object-Oriented feature, Java supports the following fundamental concepts: โ€ข Polymorphism โ€ข Inheritance โ€ข Encapsulation โ€ข Abstraction โ€ข Classes โ€ข Objects โ€ข Instance โ€ข Method โ€ข Message Parsing Priyanka Pradhan 17
  • 18. Contdโ€ฆ โ€ข Object - Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behaviors โ€“ wagging the tail, barking, eating. An object is an instance of a class. โ€ข Class - A class can be defined as a template/blueprint that describes the behavior/state that the object of its type support. Priyanka Pradhan 18
  • 19. Objects in Java โ€ข If we consider the real-world, we can find many objects around us, cars, dogs, humans, etc. All these objects have a state and a behavior. โ€ข Software objects also have a state and a behavior. A software object's state is stored in fields and behavior is shown via methods. โ€ข in software development, methods operate on the internal state of an object and the object-to- object communication is done via methods. Priyanka Pradhan 19
  • 20. Classes in Java โ€ข A class is a blueprint from which individual objects are created. public class Dog{ String breed; int ageC; String color; void barking(){ } void hungry(){ } void sleeping(){ } } Priyanka Pradhan 20
  • 21. Contdโ€ฆ A class can contain any of the following variable types. โ€ข Local variables: Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed. โ€ข Instance variables: Instance variables are variables within a class but outside any method. These variables are initialized when the class is instantiated. Instance variables can be accessed from inside any method, constructor or blocks of that particular class. โ€ข Class variables: Class variables are variables declared within a class, outside any method, with the static keyword. Priyanka Pradhan 21
  • 22. Constructors โ€ข Every class has a constructor. โ€ข If we do not explicitly write a constructor for a class, the Java compiler builds a default constructor for that class. โ€ข Each time a new object is created, at least one constructor will be invoked. The main rule of constructors is that they should have the same name as the class. A class can have more than one constructor. example of a constructor: public class Puppy{ public Puppy(){ } public Puppy(String name){ // This constructor has one parameter, name. } } Priyanka Pradhan 22
  • 23. Creating an Object โ€ข In Java, the new keyword is used to create new objects. There are three steps when creating an object from a class: โ€ข Declaration: A variable declaration with a variable name with an object type. โ€ข Instantiation: The 'new' keyword is used to create the object. โ€ข Initialization: The 'new' keyword is followed by a call to a constructor. This call initializes the new object. Priyanka Pradhan 23
  • 24. Contdโ€ฆ example of creating an object: public class Puppy{ public Puppy(String name){ // This constructor has one parameter, name. System.out.println("Passed Name is :" + name ); } public static void main(String []args){ // Following statement would create an object myPuppy Puppy myPuppy = new Puppy( "tommy" ); } } If we compile and run the above program, then it will produce the following result: Passed Name is :tommy Priyanka Pradhan 24
  • 25. Accessing Instance Variables and Methods Instance variables and methods are accessed via created objects. /* First create an object */ ObjectReference = new Constructor(); /* Now call a variable as follows */ ObjectReference.variableName; /* Now you can call a class method as follows */ ObjectReference.MethodName(); Priyanka Pradhan 25
  • 26. how to access instance variables and methods of a class public class Puppy{ int puppyAge; public Puppy(String name){ System.out.println("Name chosen is :" + name ); } public void setAge( int age ){ puppyAge = age; } public int getAge( ){ System.out.println("Puppy's age is :" + puppyAge ); return puppyAge; } public static void main(String []args){ Puppy myPuppy = new Puppy( "tommy" ); myPuppy.setAge( 2 ); myPuppy.getAge( ); System.out.println("Variable Value :" + myPuppy.puppyAge ); } Priyanka Pradhan 26
  • 27. Java Package โ€ข it is a way of categorizing the classes and interfaces. When developing applications in Java, hundreds of classes and interfaces will be written, therefore categorizing these classes is a must as well as makes life much easier. Priyanka Pradhan 27
  • 28. Import Statements โ€ข In Java if a fully qualified name, which includes the package and the class name is given, then the compiler can easily locate the source code or classes. Import statement is a way of giving the proper location for the compiler to find that particular class. โ€ข For example, the following line would ask the compiler to load all the classes available in directory java_installation/java/io: โ€ข import java.io.*; Priyanka Pradhan 28
  • 29. Java โ€“ Basic Datatypes There are two data types available in Java: โ€ข Primitive Datatypes โ€ข Reference/Object Datatypes Priyanka Pradhan 29

Editor's Notes

  • #13: Note: Enums can be declared as their own or inside a class. Methods, variables, constructors can be defined inside enums as well.
  • #28: If we compile and run the above program, then it will produce the following result: Name chosen is :tommy Puppy's age is :2 Variable Value :2