SlideShare a Scribd company logo
JAVA PROGRAMMING
"Write once, run anywhere"
Name : Saransh Kumawat
Branch : 3rd
Year IT
Simple Program in JAVA
package oop; //importing the package
public class Test
{
public static void main(String [] args)
{
System.out.println(“basic java program”);
}
}
Constructor in Java
Types of Constructor in java
1. Default constructor //no argument
2. User-define constructor //any no. of argument
•It is an special type of method that has same name as the class name itself .
•It does not specify any return type not even void.
•Constructors are invoked at the time object creation .
•It is used to initialize the object .
package q8C;
import java.util.Scanner;
public class Digit
{
static int n;
Digit()
{
int fd,ld,sum;
Scanner sc=new Scanner(System.in);
System.out.println("enter a 5 digit number :");
n=sc.nextInt();
fd=n/10000;
ld= n%10;
sum=ld+fd;
System.out.println("the sum is "+ sum);
}
public static void main(String[] args)
{
Digit n = new Digit();// creating object of constructor
}
}
OUTPUT : enter a 5 digit number : 12345
the sum is 6
}
}
package cw;
// parameterized constructor
public class C2007
{
C2007(String ch)
{
System.out.println(ch);
}
public static void main(String[] args)
{
C2007 t= new C2007("Am parameterized constructor");
}
}
**BRIEF BREAKDOWN**
//
In this code, we have used the parameterized constructor by passing a specific
argument when initializing the object of C2007 class.
The Argument is passed to the constructor as a String type and will be stored
In the ch variable.
//
Methods in JAVA
Types of Method
1. Instance method
2. Static method
• Methods are used to provide logic of the project.
• It also specifies behavior. A method is also called function in C.
• Inside the class, it is possible to declare any no. of methods based on
developer requirement, it will improve reusability of the code, and we
can optimize the code.
1. Instance method
Example: void m1()
{
// this area is called instance area
}
2. Static method
Example: static void m1()
{
// this area is called static area
}
package cw;
public class B1907 //instance with parameters
{
public void IT(int i ,String ch)
{
System.out.println(i+ " " + ch);
}
public static void main(String[] args)
{
B1907 b= new B1907();
b.IT(1, “Training in java");
}
}
}
***Breakdown of the code***
In this code, IT is an instance method which is printing the String
we passed by first creating the object of the class and using the object we
called the method IT for performing the desired output.
package cw;
public class D1907
{ //static function with parameter
passing
static void IT(int i,String ch)
{
System.out.println(i + " "+ ch);
}
public static void main(String[] args)
{
IT(1,"hello");
}
}
**breakdown of the code**
In this code I showed the use of static function by using the keyword “static”
before the method IT, with the static method, the method can be called without
creating any object of it.
Errors and Exceptions in Java
• In Java, errors and exceptions are both conditions that indicate
something has gone wrong, but they differ in several ways.
• Errors are caused by system or environmental issues, such as hardware
failures, while exceptions are caused by issues in the application code.
• Errors are not recoverable and cause the program to terminate
abnormally, while exceptions can be caught and recovered.
• TYPES OF EXCEPTIONS :
1.Check
2.Uncheck
3.Error
Check Exceptions
These exceptions occur at compile time :
• ClassNotFoundException
• NoSuchException
• IllegalAccesException
• NoSuchFieldException
• InteruptedException
Uncheck Exceptions
These exceptions occur during runtime :
• ArithmeticException
• ArrayIndexOutOfBoundsException
• NullPointerException
• InputMismatchException
• IllegalArgumentException
Error
Error occur due to a lack of system resources.
E.g.
•StackOverflow error
•OutOfMemory error
•Assertion error
Try – Catch Block in Java
In Java, the try-catch block is used for handling exceptions
(runtime errors).
It allows the programmer to define a block of code to be
tested for exceptions, and if an exception occurs,
it can be caught and handled.
package nul;
class Test
{
public static void main(String args[])
{
int a= 10;
int b = 5,c=5;
int x, y;
try
{
x=a/(b-c);
}
catch(ArithmeticException e)
{
System.out.println("division by zero");
}
y= a/b + c;
System.out.println(“y = " + y);
}
}

More Related Content

Similar to JAVA PROGRAMMING presentation for engineering student.pptx (20)

PDF
Java basic concept
University of Potsdam
 
PPTX
Java For Automation
Abhijeet Dubey
 
PPTX
Computer programming 2 Lesson 15
MLG College of Learning, Inc
 
PPTX
constructors.pptx
Epsiba1
 
PPTX
Object Oriented Programming unit 1 content for students
ASHASITTeaching
 
PPTX
Lecture_4_Static_variables_and_Methods.pptx
IkaDeviPerwitasari1
 
PPTX
UNIT 3- Java- Inheritance, Multithreading.pptx
shilpar780389
 
PPTX
BCA Class and Object (3).pptx
SarthakSrivastava70
 
PPT
Corejava Training in Bangalore Tutorial
rajkamaltibacademy
 
PPTX
CH1 ARRAY (1).pptx
AnkitaVerma776806
 
PPT
METHODS IN JAVA.ppt
JayanthiM15
 
PPTX
Static keyword.pptx
KishanMishra44
 
PPTX
6. static keyword
Indu Sharma Bhardwaj
 
PDF
JAVA Class Presentation.pdf Vsjsjsnheheh
AnushreeP4
 
PPTX
OOPSCA1.pptx
Soumyadipchanda2
 
PPTX
CJP Unit-1 contd.pptx
RAJASEKHARV10
 
PPTX
java: basics, user input, data type, constructor
Shivam Singhal
 
PPTX
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Sagar Verma
 
PPTX
1_JavIntro
SARJERAO Sarju
 
Java basic concept
University of Potsdam
 
Java For Automation
Abhijeet Dubey
 
Computer programming 2 Lesson 15
MLG College of Learning, Inc
 
constructors.pptx
Epsiba1
 
Object Oriented Programming unit 1 content for students
ASHASITTeaching
 
Lecture_4_Static_variables_and_Methods.pptx
IkaDeviPerwitasari1
 
UNIT 3- Java- Inheritance, Multithreading.pptx
shilpar780389
 
BCA Class and Object (3).pptx
SarthakSrivastava70
 
Corejava Training in Bangalore Tutorial
rajkamaltibacademy
 
CH1 ARRAY (1).pptx
AnkitaVerma776806
 
METHODS IN JAVA.ppt
JayanthiM15
 
Static keyword.pptx
KishanMishra44
 
6. static keyword
Indu Sharma Bhardwaj
 
JAVA Class Presentation.pdf Vsjsjsnheheh
AnushreeP4
 
OOPSCA1.pptx
Soumyadipchanda2
 
CJP Unit-1 contd.pptx
RAJASEKHARV10
 
java: basics, user input, data type, constructor
Shivam Singhal
 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Sagar Verma
 
1_JavIntro
SARJERAO Sarju
 

Recently uploaded (20)

PDF
Statistical Data Analysis Using SPSS Software
shrikrishna kesharwani
 
PDF
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
PPTX
EC3551-Transmission lines Demo class .pptx
Mahalakshmiprasannag
 
PPTX
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
PPTX
Innowell Capability B0425 - Commercial Buildings.pptx
regobertroza
 
PPTX
Pharmaceuticals and fine chemicals.pptxx
jaypa242004
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PPTX
Break Statement in Programming with 6 Real Examples
manojpoojary2004
 
DOCX
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
PPTX
Green Building & Energy Conservation ppt
Sagar Sarangi
 
PPTX
UNIT DAA PPT cover all topics 2021 regulation
archu26
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PPTX
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
PDF
Water Design_Manual_2005. KENYA FOR WASTER SUPPLY AND SEWERAGE
DancanNgutuku
 
PPTX
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
PPTX
ISO/IEC JTC 1/WG 9 (MAR) Convenor Report
Kurata Takeshi
 
PDF
Zilliz Cloud Demo for performance and scale
Zilliz
 
PDF
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
PDF
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
Statistical Data Analysis Using SPSS Software
shrikrishna kesharwani
 
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
EC3551-Transmission lines Demo class .pptx
Mahalakshmiprasannag
 
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
Innowell Capability B0425 - Commercial Buildings.pptx
regobertroza
 
Pharmaceuticals and fine chemicals.pptxx
jaypa242004
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
Break Statement in Programming with 6 Real Examples
manojpoojary2004
 
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
Green Building & Energy Conservation ppt
Sagar Sarangi
 
UNIT DAA PPT cover all topics 2021 regulation
archu26
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
artificial intelligence applications in Geomatics
NawrasShatnawi1
 
Water Design_Manual_2005. KENYA FOR WASTER SUPPLY AND SEWERAGE
DancanNgutuku
 
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
ISO/IEC JTC 1/WG 9 (MAR) Convenor Report
Kurata Takeshi
 
Zilliz Cloud Demo for performance and scale
Zilliz
 
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
Ad

JAVA PROGRAMMING presentation for engineering student.pptx

