SlideShare a Scribd company logo
1 of 29
Core Java Notes
Final Keyword In Java
The final keyword in java is used to restrict the user. The final keyword can be used in many context.
Final can be:
1. variable
2. method
3. class
The final keyword can be applied with the variables, a final variable that have no value it is called blank
final variable or uninitialized final variable. It can be initialized in the constructor only. The blank final
variable can be static also which will be initialized in the static block only. We will have detailed learning of
these. Let's first learn the basics of final keyword.
1) final variable
If you make any variable as final, you cannot change the value of final variable(It will be constant).
Example of final variable
There is a final variable speedlimit, we are going to change the value of this variable, but It can't be
changed because final variable once assigned a value can never be changed.
class Bike{
final int speedlimit=90;//final variable
void run(){
speedlimit=400;
}
public static void main(String args[]){
Bike obj=new Bike();
obj.run();
}
}//end of class
Output:Compile Time Error
________________________________________
2) final method
If you make any method as final, you cannot override it.
Example of final method
class Bike{
final void run(){System.out.println("running");}
}
class Honda extends Bike{
void run(){System.out.println("running safely with 100kmph");}
public static void main(String args[]){
Honda honda= new Honda();
honda.run();
}
}
Output:Compile Time Error
________________________________________
3) final class
If you make any class as final, you cannot extend it.
Example of final class
1. final class Bike{}
2.
3. class Honda extends Bike{
4. void run(){System.out.println("running safely with 100kmph");}
5.
6. public static void main(String args[]){
7. Honda honda= new Honda();
8. honda.run();
9. }
10. }
Output:Compile Time Error
________________________________________
Abstract class in Java
A class that is declared with abstract keyword, is known as abstract class. Before learning abstract class,
let's understand the abstraction first.
Abstraction
Abstraction is a process of hiding the implementation details and showing only functionality to the user.
Another way, it shows only important things to the user and hides the internal details for example sending
sms, you just type the text and send the message. You don't know the internal processing about the
message delivery.
Abstraction lets you focus on what the object does instead of how it does it.
Ways to achieve Abstaction
There are two ways to achieve abstraction in java
1. Abstract class (0 to 100%)
2. Interface (100%)
________________________________________
Abstract class
A class that is declared as abstract is known as abstract class. It needs to be extended and its method
implemented. It cannot be instantiated.
Syntax to declare the abstract class
1. abstract class <class_name>{}
abstract method
A method that is declared as abstract and does not have implementation is known as abstract method.
Syntax to define the abstract method
1. abstract return_type <method_name>();//no braces{}
Example of abstract class that have abstract method
In this example, Bike the abstract class that contains only one abstract method run. It implementation is
provided by the Honda class.
1. abstract class Bike{
2. abstract void run();
3. }
4.
5. class Honda extends Bike{
6. void run(){System.out.println("running safely..");}
7.
8. public static void main(String args[]){
9. Bike obj = new Honda();
10. obj.run();
11. }
12. }
Output:running safely..
________________________________________
Understanding the real scenario of abstract class
In this example, Shape is the abstract class, its implementation is provided by the Rectangle and Circle
classes. Mostly, we don't know about the implementation class (i.e. hidden to the end user) and object of
the implementation class is provided by the factory method.
A factory method is the method that returns the instance of the class. We will learn about the factory
method later.
In this example, if you create the instance of Rectangle class, draw method of Rectangle class will be
invoked.
1. abstract class Shape{
2. abstract void draw();
3. }
4.
5. class Rectangle extends Shape{
6. void draw(){System.out.println("drawing rectangle");}
7. }
8.
9. class Circle extends Shape{
10. void draw(){System.out.println("drawing circle");}
11. }
12.
13. class Test{
14. public static void main(String args[]){
15. Shape s=new Circle();
16. //In real scenario, Object is provided through factory method
17. s.draw();
18. }
19. }
Output:drawing circle
________________________________________
Abstract class having constructor, data member, methods etc.
Note: An abstract class can have data member, abstract method, method body, constructor and even
main() method.
1. //example of abstract class that have method body
2. abstract class Bike{
3. abstract void run();
4. void changeGear(){System.out.println("gear changed");}
5. }
6.
7. class Honda extends Bike{
8. void run(){System.out.println("running safely..");}
9.
10. public static void main(String args[]){
11. Bike obj = new Honda();
12. obj.run();
13. obj.changeGear();
14. }
15. }
Output:running safely..
gear changed
1. //example of abstract class having constructor, field and method
2. abstract class Bike
3. {
4. int limit=30;
5. Bike(){System.out.println("constructor is invoked");}
6. void getDetails(){System.out.println("it has two wheels");}
7. abstract void run();
8. }
9.
10. class Honda extends Bike{
11. void run(){System.out.println("running safely..");}
12.
13. public static void main(String args[]){
14. Bike obj = new Honda();
15. obj.run();
16. obj.getDetails();
17. System.out.println(obj.limit);
18. }
19. }
Output:constructor is invoked
running safely..
it has two wheels
30
Rule: If there is any abstract method in a class, that class must be abstract.
Interface in Java
An interface is a blueprint of a class. It has static constants and abstract methods.
The interface is a mechanism to achieve fully abstraction in java. There can be only abstract methods in
the interface. It is used to achieve fully abstraction and multiple inheritance in Java.
Interface also represents IS-A relationship.
It cannot be instantiated just like abstract class.
Why use Interface?
There are mainly three reasons to use interface. They are given below.
• It is used to achieve fully abstraction.
• By interface, we can support the functionality of multiple inheritance.
• It can be used to achieve loose coupling.
The java compiler adds public and abstract keywords before the interface method and public, static and
final keywords before data members.
In other words, Interface fields are public, static and final bydefault, and methods are public and abstract.
________________________________________
Understanding relationship between classes and interfaces
As shown in the figure given below, a class extends another class, an interface extends another interface
but a class implements an interface.
________________________________________
Simple example of Interface
In this example, Printable interface have only one method, its implementation is provided in the A class.
1. interface printable{
2. void print();
3. }
4.
5. class A implements printable{
6. public void print(){System.out.println("Hello");}
7.
8. public static void main(String args[]){
9. A obj = new A();
10. obj.print();
11. }
12. }
Output:Hello
________________________________________
Multiple inheritance in Java by interface
If a class implements multiple interfaces, or an interface extends multiple interfaces i.e. known as multiple
inheritance.
1. interface Printable{
2. void print();
3. }
4.
5. interface Showable{
6. void show();
7. }
8.
9. class A implements Printable,Showable{
10.
11. public void print(){System.out.println("Hello");}
12. public void show(){System.out.println("Welcome");}
13.
14. public static void main(String args[]){
15. A obj = new A();
16. obj.print();
17. obj.show();
18. }
19. }
Output:Hello
Welcome
Package in Java
A package is a group of similar types of classes, interfaces and sub-packages.
Package can be categorized in two form, built-in package and user-defined package. There are many
built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc.
Here, we will have the detailed learning of creating and using user-defined packages.
Advantage of Package
• Package is used to categorize the classes and interfaces so that they can be easily maintained.
• Package provids access protection.
• Package removes naming collision.
________________________________________
Simple example of package
The package keyword is used to create a package.
1. //save as Simple.java
2.
package mypack;
public class Simple{
public static void main(String args[]){
System.out.println("Welcome to package");
}
}
How to compile the Package (if not using IDE)
If you are not using any IDE, you need to follow the syntax given below:
1. javac -d directory javafilename
For example
1. javac -d . Simple.java
The -d switch specifies the destination where to put the generated class file. You can use any directory
name like /home (in case of Linux), d:/abc (in case of windows) etc. If you want to keep the package
within the same directory, you can use . (dot).
________________________________________
How to run the Package (if not using IDE)
You need to use fully qualified name e.g. mypack.Simple etc to run the class.
________________________________________
To Compile: javac -d . Simple.java
To Run: java mypack.Simple
Output:Welcome to package
The -d is a switch that tells the compiler where to put the class file i.e. it represents destination. The
.represents the current folder.
________________________________________
How to access package from another package?
There are three ways to access the package from outside the package.
1. import package.*;
2. import package.classname;
3. fully qualified name.
Using packagename.*
If you use package.* then all the classes and interfaces of this package will be accessible but not
subpackages.
The import keyword is used to make the classes and interface of another package accessible to the
current package.
Example of package that import the packagename.*
1. //save by A.java
2.
3. package pack;
4. public class A{
5. public void msg(){System.out.println("Hello");}
6. }
1. //save by B.java
2.
3. package mypack;
4. import pack.*;
5.
6. class B{
7. public static void main(String args[]){
8. A obj = new A();
9. obj.msg();
10. }
11. }
Output:Hello
________________________________________
Using packagename.classname
If you import package.classname then only declared class of this package will be accessible.
Example of package by import package.classname
1. //save by A.java
2.
3. package pack;
4. public class A{
5. public void msg(){System.out.println("Hello");}
6. }
1. //save by B.java
2.
3. package mypack;
4. import pack.A;
5.
6. class B{
7. public static void main(String args[]){
8. A obj = new A();
9. obj.msg();
10. }
11. }
Output:Hello
________________________________________
Using fully qualified name
If you use fully qualified name then only declared class of this package will be accessible. Now there is no
need to import. But you need to use fully qualified name every time when you are accessing the class or
interface.
It is generally used when two packages have same class name e.g. java.util and java.sql packages
contain Date class.
Example of package by import fully qualified name
1. //save by A.java
2.
3. package pack;
4. public class A{
5. public void msg(){System.out.println("Hello");}
6. }
1. //save by B.java
2.
3. package mypack;
4. class B{
5. public static void main(String args[]){
6. pack.A obj = new pack.A();//using fully qualified name
7. obj.msg();
8. }
9. }
Output:Hello
Note: Sequence of the program must be package then import then class.
________________________________________
________________________________________
Access Modifiers
There are two types of modifiers in java: access modifier and non-access modifier. The access modifiers
specifies accessibility (scope) of a datamember, method, constructor or class.
There are 4 types of access modifiers:
1. private
2. default
3. protected
4. public
There are many non-access modifiers such as static, abstract etc. Here, we will learn access modifiers.
________________________________________
1) private
The private access modifier is accessible only within class.
Simple example of private access modifier
In this example, we have created two classes A and Simple. A class contains private data member and
private method. We are accessing these private members from outside the class, so there is compile time
error.
1. class A{
2. private int data=40;
3. private void msg(){System.out.println("Hello java");}
4. }
5.
6. public class Simple{
7. public static void main(String args[]){
8. A obj=new A();
9. System.out.println(obj.data);//Compile Time Error
10. obj.msg();//Compile Time Error
11. }
12. }
Role of Private Constructor:
If you make any class constructor private, you cannot create the instance of that class from outside the
class. For example:
1. class A{
2. private A(){}//private constructor
3.
4. void msg(){System.out.println("Hello java");}
5. }
6.
7. public class Simple{
8. public static void main(String args[]){
9. A obj=new A();//Compile Time Error
10. }
11. }
________________________________________
2) default
If you don't use any modifier, it is treated as default bydefault. The default modifier is accessible only
within package.
Example of default access modifier
In this example, we have created two packages pack and mypack. We are accessing the A class from
outside its package, since A class is not public, so it cannot be accessed from outside the package.
1. //save by A.java
2.
3. package pack;
4. class A{
5. void msg(){System.out.println("Hello");}
6. }
1. //save by B.java
2.
3. package mypack;
4. import pack.*;
5.
6. class B{
7. public static void main(String args[]){
8. A obj = new A();//Compile Time Error
9. obj.msg();//Compile Time Error
10. }
11. }
In the above example, the scope of class A and its method msg() is default so it cannot be accessed from
outside the package.
________________________________________
3) protected
The protected access modifier is accessible within package and outside the package but through
inheritance only.
The protected access modifier can be applied on the data member, method and constructor. It can't be
applied on the class.
Example of protected access modifier
In this example, we have created the two packages pack and mypack. The A class of pack package is
public, so can be accessed from outside the package. But msg method of this package is declared as
protected, so it can be accessed from outside the class only through inheritance.
1. //save by A.java
2.
3. package pack;
4. public class A{
5. protected void msg(){System.out.println("Hello");}
6. }
1. //save by B.java
2.
3. package mypack;
4. import pack.*;
5.
6. class B extends A{
7. public static void main(String args[]){
8. B obj = new B();
9. obj.msg();
10. }
11. }
Output:Hello
________________________________________
4) public
The public access modifier is accessible everywhere. It has the widest scope among all other modifiers.
Example of public access modifier
1. //save by A.java
2.
3. package pack;
4. public class A{
5. public void msg(){System.out.println("Hello");}
6. }
1. //save by B.java
2.
3. package mypack;
4. import pack.*;
5.
6. class B{
7. public static void main(String args[]){
8. A obj = new A();
9. obj.msg();
10. }
11. }
Output:Hello
Understanding all java access modifiers
Let's understand the access modifiers by a simple table.
Access Modifier within class within package outside package by subclass only outside package
Private Y N N N
Default Y Y N N
Protected Y Y Y N
Public Y Y Y Y
________________________________________
Applying access modifier with method overriding
If you are overriding any method, overridden method (i.e. declared in subclass) must not be more
restrictive.
1. class A{
2. protected void msg(){System.out.println("Hello java");}
3. }
4.
5. public class Simple extends A{
6. void msg(){System.out.println("Hello java");}//C.T.Error
7. public static void main(String args[]){
8. Simple obj=new Simple();
9. obj.msg();
10. }
11. }
The default modifier is more restrictive than protected. That is why there is compile time error.
Encapsulation in Java
Encapsulation is a process of wrapping code and data together into a single unit e.g. capsule i.e mixed of
several medicines.
We can create a fully encapsulated class by making all the data members of the class private. Now we
can use setter and getter methods to set and get the data in it.
Array in Java
Normally, array is a collection of similar type of elements that have contiguous memory location.
In java, array is an object the contains elements of similar data type. It is a data structure where we store
similar elements. We can store only fixed elements in an array.
Array is index based, first element of the array is stored at 0 index.
Advantage of Array
• Code Optimization: It makes the code optimized, we can retrieve or sort the data easily.
• Random access: We can get any data located at any index position.
________________________________________
Disadvantage of Array
• Size Limit: We can store only fixed size of elements in the array. It doesn't grow its size at runtime. To
solve this problem, collection framework is used in java.
________________________________________
Types of Array
There are two types of array.
• Single Dimensional Array
• Multidimensional Array
________________________________________
Single Dimensional Array
Syntax to Declare an Array in java
1. dataType[] arrayRefVar; (or)
2. dataType []arrayRefVar; (or)
3. dataType arrayRefVar[];
Instantiation of an Array in java
1. arrayRefVar=new datatype[size];
Example of single dimensional java array
Let's see the simple example of java array, where we are going to declare, instantiate, initialize and
traverse an array.
1. class B{
2. public static void main(String args[]){
3.
4. int a[]=new int[5];//declaration and instantiation
5. a[0]=10;//initialization
6. a[1]=20;
7. a[2]=70;
8. a[3]=40;
9. a[4]=50;
10.
11. //printing array
12. for(int i=0;i<a.length;i++)//length is the property of array
13. System.out.println(a[i]);
14.
15. }}
Output: 10
20
70
40
50
________________________________________
Declaration, Instantiation and Initialization of Java Array
We can declare, instantiate and initialize the java array together by:
1. int a[]={33,3,4,5};//declaration, instantiation and initialization
Let's see the simple example to print this array.
1. class B{
2. public static void main(String args[]){
3.
4. int a[]={33,3,4,5};//declaration, instantiation and initialization
5.
6. //printing array
7. for(int i=0;i<a.length;i++)//length is the property of array
8. System.out.println(a[i]);
9.
10. }}
Output:33
3
4
5
________________________________________
Passing Java Array in the method
We can pass the array in the method so that we can reuse the same logic on any array.
Let's see the simple example to get minimum number of an array using method.
1. class B{
2. static void min(int arr[]){
3. int min=arr[0];
4. for(int i=1;i<arr.length;i++)
5. if(min>arr[i])
6. min=arr[i];
7.
8. System.out.println(min);
9. }
10.
11. public static void main(String args[]){
12.
13. int a[]={33,3,4,5};
14. min(a);//passing array in the method
15.
16. }}
Output:3
________________________________________
Multidimensional array
In such case, data is stored in row and column based index (also known as matrix form).
Syntax to Declare Multidimensional Array in java
1. dataType[][] arrayRefVar; (or)
2. dataType [][]arrayRefVar; (or)
3. dataType arrayRefVar[][]; (or)
4. dataType []arrayRefVar[];
Example to instantiate Multidimensional Array in java
1. int[][] arr=new int[3][3];//3 row and 3 column
Example to initialize Multidimensional Array in java
1. arr[0][0]=1;
2. arr[0][1]=2;
3. arr[0][2]=3;
4. arr[1][0]=4;
5. arr[1][1]=5;
6. arr[1][2]=6;
7. arr[2][0]=7;
8. arr[2][1]=8;
9. arr[2][2]=9;
Example of Multidimensional java array
Let's see the simple example to declare, instantiate, initialize and print the 2Dimensional array.
1. class B{
2. public static void main(String args[]){
3.
4. //declaring and initializing 2D array
5. int arr[][]={{1,2,3},{2,4,5},{4,4,5}};
6.
7. //printing 2D array
8. for(int i=0;i<3;i++){
9. for(int j=0;j<3;j++){
10. System.out.print(arr[i][j]+" ");
11. }
12. System.out.println();
13. }
14.
15. }}
Output:1 2 3
2 4 5
4 4 5
________________________________________
________________________________________
Copying an array
We can copy an array to another by the arraycopy method of System class.
Syntax of arraycopy method
1. public static void arraycopy(
2. Object src, int srcPos,Object dest, int destPos, int length
3. )
Example of arraycopy method
1. class ArrayCopyDemo {
2. public static void main(String[] args) {
3. char[] copyFrom = { 'd', 'e', 'c', 'a', 'f', 'f', 'e',
4. 'i', 'n', 'a', 't', 'e', 'd' };
5. char[] copyTo = new char[7];
6.
7. System.arraycopy(copyFrom, 2, copyTo, 0, 7);
8. System.out.println(new String(copyTo));
9. }
10. }
Output:caffein
________________________________________
Addition 2 matrices
Let's see a simple example that adds two matrices.
1. class AE{
2. public static void main(String args[]){
3. //creating two matrices
4. int a[][]={{1,3,4},{3,4,5}};
5. int b[][]={{1,3,4},{3,4,5}};
6.
7. //creating another matrix to store the sum of two matrices
8. int c[][]=new int[2][3];
9.
10. //adding and printing addition of 2 matrices
11. for(int i=0;i<2;i++){
12. for(int j=0;j<3;j++){
13. c[i][j]=a[i][j]+b[i][j];
14. System.out.print(c[i][j]+" ");
15. }
16. System.out.println();//new line
17. }
18.
19. }}
Output:2 6 8
6 8 10
Lab exercises
Model 2(Lab)
1.Wrire a Proram to creat a class that stores the train reservation details. In addition, define a
method that will display the stored details.
public class Reservation {
int ticketID;
String name;
String source;
String destination;
Reservation() {
ticketID = 80;
name ="Harry";
source = "Chicago"
destination = "Dallas";
}
public void showTicket () {
System.out.println("The Ticket ID is "+ ticketID);
System.out.println("The Passenger Name is "+ name);
System.out.println("The Sourse is" + sourse);
System.out.println("The Destination is" + Destination);
System.out.println("nChoose the option: ");
public static void main(String[] args) {
Reservation g = new Reservation();
g.showTicket();
}
}
Q 2. Write a program to create a class named EmployeeDetails and display a menue similar to the
following menu:
--------------Menu--------
1. Enter Data
2. Display Data
3. Exit
Choose the option
Thereafter, invoke the respective method according to the given menu input. The methods will
contain appropriate message, such as the displayData()
method will contain the message, displayData method is invoked
public class EmployeeDetails {
public void showMenue () {
int option;
System.out.println("------------Menu--------");
System.out.println("1. Enter Data");
System.out.println("2. Display Data");
System.out.println("3. Exit");
System.out.println("nChoose the option: ");
Option = 2;
switch (option) {
case 1:
enterData();
break;
case2:
DisplayData();
break;
case3:
exitMenue();
break;
defalt:
System.out.println("Incorrect menu option");
showMenu();
break;
}
}
public void enterData() {
System.out.println("enterData method is invoked");
}
public void enterData() {
System.out.println("displayData method is invoked");
}
public void enterData() {
System.out.println("exitMenu method is invoked");
System.exit(0);
}
public static void main(String[] args) {
EmployeeDetails obj = new EmployeeDetails();
obj.showMenu();
}
}
3.Write a program to create a class that stores the grocery details. In addition, define three methods that
will add the weight, remove the weight, and display the current weight, respectively..
4.Write a program to create a class that declares a member variable and a member method. The
member method will display the value of the member variable.
Ans.Q 4. Write a program that will store the employee records, such as employee ID, employee
name, department, designation,
date of joining, date of birth, and marital status, in an array. In addition, the stored record needs to
be displayed.
Ans
public class employeerecord
string employeeDetails [] [] = new String [1] [7];
public void storeData() {
employeeDeatils [0] [0] = "A101";
employeeDeatils [0] [1] = "john mathew";
employeeDetails [0] [2] = "admin";
employeeDetails [0] [3] = "manager";
employeeDetails [0] [4] = "05/04/1998";
employeeDetails [0] [5] = "11/09/1997";
employeeDetails [0] [6] = "married";
}
public void displayData() {
system.out.println ("Employee Details:");
for ( int i = 0; i < employeeDetails,length;
for ( int j = 0; j < employeeDetails[i].length; j++ {
system.out.println(employeeDetails[i] [j] );
}
}
}
public static void main (String [] args) {
EmployeeRecord obj = new EmployeeRecord();
obj.storeData();
obj.displayData();
}
}
5.Write a program to identify whether the given character is a vowel or a consonant.
Ans.
6.Write a program to display the following numeric pattern:
12345
1234
123
12
1
Ans
.7.Using the NetBeans IDE, create an Employee class, create a class with a main method to test the
Employee class, compile and run your application, and print the results to the command line output.
Ans.
1. start the NetBeans IDE by using the icon from desktop.
2. create a new project employeepractice in the D:labs02-reviewpractices directory with anemployeetest
main class in the com.example package.
3. Set the source/binary format to JDK 7.
a. right-click the project and select properties.
b. select JDK 7 from the drop-down list for SOurc/binary format.
c. click ok.
4. create another package called com.example.domain.
5. Add a java class called Employee in the com.example.domain package.
6. code the employee class.
a. add the following data fields to the employee class-use your judgment as to what you want to call these
fields in the class. Refer to the lesson material for ideas on the fields names and the syntax if you are not
sure. Use public as the access modifier.
7. create a no-arg constructor for the employee class.
Netbeans can format your code at any time for you. Right-click in the class and select format, or press the
Alt-Shift-F key combination.
8. Add accessor/mutator methods for each of the fields.
9. write code in the employeetest class to test your employee class.
a. construct an instance of employee.
b. use the setter mothods to assign the following values to the instance:
c. in the body of the main methoed, use the system.out.printIn method to write the values of the employee
fields to the console output.
d. rsolve any missing import statements.
e. save the employeetest class.
10. run the EmployeePractice project.
11. Add some additional employee instances to your test class.
http://mkniit.blogspot.in/2015/12/q-1.html

More Related Content

What's hot

oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaCPD INDIA
 
Object oriented programming-with_java
Object oriented programming-with_javaObject oriented programming-with_java
Object oriented programming-with_javaHoang Nguyen
 
Java oops and fundamentals
Java oops and fundamentalsJava oops and fundamentals
Java oops and fundamentalsjavaease
 
Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)indiangarg
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of javakamal kotecha
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingNithyaN19
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in javaElizabeth alexander
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and objectFajar Baskoro
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singhdheeraj_cse
 

