Upload
lavish-bansal
View
255
Download
0
Embed Size (px)
Citation preview
8/10/2019 Notepad Using Java
1/26
JAVAUsing NOTEPAD
Submitted by:
Lavish Bansal
Submitted to:
Mr Amit Monga
8/10/2019 Notepad Using Java
2/26
HISTORY OF C,C++ AND JAVA
C
1969-1973
Denis Ritche
A T & T Bell Lab
Windows
C++1975-1984
Bjarne
StrausStrupWindows
JAVA1991-1995
James Gosling
Sun MicrosystemsOracle
8/10/2019 Notepad Using Java
3/26
FEATURES OF OOPS
It has 4 main features:-
>Inheritance
>Encapsulation>Polymorphism
>Abstraction
8/10/2019 Notepad Using Java
4/26
What is JAVA?
A general purpose object-oriented Programing
language.
Write Once Run Anywhere (WORA).
Designed for easy web/internet applications
Widespread acceptance
It is case sensitive language. It is developed and deployed.
8/10/2019 Notepad Using Java
5/26
Why JAVAimportant ?
Two reasons :
Trouble with C/C++ language is that they are
not portable and are not platform
independent languages.
Emergence of World Wide Web, which
demanded portable programs
Portability and security necessitated the
invention of Java.
8/10/2019 Notepad Using Java
6/26
New features added in Java
Multithreading, that allows two or more pieces ofthe same program to execute concurrently.
C++ has a set of library functions that use acommon header file. But java replaces it with itsown set of APIclasses.
It adds packagesand interfaces.
Java supports automatic garbage collection.
Break and continue statements have beenenhanced in java to accept labels as targets.
The use of unicode characters ensures portability.
8/10/2019 Notepad Using Java
7/26
Features that differ:
Though C++ andjavasupports Boolean data type,
C++ takes any nonzerovalue as true and zero as
false. True and false in java are predefined literals
that are values for a boolean expression.
Java has replaced the destructor function with a
finalize() function.
C++ supports exception handling that is similar tojava's. However, in C++ there is no requirement
that a thrown exception be caught.
8/10/2019 Notepad Using Java
8/26
DATATYPE
Basically Data type is which type of value store
in variable.
SYNTAX ;
Int age;
It is of 2 types:
Primitive(Pre defined) and Reference(Userdefined).
8/10/2019 Notepad Using Java
9/26
ARRAYS
Array is a collection of variables of same
datatype.
SYNTAX [] = new
[];
Example:- int [] arr=new int [5];
8/10/2019 Notepad Using Java
10/26
PACKAGES
Packages are collection of classes or it act as a
container for different classes.
How to create a package?
PACKAGE ;
class abc
{};
8/10/2019 Notepad Using Java
11/26
CONSTRUCTOR
Class name and constructor name must be same.
It do not have any return type.
It is called when we create object of class.
It is used to initialise and store the variable.
Class hh
{
int a;
hh(){a=10;
}
8/10/2019 Notepad Using Java
12/26
INHERITANCE
It is basically reusability ,like parent->child ,
super class->sub class.
SYNTAX :- extends
Type of inheritance:-
>single
>multilevel>multiple
8/10/2019 Notepad Using Java
13/26
Overriding & overloading
Overriding is function name and function
signature should be same.
Overlaoding is function name is same and
function signature is different.
8/10/2019 Notepad Using Java
14/26
SUPER KEYWORD AND SUPER
METHOD
A subclass method can invoke a superclass
method using the super keyword.
Super method is used for invoking parent
parameter constuctor.
Example:-
l
8/10/2019 Notepad Using Java
15/26
class person
{
String firstname;
String lastname;
person(String fname,String lname)
{firstname=fname;lastname=lname;
}
void display()
{System.out.println("person:");
System.out.println("firstname:"+firstname);
System.out.println("lastname:"+lastname);}
}
class student extends person
{
int id;
String standard;String instructor;
student(String fname,String lname,int nld,String stnd,String instr)
{
super(fname,lname);
id=nld;standard=stnd;
8/10/2019 Notepad Using Java
16/26
instructor=instr;
}
void display()
{
System.out.println("student:");super.display();
System.out.println("id:"+id);
System.out.println("standard:"+standard);
System.out.println("instructor:"+instructor);
}
}class teacher extends person
{
String mainsubject;
String type;
int salary;
teacher(String fname,String lname,String sub,int slry,String stype)
{
super(fname,lname);
mainsubject=sub;
salary=slry;
8/10/2019 Notepad Using Java
17/26
type=stype;
}
void display()
{
System.out.println("teacher:");
super.display();
System.out.println("mainsubject:"+mainsubject);
System.out.println("salary:"+salary);
System.out.println("type:"+type);
}
}
class inheritancedemo
{
public static void main(String arr[])
{
person pobj=new person("rayan","miller");student sobj=new student("jacob","smith",1,"1-b","roma");
teacher tobj=new teacher("daniel","mart","english",6000,"primary teacher");
pobj.display();
sobj.display();
tobj.display();}}
8/10/2019 Notepad Using Java
18/26
ABSTRACT CLASS
Abstract is a keyword used along with classes
and methods.
In this we only declare the methods , we
define these methods in there child class.
Abstract class use only abstract methods.
Example:-
8/10/2019 Notepad Using Java
19/26
Abstract class dd
{
public abstract void a();
public abstract void b();
}
class s extends dd
{
public void a()
{
int a=10;
System.out.println(a);
}public void b()
{int bb=10;
System.out.println(bb);
public static void main(String arr[])
{
s.b=new s();
b.a();b.bb();
}}
8/10/2019 Notepad Using Java
20/26
INTERFACE
It is used for multiple inheritance.
In interface we only declare the methods , we definethese methods in there child class.
Example:-
Interface kk{
}
Interface gg
{
}
Class s implements kk,gg
8/10/2019 Notepad Using Java
21/26
EXCEPTION HANDLING
Basically we have 3 types of errors:-
>Syntax error- occurs at compilation time
>Logical error- can occur at compile time or run
time>Runtime error- basically unexpected
So to resolve this we use exception handling.
It has 3 blocks:-
> Try used where exception can occur.> Catchused to handle the exception.
>Finallyalways run.
8/10/2019 Notepad Using Java
22/26
EXAMPLE OF EXCEPTION HANDLING class ex
{ public static void main(String[]arr)
{
try
{
String aa=arr[0]; int a=Integer.parseInt(arr[1]);
int b=Integer.parseInt(arr[2]);
int c=a/b;
System.out.println(c);
System.out.println(aa);
System.out.println(b);
}
catch(Exception e)
{
System.out.println(e);
}
8/10/2019 Notepad Using Java
23/26
USER DEFINED EXCEPTION
It is when the user defined his/her definesthere own exception.
It uses 2 keywords throw and throws.
Throws clause is used to declare an exceptionand throw keyword is used to throw anexception explicitly.
The keyword throw is used inside methodbodyand throws clause is used in methoddeclaration.
8/10/2019 Notepad Using Java
24/26
G U I
Defined as graphical user interface.
Till now we had used it on black command
window but from now we will se how it will
work and we will visualise it .
Example:- import java. Awt.*;
Awt=abstract window toolkit
The child class of awt is swingx
Example:-import javax.swing.*;
8/10/2019 Notepad Using Java
25/26
CONSTRUCTION OF FRAME
Import javax.swing.*;
Class cont
{
Jframe f;
Jbutton b;
cont()
{
f=new Jframe (welcome);
b=new Jbutton(submit);
}
Public void aa()
{f.add(b);
f.setSize(100,100);
f.setvisible(true);
Public static void main(String arrr[])
{cont v=new cont();
v.aa();}}
8/10/2019 Notepad Using Java
26/26
Thank You