  • 1. JAVA PROGRAMMING "Write once, run anywhere" Name : Saransh Kumawat Branch : 3rd Year IT
  • 2. Simple Program in JAVA package oop; //importing the package public class Test { public static void main(String [] args) { System.out.println(“basic java program”); } }
  • 3. Constructor in Java Types of Constructor in java 1. Default constructor //no argument 2. User-define constructor //any no. of argument •It is an special type of method that has same name as the class name itself . •It does not specify any return type not even void. •Constructors are invoked at the time object creation . •It is used to initialize the object .
  • 4. package q8C; import java.util.Scanner; public class Digit { static int n; Digit() { int fd,ld,sum; Scanner sc=new Scanner(System.in); System.out.println("enter a 5 digit number :"); n=sc.nextInt(); fd=n/10000; ld= n%10; sum=ld+fd; System.out.println("the sum is "+ sum); } public static void main(String[] args) { Digit n = new Digit();// creating object of constructor } } OUTPUT : enter a 5 digit number : 12345 the sum is 6 } }
  • 5. package cw; // parameterized constructor public class C2007 { C2007(String ch) { System.out.println(ch); } public static void main(String[] args) { C2007 t= new C2007("Am parameterized constructor"); } } **BRIEF BREAKDOWN** // In this code, we have used the parameterized constructor by passing a specific argument when initializing the object of C2007 class. The Argument is passed to the constructor as a String type and will be stored In the ch variable. //
  • 6. Methods in JAVA Types of Method 1. Instance method 2. Static method • Methods are used to provide logic of the project. • It also specifies behavior. A method is also called function in C. • Inside the class, it is possible to declare any no. of methods based on developer requirement, it will improve reusability of the code, and we can optimize the code.
  • 7. 1. Instance method Example: void m1() { // this area is called instance area } 2. Static method Example: static void m1() { // this area is called static area }
  • 8. package cw; public class B1907 //instance with parameters { public void IT(int i ,String ch) { System.out.println(i+ " " + ch); } public static void main(String[] args) { B1907 b= new B1907(); b.IT(1, “Training in java"); } } } ***Breakdown of the code*** In this code, IT is an instance method which is printing the String we passed by first creating the object of the class and using the object we called the method IT for performing the desired output.
  • 9. package cw; public class D1907 { //static function with parameter passing static void IT(int i,String ch) { System.out.println(i + " "+ ch); } public static void main(String[] args) { IT(1,"hello"); } } **breakdown of the code** In this code I showed the use of static function by using the keyword “static” before the method IT, with the static method, the method can be called without creating any object of it.
  • 10. Errors and Exceptions in Java • In Java, errors and exceptions are both conditions that indicate something has gone wrong, but they differ in several ways. • Errors are caused by system or environmental issues, such as hardware failures, while exceptions are caused by issues in the application code. • Errors are not recoverable and cause the program to terminate abnormally, while exceptions can be caught and recovered. • TYPES OF EXCEPTIONS : 1.Check 2.Uncheck 3.Error
  • 11. Check Exceptions These exceptions occur at compile time : • ClassNotFoundException • NoSuchException • IllegalAccesException • NoSuchFieldException • InteruptedException
  • 12. Uncheck Exceptions These exceptions occur during runtime : • ArithmeticException • ArrayIndexOutOfBoundsException • NullPointerException • InputMismatchException • IllegalArgumentException
  • 13. Error Error occur due to a lack of system resources. E.g. •StackOverflow error •OutOfMemory error •Assertion error
  • 14. Try – Catch Block in Java In Java, the try-catch block is used for handling exceptions (runtime errors). It allows the programmer to define a block of code to be tested for exceptions, and if an exception occurs, it can be caught and handled.
  • 15. package nul; class Test { public static void main(String args[]) { int a= 10; int b = 5,c=5; int x, y; try { x=a/(b-c); } catch(ArithmeticException e) { System.out.println("division by zero"); } y= a/b + c; System.out.println(“y = " + y); } }