What's hot (20)

Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Basics of Java
Basics of JavaBasics of Java
Basics of Java
 
Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674
 
Object oriented programming-with_java
Object oriented programming-with_javaObject oriented programming-with_java
Object oriented programming-with_java
 
Java oops and fundamentals
Java oops and fundamentalsJava oops and fundamentals
Java oops and fundamentals
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of java
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
 
OOP java
OOP javaOOP java
OOP java
 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overriding
 
Oop java
Oop javaOop java
Oop java
 
Chapter 05 classes and objects
Chapter 05 classes and objectsChapter 05 classes and objects
Chapter 05 classes and objects
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
 
Introduction to java and oop
Introduction to java and oopIntroduction to java and oop
Introduction to java and oop
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singh
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 

Viewers also liked

Conditional Statement
Conditional Statement Conditional Statement
Conditional Statement OXUS 20
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesOXUS 20
 
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using JavaFal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using JavaOXUS 20
 
Java Regular Expression PART II
Java Regular Expression PART IIJava Regular Expression PART II
Java Regular Expression PART IIOXUS 20
 
Java Regular Expression PART I
Java Regular Expression PART IJava Regular Expression PART I
Java Regular Expression PART IOXUS 20
 
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesJava Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesOXUS 20
 
Everything about Object Oriented Programming
Everything about Object Oriented ProgrammingEverything about Object Oriented Programming
Everything about Object Oriented ProgrammingAbdul Rahman Sherzad
 
