Java Programming Course Overview
Java Programming Course Overview
ETHNOTECH ACADEMY
CERTIFICATE FORMAT
Click icon to add picture
ETHNOTECH ACADEMY
COURSE OUTLINE
S1 JAVA FUNDAMENTALS
ETHNOTECH ACADEMY
COURSE OUTLINE
FLOW CONTROL IMPLEMENTATION
S5
BRANCHING STATEMENTS
S6 LOOPING STATEMENTS
ETHNOTECH ACADEMY
COURSE OUTLINE
S12 DEBUGGING
ETHNOTECH ACADEMY
EXIT PROFILE
Jav
a
Senior We
b
Developer Develo
per
Junior
Developer Programmer
Analyst
Java
Android Free
lanc
Developer Full Stack ing
Java
Developer
ETHNOTECH ACADEMY
ETHNOTECH ACADEMY
ETHNOTECH ACADEMY
ETHNOTECH ACADEMY
SESSION 1- JAVA FUNDAMENTALS
• Download Java
1. Using your preferred web browser, navigate to the Oracle Java Downloads page.
2. On the Downloads page, click the x64 Installer download link under
the Windows category. At the time of writing this article, Java version 17 is the
latest long-term support Java version.
We must have:
• The Java Runtime Environment (JRE)
• Includes Java Virtual Machine (JVM)
• The Java Developer Kit (JDK)
• Includes the Java Compiler
• A text editor
Optional:
• An Integrated Development Environment (IDE) – a software application that
provides comprehensive facilities to computer programmers for software
development
• NetBeans
• Eclipse
ETHNOTECH ACADEMY
Installation Steps Cont’d..
Step 1: Run the Downloaded File
• Double-click the downloaded file to start the installation.
Step 2: Configure the Installation Wizard
• After running the installation file, the installation wizard welcome screen
appears.
1. Click Next to proceed to the next step.
ETHNOTECH ACADEMY
Installation Steps Cont’d..
2. Choose the destination folder for the Java installation files or stick to the default
path. Click Next to proceed.
ETHNOTECH ACADEMY
Installation Steps Cont’d..
3. Wait for the wizard to finish the installation process until the Successfully
Installed message appears. Click Close to exit the wizard.
ETHNOTECH ACADEMY
Set Environment In Java
Step 1: Add Java to System Variables
1. Open the Start menu and search for environment variables.
2. Select the Edit the system environment variables result.
ETHNOTECH ACADEMY
Set Environment In Java Cont’d..
3. In the System Properties window, under the Advanced tab, click Environment
Variables…
ETHNOTECH ACADEMY
Set Environment In Java Cont’d..
4. Under the System variables category, select the Path variable and click Edit:
ETHNOTECH ACADEMY
Set Environment In Java Cont’d..
5. Click the New button and enter the path to the Java bin directory:
6. Click OK to save the changes and exit the variable editing window.
ETHNOTECH ACADEMY
Set Environment In Java Cont’d..
Step 2: Add JAVA_HOME Variable
• Some applications require the JAVA_HOME variable. Follow the steps below to
create the variable:
• 1. In the Environment Variables window, under the System variables category,
click the New… button to create a new variable.
ETHNOTECH ACADEMY
Set Environment In Java Cont’d..
2. Name the variable as JAVA_HOME.
3. In the variable value field, paste the path to your Java jdk directory and
click OK.
4. Confirm the changes by clicking OK in the Environment Variables and System
properties windows.
ETHNOTECH ACADEMY
Test the Java Installation
• Run the java -version command in the command prompt to make sure Java
installed correctly:
• If installed correctly, the command outputs the Java version. Make sure
everything works by writing a simple program and compiling it. Follow the steps
below:
ETHNOTECH ACADEMY
Test the Java Installation Cont’d
Step 1: Write a Test Java Script
• 1. Open a text editor such as Notepad++ and create a new file.
• 2. Enter the following lines of code and click Save:
ETHNOTECH ACADEMY
Java Features
ETHNOTECH ACADEMY
Describe the use of main in a Java
Application
Signature of main
public static void main(String[] args)
ETHNOTECH ACADEMY
Describe the use of main in a Java Application
Cont’d..
ETHNOTECH ACADEMY
Describe the use of main in a Java Application
Cont’d..
Simple example:
class ethnotech
{
public static void main( String args[])
{
[Link](“Ethnotech Academy");
}
}
Output: Ethnotech Academy
ETHNOTECH ACADEMY
Describe the use of main in a Java Application
Cont’d..
How to consume an instance of your own class:
• The variables that the object contains are called instance variables.
• The methods (that is, subroutines) that the object contains are
called instance methods.
ETHNOTECH ACADEMY
Describe the use of main in a Java Application
Cont’d..
Declaration of Class:
• Variables defined within a class are called instance variables because each instance of the class
(that is, each object of the class) contains its own copy of these variables.
• When we do not want our variable’s value to be changed out-side our class we should declare
them private.
• Public variables can be accessed and changed from outside of the class.
ETHNOTECH ACADEMY
Describe the use of main in a Java Application
Cont’d..
Declaration of Methods :
• A method is a program module that contains a series of statements that carry out a
task.
• To execute a method, you invoke or call it from another method; the calling method
makes a method call, which invokes the called method.
• Any class can contain an unlimited number of methods, and each method can be
called an unlimited number of times.
ETHNOTECH ACADEMY
Input & Output using Standard
Packages
Java IO : Input-output in Java with Examples
ETHNOTECH ACADEMY
Input & Output using Standard Packages
cont’d..
Java provides 3 standard or default streams
ETHNOTECH ACADEMY
Input & Output using Standard Packages
cont’d..
ETHNOTECH ACADEMY
.
2. println() - It prints string inside the quotes similar like print() method.
Then
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
Input and Output Using IO package
Streams
Creating DataInputStream Object for Reading values From Keyboard
DataInputStream d=new DataInputStream([Link]);
To read Integer values
int i=[Link]([Link]());
To Read Floating point values
float f=[Link]([Link]());
To Read Double values
double d=[Link]([Link]());
ETHNOTECH ACADEMY
Input and Output Using IO package
Cont’d
To Read Long values
Long l=[Link]([Link]());
To Read String
String name=[Link]();
To read Boolean Value
Boolean b=[Link]([Link]());
To Read Byte Value
byte b=[Link]([Link]());
ETHNOTECH ACADEMY
Input and Output Using IO package
Streams
import [Link].*;
class scan
{
public static void main(String args[])throws IOException
{
DataInputStream s=new DataInputStream([Link]);
[Link]("Enter rollno");
int rollno=[Link]([Link]());
[Link](“Enter mobile no\n");
long mno=[Link]([Link]());
String name=[Link]();
double per=[Link]([Link]());
[Link](“Enter gender");
ETHNOTECH ACADEMY
Input and Output Using IO package
Streams
char g=(char)[Link]();
byte b1=[Link]("123");
boolean b=[Link]("true");
[Link]("rollno="+rollno);
[Link]("name="+name);
[Link]("gender="+g);
[Link]("mno="+mno);
[Link]("per="+per);
[Link]("b="+b);
[Link]("b1="+b1);
}
}
ETHNOTECH ACADEMY
SESSION-2
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
.
• It makes easy to maintain the code and to find the errors easily.
ETHNOTECH ACADEMY
.
[Link] Comment
ETHNOTECH ACADEMY
.
• Syntax:
ETHNOTECH ACADEMY //This is single line comment
.
ETHNOTECH ACADEMY
.
Syntax: /* This
is
multi line
comment */
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
.
• Documentation comments are usually used to write large programs for a project
or software application as it helps to create documentation API.
• These APIs are needed for reference, i.e., which classes, methods, arguments,
etc., are used in the code.
ETHNOTECH ACADEMY
.
/**
*
*We can use various tags to depict the parameter
*or heading or author name
*We can also use HTML tags
*
*/
ETHNOTECH ACADEMY
SESSION 3
• Type Conversions.
• Strings
ETHNOTECH ACADEMY
Primitive Data Types Cont’d..
ETHNOTECH ACADEMY
Primitive Data Types Cont’d..
Example:
short s = 10000; short r = -5000;
ETHNOTECH ACADEMY
Primitive Data Types Cont’d..
Example:
int a = 100000; int b = -200000;
ETHNOTECH ACADEMY
Primitive Data Types Cont’d..
ETHNOTECH ACADEMY
Primitive Data Types Cont’d..
Example:
float f1 = 234.5f;
ETHNOTECH ACADEMY
Primitive Data Types Cont’d..
ETHNOTECH ACADEMY
Primitive Data Types Cont’d..
• Java uses 2-byte Unicode for character data, in order to hold the
ETHNOTECH ACADEMY
Primitive Data Types Cont’d..
Escape Sequences For Special chars
These ‘\x’ values represent special characters:
Code Name meaning
\t Horizontal Tab Advance to next tab stop
\n New line Start a new line
\v Vertical Tab Performs a vertical tab (maybe)
\f Form feed Start a new page on printed media
\r Carriage return Move to beginning of line
\0 Null Null character, has value 0
\" Double Quote Use for " inside of String
\' Single Quote Use for ' inside of char
\\ Backslash Display a \
ETHNOTECH ACADEMY
Type Conversion
ETHNOTECH ACADEMY
Type Conversion Cont’d..
ETHNOTECH ACADEMY
Type Conversion Cont’d..
ETHNOTECH ACADEMY
Type Conversion Cont’d..
class Ethno
{
public static void main(String[] args)
{
int i = 100;
// Automatic type conversion
// Integer to long type
long l = i;
[Link]("Int value " + i);
[Link]("Long value " + l);
}
ETHNOTECH ACADEMY
Type Conversion Cont’d
ETHNOTECH ACADEMY
Type Conversion Cont’d..
public class GFG
{
public static void main(String[] args)
{
double d = 100.04;
// data from double type to long type
long l = (long)d;
// Explicit type casting
int i = (int)l;
[Link]("Double value " + d);
[Link]("Long value " + l);
[Link]("Int value " + i);
}}
ETHNOTECH ACADEMY
Strings
What is String?
Widely used in Java programming, are a sequence of characters. In
the Java String is a group of characters stored in string object.
Creating Strings:
String greeting = "Hello world!";
String Length:
The length function which returns the number of characters
contained in the string object.
int n=[Link]();
ETHNOTECH ACADEMY
Strings Cont’d..
Concatenating Strings:
[Link](string2);
This returns a new string that is string2 added to it at the end of string1
Strings are more commonly concatenated with the + operator, as in:
"Hello" + " world" + "!“
Character Extraction
Example1: char ch; ch = “abc”.charAt(1); //assign the value “b” to ch
Example2:String name=“java Program”; char ch=[Link](5);
ETHNOTECH ACADEMY
Strings Cont’d..
String Comparison
To compare two strings for equality
Syntax:boolean equals(String str)
Example:String s1=“java”;
String s2=“JAVA”;
[Link](s2);//Returns true if s1 is equal to s2
To perform a comparison that ignores case differences
boolean equalsIgnoreCase(String str)
Example:[Link](s2);
//Returns true if s1 is equal to s2 and ignoring case of characters
ETHNOTECH ACADEMY
Strings Cont’d
To find position of given character
String s=“java program”;
int n=[Link](‘a’);//Returns position of first occurrence of character ‘a’
int n=[Link](‘a’);//Returns position of last occurrence of character ‘a’
ETHNOTECH ACADEMY
Strings Cont’d
To replace characters by new characters
Syntax:[Link] (char original,char new);
String s=“Java”;
String s1=[Link](‘j’,’L’);
Program:
class StringDemo
{
public static void main(String args[])
{
String s1=“java”;
String s2=“program”;
ETHNOTECH ACADEMY
Strings Cont’d
[Link](“the length of string s1=“+[Link]());
[Link](“The concatenated string of s1 and s2=“+[Link](s2));
[Link](“The substring of s2 =“+[Link](2,5));
[Link],println(“The replaced string of s1=“[Link](‘j’,’L’));
[Link](“The position of character a in s1=“+[Link](‘a’));
[Link](“The last position of a in s1=“+[Link](‘a’));
[Link](“The character at position 1 in s2=“[Link](1));
}
}
ETHNOTECH ACADEMY
Strings Cont’d..
Example
class EqualsDemo
{
public static void main(String args[ ])
{
String s1 = “Hello”;
String s2 = “Hello”;
String s3 = “Hi”;
String s4 = “HELLO”;
[Link]([Link](s2));
[Link]([Link](s3));
[Link]([Link](s4));
[Link]([Link](s4));
}}
ETHNOTECH ACADEMY
Output
ETHNOTECH ACADEMY
String Cont’d
StringBuffer Class:
It is a peer class of String class unlike String class, StringBuffer creates
string of flexible length and we can modify string in terms of length and
contents in Original string itself.
Method Description
ETHNOTECH ACADEMY
String Cont’d
class stringBuf
{
public static void main(String args[])
{
StringBuffer str=new StringBuffer("Object language ");
[Link]("The original string is="+str);
int pos=[Link]("language");
[Link](pos ,"Oriented ");
[Link]("After inserting ,the string is ="+str);
[Link](6,'_');
ETHNOTECH ACADEMY
Strings Cont’d
ETHNOTECH ACADEMY
Operators In Java
There are many types of operators in Java which are given below:
• Unary Operator
• Arithmetic Operator
• Relational Operator
• Bitwise Operator
• Logical Operator
• Ternary Operator
• Assignment Operator
ETHNOTECH ACADEMY
Operators Cont’d..
ETHNOTECH ACADEMY
Operators Cont’d..
ETHNOTECH ACADEMY
Operators Cont’d..
ETHNOTECH ACADEMY
Operators Cont’d..
Java Ternary Operator
public class OperatorExample
{
public static void main(String args[])
{
int a=2;
int b=5; OUTPUT
int min=(a<b)?a:b; 2
[Link](min);
}}
ETHNOTECH ACADEMY
Expressions Evaluation
ETHNOTECH ACADEMY
Expressions Evaluation Cont’d..
ETHNOTECH ACADEMY
Expressions Evaluation Cont’d
Operators Meaning Associativity
() Parenthesis Left to right
[] Square bracket
. Dot
-> arrow
++,--
+,- Unary plus, minus Right to left
sizeof
(type)
&
*,/,% Multiplication,division,modul Left to right
us,
+,- Addition,subtraction Left to right
ETHNOTECH ACADEMY
SESSION 4
• Arrays in Java
• ArrayList in Java
• Wrapper Classes
• Parsing in Java
ETHNOTECH ACADEMY
Java Arrays
What is an Array?
An array is a collection of similar type of elements which has
contiguous memory location.
There are two types of array
• Single Dimensional Array
• Multidimensional Array
Syntax to Declare an Array in Java
dataType []arr; (or)
dataType arr[];
ETHNOTECH ACADEMY
Java Arrays Cont’d
Instantiation of an Array in Java
arrayRefVar=new datatype[size];
Example of Java Array
class Testarray{
public static void main(String args[])
{
int a[]=new int[5];//declaration and instantiation
a[0]=10;//initialization
a[1]=20;
a[2]=70;
a[3]=40;
a[4]=50;
ETHNOTECH ACADEMY
Java Arrays Cont’d
//traversing array
for(int i=0;i<[Link];i++)//length is the property of array
[Link](a[i]);
}}
ETHNOTECH ACADEMY
Java Arrays Cont’d..
Output
10 20 70 40 50
Multidimensional Arrays
• A multidimensional array is an array of arrays.
• To create a two-dimensional array, add each array within its own set
of curly braces:
int[][] myNumbers = { {1, 2, 3, 4}, {5, 6, 7} };
ETHNOTECH ACADEMY
Java Arrays Cont’d..
int x = myNumbers[1][2];
[Link](x); // Outputs 7
ETHNOTECH ACADEMY
Java Arrays Cont’d..
Iterating Array Elements
terating over an array means accessing each element of array one by
one. There may be many ways of iterating over an array in Java, below
are some simple ways.
Using for loop:
This is the simplest of all where we just have to use a for loop where a
counter variable accesses each element one by one.
ETHNOTECH ACADEMY
Java Arrays Cont’d..
class Ethno {
public static void main(String args[])
{
int ar[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
int i, x;
ETHNOTECH ACADEMY
Java ArrayList
What is ArrayList?
• Java ArrayList class uses a dynamic array for storing the elements.
• It is like an array, but there is no size limit.
• We can add or remove elements anytime. So, it is much more flexible
than the traditional array.
ETHNOTECH ACADEMY
Java ArrayList Cont’d..
Methods of ArrayList
Method Description
void add(int index, E element) It is used to insert the specified element at the
specified position in a list.
boolean add(E e) It is used to append the specified element at the
end of a list.
void clear() It is used to remove all of the elements from this
list.
E get(int index) t is used to fetch the element from the particular
position of the list.
boolean isEmpty() It returns true if the list is empty, otherwise false.
void set(int index,E e) Sets nth element to e
void remove(int index) Remove the specified elememt from the list
ETHNOTECH ACADEMY
Arraylist
ETHNOTECH ACADEMY
Wrapper Classes
ETHNOTECH ACADEMY
Wrapper Classes Cont’d..
ETHNOTECH ACADEMY
Parsing in Java
What is Parsing?
• Parsing in its most general sense is the extraction of the necessary
information from some piece of data, most often textual data.
• There are many Java classes that have the parse() method.
• The parse() method receives some string as input, "extracts" the
necessary information from it and converts it into an object of the
calling class.
ETHNOTECH ACADEMY
Parsing in Java Cont’d..
public class Parsing
{
public static void main(String args[])
{ int x = [Link]("12");
double c = [Link]("12.56"); OUTPUT
int b = [Link]("100",2);
[Link]([Link]("12 “)); 12
[Link]([Link]("12.56")); 12.56
[Link]([Link]("100",2)); 4
[Link]([Link]("101", 8)); 65
}}
ETHNOTECH ACADEMY
SESSION-5 Flow Control
Implementation
• Jump statements
ETHNOTECH ACADEMY
.
Branching Statements
• if statement
• if-else statement
• switch statement
ETHNOTECH ACADEMY
.
if(condition)
{
//code to be executed
}
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
.
• The value of the expression is compared with the values of each case.
ETHNOTECH ACADEMY
.
20
int number=20; //Declaring a variable for switch expression
switch(number) //Switch expression
{
case 10: [Link]("10"); //
Case statements case 20: [Link]("20");
break;
case 30: [Link]("30");
break;
default:[Link]("Not in 10, 20 or 30"); //Default case statement
} } }
ETHNOTECH ACADEMY
SESSION-6 Looping Statements
Construct and evaluate code that uses loops:
• For
• While
• Do-while
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
.
[Link]: It is the second condition which is executed each time to test the condition of
the loop. It continues execution until the condition is false. It must return boolean value
either true or false. It is an optional condition.
ETHNOTECH ACADEMY
[Link]: The statement of the loop is executed each time until the second condition
.
Syntax:
for(initialization; condition; increment/decrement)
{
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
Looping Statements Cont’d..
for(j=0; j<=i; j++) // inner loop for columns
{
[Link]("* "); // print star
}
[Link](); // ending line after each row
}
}
ETHNOTECH ACADEMY
.
• while loop in Java comes into use when we need to repeatedly execute a block
of statements.
ETHNOTECH ACADEMY
.
Example:
i <= 10;
Example: i++;
ETHNOTECH ACADEMY
.
Syntax:
while (condition)
{
//code to be executed
Increment / decrement statement
}
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
.
• The Java do-while loop is used to iterate a part of the program repeatedly, until
the specified condition is true.
• If the number of iteration is not fixed and you must have to execute the loop at
least once, it is recommended to use a do-while loop.
• Java do-while loop is called an exit control loop. Therefore, unlike while loop
and for loop, the do-while check the condition at the end of loop body.
• The Java do-while loop is executed at least once because condition is checked
after loop body.
ETHNOTECH ACADEMY
.
2. Update expression: Every time the loop body is executed, the this expression
increments or decrements loop variable.
Example:
i++;
ETHNOTECH ACADEMY
.
Syntax:
do
{
//code to be executed / loop body
//update statement
}while (condition);
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
.
• Constructor Overloading
• this keyword
• Basic Inheritance
• Overriding
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
.
ETHNOTECH ACADEMY
SESSION-8 Accessing Data Members
In Classes
Declare, implement, and access data members in classes
• Private, Public & Protected
• Describe Encapsulation
ETHNOTECH ACADEMY
SESSION 9
• Declaring Methods
• Implementing Methods
• Accessing Methods
• Creating Objects
• Abstract Methods and Classes
• Final Method and Final Classes
• Visibility Control.
ETHNOTECH ACADEMY
Declaring Methods
ETHNOTECH ACADEMY
Declaring Methods Cont’d..
ETHNOTECH ACADEMY
Declaring Methods Cont’d..
ETHNOTECH ACADEMY
Declaring Methods Cont’d..
Method Name: It is a unique name that is used to define the name of a
method. It must be corresponding to the functionality of the method.
Suppose, if we are creating a method for subtraction of two numbers,
the method name must be subtraction(). A method is invoked by its
name.
Parameter List: It is the list of parameters separated by a comma and
enclosed in the pair of parentheses. It contains the data type and
variable name. If the method has no parameter, left the parentheses
blank.
Method Body: It is a part of the method declaration. It contains all the
actions to be performed. It is enclosed within the pair of curly braces.
ETHNOTECH ACADEMY
Declaring Methods Cont’d..
Types of Method
There are two types of methods in Java:
• Predefined Method
• User-defined Method
Predefined Method
In Java, predefined methods are the method that is already defined in
the Java class libraries is known as predefined methods
It is also known as the standard library method or built-in method.
ETHNOTECH ACADEMY
Declaring Methods Cont’d..
User-defined Method
The method written by the user or programmer is known as a user-
defined method.
These methods are modified according to the requirement.
ETHNOTECH ACADEMY
Declaring Methods Cont’d..
Let's create a user defined method that checks the number is even or
odd. First, we will define the method.
//user defined method
public static void findEvenOdd(int num)
{
//method body
if(num%2==0)
[Link](num+" is even");
else
[Link](num+" is odd");
}
ETHNOTECH ACADEMY
Declaring Methods Cont’d..
ETHNOTECH ACADEMY
Declaring Methods Cont’d..
• OUTPUT
ETHNOTECH ACADEMY
Accessing Methods
Instance Method
The method of the class is known as an instance method. It is a non-
static method defined in the class.
Before calling or invoking the instance method, it is necessary to create
an object of its class. Let's see an example of an instance method.
ETHNOTECH ACADEMY
Accessing Methods Cont’d..
public class InstanceMethodExample
{
public static void main(String [] args)
{
//Creating an object of the class
InstanceMethodExample obj = new InstanceMethodExample();
//invoking instance method
[Link]("The sum is: "+[Link](12, 13));
}
int s;
//user-defined method because we have not used static keyword
public int add(int a, int b)
{
s = a+b;
//returning the sum
return s; }}
ETHNOTECH ACADEMY
Accessing Methods
ETHNOTECH ACADEMY
Accessing Methods Cont’d..
{ {
ETHNOTECH ACADEMY
Method Overloading Cont’d..
class Adder
{
static int add(int a,int b){return a+b;}
static int add(int a,int b,int c){return a+b+c;}
}
class TestOverloading1{
public static void main(String[] args){
[Link]([Link](11,11));
[Link]([Link](11,11,11));
}
}
ETHNOTECH ACADEMY
Output
ETHNOTECH ACADEMY
SESSION 10
• Creating Objects
• Visibility Control.
ETHNOTECH ACADEMY
Creating Objects
ETHNOTECH ACADEMY
Creating Objects Cont’d..
ETHNOTECH ACADEMY
Creating Objects Cont’d..
ETHNOTECH ACADEMY
Constructors
What are Constructors?
Constructors are special methods used to initialize instance variable
and its name should be same as class [Link] does not return any
value.
class Student
{
int rollno,sem,age;
char name[15];
Student()//default Constructor
{}
r ACADEMY
ETHNOTECH
Constructors Cont’d
Student(int r,int a,int s,char n[])//parameterized Constructor
{
rollno=r;
age=a;
sem=s;
name=n;
}
void display()
{
[Link](rollno+”\t”+name+”\t”+sem+”\t”+age);}}
ETHNOTECH ACADEMY
Constructors Cont’d
class ConstructorDemo
{
public static void main(String args[])
{
Student s=new Student(111,24,3,”raj”);
[Link]();
}
}
ETHNOTECH ACADEMY
Abstract Methods
• The method that does not has method body is known as abstract
method. In other words, without an implementation is known as
abstract method. It always declares in the abstract class. It means the
class itself must be abstract if it has abstract method. To create an
abstract method, we use the keyword abstract.
Syntax:
abstract void method_name();
ETHNOTECH ACADEMY
Static keyword in Java
The static keyword in Java is used for memory management mainly. We
can apply static keyword with variables, methods, blocks and nested
classes. The static keyword belongs to the class than an instance of the
class(Object).
The static can be:
Variable (also known as a class variable)
Method (also known as a class method)
Block
Nested class
ETHNOTECH ACADEMY
Static Keyword in Java Cont’d..
ETHNOTECH ACADEMY
Static Keyword in Java Cont’d..
Java static method
If you apply static keyword with any method, it is known as static method.
A static method belongs to the class rather than the object of a class.
A static method can be invoked without the need for creating an instance of a
class.
A static method can access static data member and can change the value of it.
The static method can not use non static data member or call non-static method
directly.
this and super cannot be used in static context.
ETHNOTECH ACADEMY
Static Keyword in Java Cont’d..
Java static block
Is used to initialize the static data member.
It is executed before the main method at the time of classloading.
Ex:class A2
{
static{
[Link]("static block is invoked");
}
public static void main(String args[]){
[Link]("Hello main");
}
}
ETHNOTECH ACADEMY
Static Keyword in Java Cont’d..
B
sub
child
ETHNOTECH ACADEMY
Inheritance Cont’d…
Multilevel Inheritance
Super A Grand Father
Intermediate
B Father
Super
ETHNOTECH ACADEMY
Inheritance Cont’d…
Hierarchical Inheritance
super class
A
ETHNOTECH ACADEMY
Inheritance Cont’d…
Multiple Inheritance
Super A B
Super
Sub
C
Java doesnot support for multiple inheritance that means a java class
doesnot have more than one super class but in real time applications it
is required so By using interface we can implement multiple inhertance.
ETHNOTECH ACADEMY
Inheritance Cont’d…
Defining Interface
interface Area
{
static final float PI=3.14159f;
float compute();
}
ETHNOTECH ACADEMY
Method Overloading
ETHNOTECH ACADEMY
Method Overloading Cont’d..
• class Adder
• {
• static int add(int a,int b){return a+b;}
• static int add(int a,int b,int c){return a+b+c;}
• }
• class TestOverloading1{
• public static void main(String[] args){
• [Link]([Link](11,11));
• [Link]([Link](11,11,11));
• }
• }
ETHNOTECH ACADEMY
Method Overriding
If sub class has the same method as declared in the super class ,it is
known as method overriding.
ETHNOTECH ACADEMY
Method Overriding Cont’d..
ETHNOTECH ACADEMY
Abstract Methods Cont’d..
ETHNOTECH ACADEMY
Final variables
ETHNOTECH ACADEMY
Java Final Method
If you make any method as final, you cannot override it.
Example of method Overriding
class Bike{
final void run(){[Link]("running");}
}
class Honda extends Bike
{
void run()
{
[Link]("running safely with 100kmph");}
public static void main(String args[]){
Honda honda= new Honda();
[Link](); }}
ETHNOTECH ACADEMY
Java Final Method Cont’d..
ETHNOTECH ACADEMY
Final Class
Java final class
If you make any class as final, you cannot extend it.
final class Bike{}
class Honda1 extends Bike{
void run(){[Link]("running safely with 100kmph");}
ETHNOTECH ACADEMY
Access Control Cont’d..
ETHNOTECH ACADEMY
CERTIFICATION QUESTIONS
ETHNOTECH ACADEMY
ETHNOTECH ACADEMY
ETHNOTECH ACADEMY
SUMMARY
Click icon to add picture
ETHNOTECH ACADEMY
ETHNOTECH ACADEMY
ETHNOTECH ACADEMY
ETHNOTECH ACADEMY
ETHNOTECH ACADEMY
CERTIFICATION PATH
Click icon to add picture
ETHNOTECH ACADEMY
ETHNOTECH ACADEMY