Java Applet and Graphics
Java Applet and GraphicsJava Applet and Graphics
Java Applet and GraphicsOXUS 20
 
PHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail ExplanationPHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail ExplanationOXUS 20
 
TKP Java Notes for Teaching Kids Programming
TKP Java Notes for Teaching Kids ProgrammingTKP Java Notes for Teaching Kids Programming
TKP Java Notes for Teaching Kids ProgrammingLynn Langit
 
Structure programming – Java Programming – Theory
Structure programming – Java Programming – TheoryStructure programming – Java Programming – Theory
Structure programming – Java Programming – TheoryOXUS 20
 
Java Guessing Game Number Tutorial
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number TutorialOXUS 20
 
Object Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non StaticObject Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non StaticOXUS 20
 
Web Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and TechnologiesWeb Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and TechnologiesOXUS 20
 
Create Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepCreate Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepOXUS 20
 
Note - Java Remote Debug
Note - Java Remote DebugNote - Java Remote Debug
Note - Java Remote Debugboyw165
 
Everything about Database JOINS and Relationships
Everything about Database JOINS and RelationshipsEverything about Database JOINS and Relationships
Everything about Database JOINS and RelationshipsOXUS 20
 

Viewers also liked (20)

Corejava ratan
Corejava ratanCorejava ratan
Corejava ratan
 
Advanced core java
Advanced core javaAdvanced core java
Advanced core java
 
Java notes
Java notesJava notes
Java notes
 
Conditional Statement
Conditional Statement Conditional Statement
Conditional Statement
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI Examples
 
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using JavaFal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
 
Java Regular Expression PART II
Java Regular Expression PART IIJava Regular Expression PART II
Java Regular Expression PART II
 
Java Regular Expression PART I
Java Regular Expression PART IJava Regular Expression PART I
Java Regular Expression PART I
 
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesJava Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
 
Everything about Object Oriented Programming
Everything about Object Oriented ProgrammingEverything about Object Oriented Programming
Everything about Object Oriented Programming
 
Java Applet and Graphics
Java Applet and GraphicsJava Applet and Graphics
Java Applet and Graphics
 
PHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail ExplanationPHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail Explanation
 
TKP Java Notes for Teaching Kids Programming
TKP Java Notes for Teaching Kids ProgrammingTKP Java Notes for Teaching Kids Programming
TKP Java Notes for Teaching Kids Programming
 
Structure programming – Java Programming – Theory
Structure programming – Java Programming – TheoryStructure programming – Java Programming – Theory
Structure programming – Java Programming – Theory
 
Java Guessing Game Number Tutorial
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number Tutorial
 
Object Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non StaticObject Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non Static
 
Web Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and TechnologiesWeb Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and Technologies
 
Create Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepCreate Splash Screen with Java Step by Step
Create Splash Screen with Java Step by Step
 
Note - Java Remote Debug
Note - Java Remote DebugNote - Java Remote Debug
Note - Java Remote Debug
 
Everything about Database JOINS and Relationships
Everything about Database JOINS and RelationshipsEverything about Database JOINS and Relationships
Everything about Database JOINS and Relationships
 

Similar to Core java notes with examples

ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfbca23189c
 
Exception handling and packages.pdf
Exception handling and packages.pdfException handling and packages.pdf
Exception handling and packages.pdfKp Sharma
 
oops with java modules i & ii.ppt
oops with java modules i & ii.pptoops with java modules i & ii.ppt
oops with java modules i & ii.pptrani marri
 
this keyword in Java.pdf
this keyword in Java.pdfthis keyword in Java.pdf
this keyword in Java.pdfParvizMirzayev2
 
abstract,final,interface (1).pptx upload
abstract,final,interface (1).pptx uploadabstract,final,interface (1).pptx upload
abstract,final,interface (1).pptx uploaddashpayal697
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using ReflectionGanesh Samarthyam
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)ssuser7f90ae
 
ITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxkristinatemen
 
Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and InterfacesJamsher bhanbhro
 
OOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxOOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxssuser84e52e
 
MC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall sessionMC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall sessionNarinder Kumar
 

Similar to Core java notes with examples (20)

ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdfch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
ch4 foohggggvvbbhhhhhhhhhbbbbbbbbbbbbp.pdf
 
Exception handling and packages.pdf
Exception handling and packages.pdfException handling and packages.pdf
Exception handling and packages.pdf
 
oops with java modules i & ii.ppt
oops with java modules i & ii.pptoops with java modules i & ii.ppt
oops with java modules i & ii.ppt
 
this keyword in Java.pdf
this keyword in Java.pdfthis keyword in Java.pdf
this keyword in Java.pdf
 
abstract,final,interface (1).pptx upload
abstract,final,interface (1).pptx uploadabstract,final,interface (1).pptx upload
abstract,final,interface (1).pptx upload
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
Java scjp-part1
Java scjp-part1Java scjp-part1
Java scjp-part1
 
Oop
OopOop
Oop
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)
 
ITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptxITTutor Advanced Java (1).pptx
ITTutor Advanced Java (1).pptx
 
CHAPTER 3 part1.pdf
CHAPTER 3 part1.pdfCHAPTER 3 part1.pdf
CHAPTER 3 part1.pdf
 
java basic .pdf
java basic .pdfjava basic .pdf
java basic .pdf
 
Delphi qa
Delphi qaDelphi qa
Delphi qa
 
Abstraction in Java: Abstract class and Interfaces
Abstraction in  Java: Abstract class and InterfacesAbstraction in  Java: Abstract class and Interfaces
Abstraction in Java: Abstract class and Interfaces
 
OOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxOOFeatures_revised-2.pptx
OOFeatures_revised-2.pptx
 
MC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall sessionMC0078 SMU 2013 Fall session
MC0078 SMU 2013 Fall session
 
Smart material - Unit 2 (1).pdf
Smart material - Unit 2 (1).pdfSmart material - Unit 2 (1).pdf
Smart material - Unit 2 (1).pdf
 
Smart material - Unit 2 (1).pdf
Smart material - Unit 2 (1).pdfSmart material - Unit 2 (1).pdf
Smart material - Unit 2 (1).pdf
 

Recently uploaded

SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 

Recently uploaded (20)

SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

Core java notes with examples

  • 1. Core Java Notes Final Keyword In Java The final keyword in java is used to restrict the user. The final keyword can be used in many context. Final can be: 1. variable 2. method 3. class The final keyword can be applied with the variables, a final variable that have no value it is called blank final variable or uninitialized final variable. It can be initialized in the constructor only. The blank final variable can be static also which will be initialized in the static block only. We will have detailed learning of these. Let's first learn the basics of final keyword. 1) final variable If you make any variable as final, you cannot change the value of final variable(It will be constant). Example of final variable There is a final variable speedlimit, we are going to change the value of this variable, but It can't be changed because final variable once assigned a value can never be changed. class Bike{ final int speedlimit=90;//final variable void run(){
  • 2. speedlimit=400; } public static void main(String args[]){ Bike obj=new Bike(); obj.run(); } }//end of class Output:Compile Time Error ________________________________________ 2) final method If you make any method as final, you cannot override it. Example of final method class Bike{ final void run(){System.out.println("running");} } class Honda extends Bike{ void run(){System.out.println("running safely with 100kmph");} public static void main(String args[]){ Honda honda= new Honda(); honda.run(); } } Output:Compile Time Error ________________________________________ 3) final class If you make any class as final, you cannot extend it. Example of final class 1. final class Bike{} 2. 3. class Honda extends Bike{ 4. void run(){System.out.println("running safely with 100kmph");}
  • 3. 5. 6. public static void main(String args[]){ 7. Honda honda= new Honda(); 8. honda.run(); 9. } 10. } Output:Compile Time Error ________________________________________ Abstract class in Java A class that is declared with abstract keyword, is known as abstract class. Before learning abstract class, let's understand the abstraction first. Abstraction Abstraction is a process of hiding the implementation details and showing only functionality to the user. Another way, it shows only important things to the user and hides the internal details for example sending sms, you just type the text and send the message. You don't know the internal processing about the message delivery. Abstraction lets you focus on what the object does instead of how it does it. Ways to achieve Abstaction There are two ways to achieve abstraction in java 1. Abstract class (0 to 100%) 2. Interface (100%) ________________________________________ Abstract class A class that is declared as abstract is known as abstract class. It needs to be extended and its method implemented. It cannot be instantiated. Syntax to declare the abstract class 1. abstract class <class_name>{} abstract method A method that is declared as abstract and does not have implementation is known as abstract method. Syntax to define the abstract method 1. abstract return_type <method_name>();//no braces{} Example of abstract class that have abstract method In this example, Bike the abstract class that contains only one abstract method run. It implementation is
  • 4. provided by the Honda class. 1. abstract class Bike{ 2. abstract void run(); 3. } 4. 5. class Honda extends Bike{ 6. void run(){System.out.println("running safely..");} 7. 8. public static void main(String args[]){ 9. Bike obj = new Honda(); 10. obj.run(); 11. } 12. } Output:running safely.. ________________________________________ Understanding the real scenario of abstract class In this example, Shape is the abstract class, its implementation is provided by the Rectangle and Circle classes. Mostly, we don't know about the implementation class (i.e. hidden to the end user) and object of the implementation class is provided by the factory method. A factory method is the method that returns the instance of the class. We will learn about the factory method later. In this example, if you create the instance of Rectangle class, draw method of Rectangle class will be invoked. 1. abstract class Shape{ 2. abstract void draw(); 3. } 4. 5. class Rectangle extends Shape{ 6. void draw(){System.out.println("drawing rectangle");} 7. } 8. 9. class Circle extends Shape{ 10. void draw(){System.out.println("drawing circle");}
  • 5. 11. } 12. 13. class Test{ 14. public static void main(String args[]){ 15. Shape s=new Circle(); 16. //In real scenario, Object is provided through factory method 17. s.draw(); 18. } 19. } Output:drawing circle ________________________________________ Abstract class having constructor, data member, methods etc. Note: An abstract class can have data member, abstract method, method body, constructor and even main() method. 1. //example of abstract class that have method body 2. abstract class Bike{ 3. abstract void run(); 4. void changeGear(){System.out.println("gear changed");} 5. } 6. 7. class Honda extends Bike{ 8. void run(){System.out.println("running safely..");} 9. 10. public static void main(String args[]){ 11. Bike obj = new Honda(); 12. obj.run(); 13. obj.changeGear(); 14. } 15. } Output:running safely.. gear changed 1. //example of abstract class having constructor, field and method 2. abstract class Bike
  • 6. 3. { 4. int limit=30; 5. Bike(){System.out.println("constructor is invoked");} 6. void getDetails(){System.out.println("it has two wheels");} 7. abstract void run(); 8. } 9. 10. class Honda extends Bike{ 11. void run(){System.out.println("running safely..");} 12. 13. public static void main(String args[]){ 14. Bike obj = new Honda(); 15. obj.run(); 16. obj.getDetails(); 17. System.out.println(obj.limit); 18. } 19. } Output:constructor is invoked running safely.. it has two wheels 30 Rule: If there is any abstract method in a class, that class must be abstract. Interface in Java An interface is a blueprint of a class. It has static constants and abstract methods. The interface is a mechanism to achieve fully abstraction in java. There can be only abstract methods in the interface. It is used to achieve fully abstraction and multiple inheritance in Java. Interface also represents IS-A relationship. It cannot be instantiated just like abstract class. Why use Interface? There are mainly three reasons to use interface. They are given below. • It is used to achieve fully abstraction.
  • 7. • By interface, we can support the functionality of multiple inheritance. • It can be used to achieve loose coupling. The java compiler adds public and abstract keywords before the interface method and public, static and final keywords before data members. In other words, Interface fields are public, static and final bydefault, and methods are public and abstract. ________________________________________ Understanding relationship between classes and interfaces As shown in the figure given below, a class extends another class, an interface extends another interface but a class implements an interface. ________________________________________ Simple example of Interface In this example, Printable interface have only one method, its implementation is provided in the A class. 1. interface printable{ 2. void print(); 3. } 4. 5. class A implements printable{ 6. public void print(){System.out.println("Hello");} 7. 8. public static void main(String args[]){ 9. A obj = new A(); 10. obj.print(); 11. } 12. } Output:Hello ________________________________________ Multiple inheritance in Java by interface If a class implements multiple interfaces, or an interface extends multiple interfaces i.e. known as multiple inheritance. 1. interface Printable{ 2. void print(); 3. } 4.
  • 8. 5. interface Showable{ 6. void show(); 7. } 8. 9. class A implements Printable,Showable{ 10. 11. public void print(){System.out.println("Hello");} 12. public void show(){System.out.println("Welcome");} 13. 14. public static void main(String args[]){ 15. A obj = new A(); 16. obj.print(); 17. obj.show(); 18. } 19. } Output:Hello Welcome Package in Java A package is a group of similar types of classes, interfaces and sub-packages. Package can be categorized in two form, built-in package and user-defined package. There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc. Here, we will have the detailed learning of creating and using user-defined packages. Advantage of Package • Package is used to categorize the classes and interfaces so that they can be easily maintained. • Package provids access protection. • Package removes naming collision. ________________________________________ Simple example of package The package keyword is used to create a package. 1. //save as Simple.java 2. package mypack; public class Simple{
  • 9. public static void main(String args[]){ System.out.println("Welcome to package"); } } How to compile the Package (if not using IDE) If you are not using any IDE, you need to follow the syntax given below: 1. javac -d directory javafilename For example 1. javac -d . Simple.java The -d switch specifies the destination where to put the generated class file. You can use any directory name like /home (in case of Linux), d:/abc (in case of windows) etc. If you want to keep the package within the same directory, you can use . (dot). ________________________________________ How to run the Package (if not using IDE) You need to use fully qualified name e.g. mypack.Simple etc to run the class. ________________________________________ To Compile: javac -d . Simple.java To Run: java mypack.Simple Output:Welcome to package The -d is a switch that tells the compiler where to put the class file i.e. it represents destination. The .represents the current folder. ________________________________________ How to access package from another package? There are three ways to access the package from outside the package. 1. import package.*; 2. import package.classname; 3. fully qualified name. Using packagename.* If you use package.* then all the classes and interfaces of this package will be accessible but not subpackages. The import keyword is used to make the classes and interface of another package accessible to the current package.
  • 10. Example of package that import the packagename.* 1. //save by A.java 2. 3. package pack; 4. public class A{ 5. public void msg(){System.out.println("Hello");} 6. } 1. //save by B.java 2. 3. package mypack; 4. import pack.*; 5. 6. class B{ 7. public static void main(String args[]){ 8. A obj = new A(); 9. obj.msg(); 10. } 11. } Output:Hello ________________________________________ Using packagename.classname If you import package.classname then only declared class of this package will be accessible. Example of package by import package.classname 1. //save by A.java 2. 3. package pack; 4. public class A{ 5. public void msg(){System.out.println("Hello");} 6. } 1. //save by B.java 2. 3. package mypack; 4. import pack.A;
  • 11. 5. 6. class B{ 7. public static void main(String args[]){ 8. A obj = new A(); 9. obj.msg(); 10. } 11. } Output:Hello ________________________________________ Using fully qualified name If you use fully qualified name then only declared class of this package will be accessible. Now there is no need to import. But you need to use fully qualified name every time when you are accessing the class or interface. It is generally used when two packages have same class name e.g. java.util and java.sql packages contain Date class. Example of package by import fully qualified name 1. //save by A.java 2. 3. package pack; 4. public class A{ 5. public void msg(){System.out.println("Hello");} 6. } 1. //save by B.java 2. 3. package mypack; 4. class B{ 5. public static void main(String args[]){ 6. pack.A obj = new pack.A();//using fully qualified name 7. obj.msg(); 8. } 9. } Output:Hello
  • 12. Note: Sequence of the program must be package then import then class. ________________________________________ ________________________________________ Access Modifiers There are two types of modifiers in java: access modifier and non-access modifier. The access modifiers specifies accessibility (scope) of a datamember, method, constructor or class. There are 4 types of access modifiers: 1. private 2. default 3. protected 4. public There are many non-access modifiers such as static, abstract etc. Here, we will learn access modifiers. ________________________________________ 1) private The private access modifier is accessible only within class. Simple example of private access modifier In this example, we have created two classes A and Simple. A class contains private data member and private method. We are accessing these private members from outside the class, so there is compile time error. 1. class A{ 2. private int data=40; 3. private void msg(){System.out.println("Hello java");} 4. } 5. 6. public class Simple{ 7. public static void main(String args[]){ 8. A obj=new A(); 9. System.out.println(obj.data);//Compile Time Error 10. obj.msg();//Compile Time Error 11. } 12. } Role of Private Constructor: If you make any class constructor private, you cannot create the instance of that class from outside the
  • 13. class. For example: 1. class A{ 2. private A(){}//private constructor 3. 4. void msg(){System.out.println("Hello java");} 5. } 6. 7. public class Simple{ 8. public static void main(String args[]){ 9. A obj=new A();//Compile Time Error 10. } 11. } ________________________________________ 2) default If you don't use any modifier, it is treated as default bydefault. The default modifier is accessible only within package. Example of default access modifier In this example, we have created two packages pack and mypack. We are accessing the A class from outside its package, since A class is not public, so it cannot be accessed from outside the package. 1. //save by A.java 2. 3. package pack; 4. class A{ 5. void msg(){System.out.println("Hello");} 6. } 1. //save by B.java 2. 3. package mypack; 4. import pack.*; 5. 6. class B{ 7. public static void main(String args[]){ 8. A obj = new A();//Compile Time Error
  • 14. 9. obj.msg();//Compile Time Error 10. } 11. } In the above example, the scope of class A and its method msg() is default so it cannot be accessed from outside the package. ________________________________________ 3) protected The protected access modifier is accessible within package and outside the package but through inheritance only. The protected access modifier can be applied on the data member, method and constructor. It can't be applied on the class. Example of protected access modifier In this example, we have created the two packages pack and mypack. The A class of pack package is public, so can be accessed from outside the package. But msg method of this package is declared as protected, so it can be accessed from outside the class only through inheritance. 1. //save by A.java 2. 3. package pack; 4. public class A{ 5. protected void msg(){System.out.println("Hello");} 6. } 1. //save by B.java 2. 3. package mypack; 4. import pack.*; 5. 6. class B extends A{ 7. public static void main(String args[]){ 8. B obj = new B(); 9. obj.msg(); 10. } 11. } Output:Hello
  • 15. ________________________________________ 4) public The public access modifier is accessible everywhere. It has the widest scope among all other modifiers. Example of public access modifier 1. //save by A.java 2. 3. package pack; 4. public class A{ 5. public void msg(){System.out.println("Hello");} 6. } 1. //save by B.java 2. 3. package mypack; 4. import pack.*; 5. 6. class B{ 7. public static void main(String args[]){ 8. A obj = new A(); 9. obj.msg(); 10. } 11. } Output:Hello Understanding all java access modifiers Let's understand the access modifiers by a simple table. Access Modifier within class within package outside package by subclass only outside package Private Y N N N Default Y Y N N Protected Y Y Y N Public Y Y Y Y ________________________________________ Applying access modifier with method overriding If you are overriding any method, overridden method (i.e. declared in subclass) must not be more restrictive.
  • 16. 1. class A{ 2. protected void msg(){System.out.println("Hello java");} 3. } 4. 5. public class Simple extends A{ 6. void msg(){System.out.println("Hello java");}//C.T.Error 7. public static void main(String args[]){ 8. Simple obj=new Simple(); 9. obj.msg(); 10. } 11. } The default modifier is more restrictive than protected. That is why there is compile time error. Encapsulation in Java Encapsulation is a process of wrapping code and data together into a single unit e.g. capsule i.e mixed of several medicines. We can create a fully encapsulated class by making all the data members of the class private. Now we can use setter and getter methods to set and get the data in it. Array in Java Normally, array is a collection of similar type of elements that have contiguous memory location. In java, array is an object the contains elements of similar data type. It is a data structure where we store similar elements. We can store only fixed elements in an array. Array is index based, first element of the array is stored at 0 index. Advantage of Array • Code Optimization: It makes the code optimized, we can retrieve or sort the data easily. • Random access: We can get any data located at any index position. ________________________________________ Disadvantage of Array • Size Limit: We can store only fixed size of elements in the array. It doesn't grow its size at runtime. To solve this problem, collection framework is used in java. ________________________________________ Types of Array
  • 17. There are two types of array. • Single Dimensional Array • Multidimensional Array ________________________________________ Single Dimensional Array Syntax to Declare an Array in java 1. dataType[] arrayRefVar; (or) 2. dataType []arrayRefVar; (or) 3. dataType arrayRefVar[]; Instantiation of an Array in java 1. arrayRefVar=new datatype[size]; Example of single dimensional java array Let's see the simple example of java array, where we are going to declare, instantiate, initialize and traverse an array. 1. class B{ 2. public static void main(String args[]){ 3. 4. int a[]=new int[5];//declaration and instantiation 5. a[0]=10;//initialization 6. a[1]=20; 7. a[2]=70; 8. a[3]=40; 9. a[4]=50; 10. 11. //printing array 12. for(int i=0;i<a.length;i++)//length is the property of array 13. System.out.println(a[i]); 14. 15. }} Output: 10 20 70 40
  • 18. 50 ________________________________________ Declaration, Instantiation and Initialization of Java Array We can declare, instantiate and initialize the java array together by: 1. int a[]={33,3,4,5};//declaration, instantiation and initialization Let's see the simple example to print this array. 1. class B{ 2. public static void main(String args[]){ 3. 4. int a[]={33,3,4,5};//declaration, instantiation and initialization 5. 6. //printing array 7. for(int i=0;i<a.length;i++)//length is the property of array 8. System.out.println(a[i]); 9. 10. }} Output:33 3 4 5 ________________________________________ Passing Java Array in the method We can pass the array in the method so that we can reuse the same logic on any array. Let's see the simple example to get minimum number of an array using method. 1. class B{ 2. static void min(int arr[]){ 3. int min=arr[0]; 4. for(int i=1;i<arr.length;i++) 5. if(min>arr[i]) 6. min=arr[i]; 7.
  • 19. 8. System.out.println(min); 9. } 10. 11. public static void main(String args[]){ 12. 13. int a[]={33,3,4,5}; 14. min(a);//passing array in the method 15. 16. }} Output:3 ________________________________________ Multidimensional array In such case, data is stored in row and column based index (also known as matrix form). Syntax to Declare Multidimensional Array in java 1. dataType[][] arrayRefVar; (or) 2. dataType [][]arrayRefVar; (or) 3. dataType arrayRefVar[][]; (or) 4. dataType []arrayRefVar[]; Example to instantiate Multidimensional Array in java 1. int[][] arr=new int[3][3];//3 row and 3 column Example to initialize Multidimensional Array in java 1. arr[0][0]=1; 2. arr[0][1]=2; 3. arr[0][2]=3; 4. arr[1][0]=4; 5. arr[1][1]=5; 6. arr[1][2]=6; 7. arr[2][0]=7; 8. arr[2][1]=8; 9. arr[2][2]=9; Example of Multidimensional java array Let's see the simple example to declare, instantiate, initialize and print the 2Dimensional array. 1. class B{
  • 20. 2. public static void main(String args[]){ 3. 4. //declaring and initializing 2D array 5. int arr[][]={{1,2,3},{2,4,5},{4,4,5}}; 6. 7. //printing 2D array 8. for(int i=0;i<3;i++){ 9. for(int j=0;j<3;j++){ 10. System.out.print(arr[i][j]+" "); 11. } 12. System.out.println(); 13. } 14. 15. }} Output:1 2 3 2 4 5 4 4 5 ________________________________________ ________________________________________ Copying an array We can copy an array to another by the arraycopy method of System class. Syntax of arraycopy method 1. public static void arraycopy( 2. Object src, int srcPos,Object dest, int destPos, int length 3. ) Example of arraycopy method 1. class ArrayCopyDemo { 2. public static void main(String[] args) { 3. char[] copyFrom = { 'd', 'e', 'c', 'a', 'f', 'f', 'e', 4. 'i', 'n', 'a', 't', 'e', 'd' }; 5. char[] copyTo = new char[7]; 6. 7. System.arraycopy(copyFrom, 2, copyTo, 0, 7);
  • 21. 8. System.out.println(new String(copyTo)); 9. } 10. } Output:caffein ________________________________________ Addition 2 matrices Let's see a simple example that adds two matrices. 1. class AE{ 2. public static void main(String args[]){ 3. //creating two matrices 4. int a[][]={{1,3,4},{3,4,5}}; 5. int b[][]={{1,3,4},{3,4,5}}; 6. 7. //creating another matrix to store the sum of two matrices 8. int c[][]=new int[2][3]; 9. 10. //adding and printing addition of 2 matrices 11. for(int i=0;i<2;i++){ 12. for(int j=0;j<3;j++){ 13. c[i][j]=a[i][j]+b[i][j]; 14. System.out.print(c[i][j]+" "); 15. } 16. System.out.println();//new line 17. } 18. 19. }} Output:2 6 8 6 8 10
  • 22. Lab exercises Model 2(Lab) 1.Wrire a Proram to creat a class that stores the train reservation details. In addition, define a method that will display the stored details. public class Reservation { int ticketID; String name; String source; String destination; Reservation() { ticketID = 80; name ="Harry"; source = "Chicago" destination = "Dallas"; } public void showTicket () { System.out.println("The Ticket ID is "+ ticketID); System.out.println("The Passenger Name is "+ name); System.out.println("The Sourse is" + sourse); System.out.println("The Destination is" + Destination); System.out.println("nChoose the option: "); public static void main(String[] args) {
  • 23. Reservation g = new Reservation(); g.showTicket(); } } Q 2. Write a program to create a class named EmployeeDetails and display a menue similar to the following menu: --------------Menu-------- 1. Enter Data 2. Display Data 3. Exit Choose the option Thereafter, invoke the respective method according to the given menu input. The methods will contain appropriate message, such as the displayData() method will contain the message, displayData method is invoked public class EmployeeDetails { public void showMenue () { int option; System.out.println("------------Menu--------"); System.out.println("1. Enter Data"); System.out.println("2. Display Data"); System.out.println("3. Exit"); System.out.println("nChoose the option: "); Option = 2; switch (option) {
  • 24. case 1: enterData(); break; case2: DisplayData(); break; case3: exitMenue(); break; defalt: System.out.println("Incorrect menu option"); showMenu(); break; } } public void enterData() { System.out.println("enterData method is invoked"); } public void enterData() { System.out.println("displayData method is invoked"); } public void enterData() { System.out.println("exitMenu method is invoked"); System.exit(0); } public static void main(String[] args) { EmployeeDetails obj = new EmployeeDetails(); obj.showMenu();
  • 25. } } 3.Write a program to create a class that stores the grocery details. In addition, define three methods that will add the weight, remove the weight, and display the current weight, respectively.. 4.Write a program to create a class that declares a member variable and a member method. The member method will display the value of the member variable. Ans.Q 4. Write a program that will store the employee records, such as employee ID, employee name, department, designation, date of joining, date of birth, and marital status, in an array. In addition, the stored record needs to
  • 26. be displayed. Ans public class employeerecord string employeeDetails [] [] = new String [1] [7]; public void storeData() { employeeDeatils [0] [0] = "A101"; employeeDeatils [0] [1] = "john mathew"; employeeDetails [0] [2] = "admin"; employeeDetails [0] [3] = "manager"; employeeDetails [0] [4] = "05/04/1998"; employeeDetails [0] [5] = "11/09/1997"; employeeDetails [0] [6] = "married"; } public void displayData() { system.out.println ("Employee Details:"); for ( int i = 0; i < employeeDetails,length; for ( int j = 0; j < employeeDetails[i].length; j++ { system.out.println(employeeDetails[i] [j] ); } } } public static void main (String [] args) { EmployeeRecord obj = new EmployeeRecord(); obj.storeData(); obj.displayData(); }
  • 27. } 5.Write a program to identify whether the given character is a vowel or a consonant. Ans. 6.Write a program to display the following numeric pattern: 12345 1234 123 12 1 Ans
  • 28. .7.Using the NetBeans IDE, create an Employee class, create a class with a main method to test the Employee class, compile and run your application, and print the results to the command line output. Ans. 1. start the NetBeans IDE by using the icon from desktop. 2. create a new project employeepractice in the D:labs02-reviewpractices directory with anemployeetest main class in the com.example package. 3. Set the source/binary format to JDK 7. a. right-click the project and select properties. b. select JDK 7 from the drop-down list for SOurc/binary format. c. click ok. 4. create another package called com.example.domain. 5. Add a java class called Employee in the com.example.domain package.
  • 29. 6. code the employee class. a. add the following data fields to the employee class-use your judgment as to what you want to call these fields in the class. Refer to the lesson material for ideas on the fields names and the syntax if you are not sure. Use public as the access modifier. 7. create a no-arg constructor for the employee class. Netbeans can format your code at any time for you. Right-click in the class and select format, or press the Alt-Shift-F key combination. 8. Add accessor/mutator methods for each of the fields. 9. write code in the employeetest class to test your employee class. a. construct an instance of employee. b. use the setter mothods to assign the following values to the instance: c. in the body of the main methoed, use the system.out.printIn method to write the values of the employee fields to the console output. d. rsolve any missing import statements. e. save the employeetest class. 10. run the EmployeePractice project. 11. Add some additional employee instances to your test class. http://mkniit.blogspot.in/2015/12/q-1.html