Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Java Notes - Unit 1 Chapter 4

The document outlines the course B.Tech. (AIML/AI/DS) for OOP with Java, detailing course outcomes, prerequisites, and a comprehensive syllabus. Key topics include object-oriented programming concepts, Java packages, exception handling, and the use of the Spring Framework. It also discusses the differences between PATH and CLASSPATH, and introduces Java static import features.

Uploaded by

Vaibhav Pal
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Java Notes - Unit 1 Chapter 4

The document outlines the course B.Tech. (AIML/AI/DS) for OOP with Java, detailing course outcomes, prerequisites, and a comprehensive syllabus. Key topics include object-oriented programming concepts, Java packages, exception handling, and the use of the Spring Framework. It also discusses the differences between PATH and CLASSPATH, and introduces Java static import features.

Uploaded by

Vaibhav Pal
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Department of Applied Computational Science & Engg.

Program: B.Tech. (AIML/AI/DS)


Course Code: BCS403
Course Name: OOP with Java
Lecture No: 04
Department of Applied Computational Science & Engg.
Course Code : BCS403 Course Name: OPP with Java

Course Outcomes :

CO1 Develop the object-oriented programming concept using Java


Implement exception handling, file handling and multi-threading in
CO2 Java

CO3 Apply new Java features to build java programs

CO4 Analyse Java programs with collection Framework


Test web and RESTful web services with spring boot using Spring
CO5 Framework concepts

Program Name: B. Tech (AIML/AI/DS) Program Code:


Department of Applied Computational Science & Engg.
Course Code : BCS403 Course Name: OOP with Java

Course Prerequisites
Basic Programming Concepts
Procedural Programming
Understanding Algorithms and Problem Solving
Memory Management
Data Structures
Basic Command-Line Usage
Understanding of Databases

Program Name: B. Tech (AIML/AI/DS) Program Code:


Department of Applied Computational Science & Engg.
Course Code : BCS403 Course Name: OOP with Java

Syllabus
Unit - 1
• Introduction: Why Java, History of Java, JVM, JRE, Java Environment, Java
Source File Structure, and Compilation. Fundamental,
• Programming Structures in Java: Defining Classes in Java, Constructors, Methods,
Access Specifies, Static Members, Final Members, Comments, Data types,
Variables, Operators, Control Flow, Arrays & String.
• Object Oriented Programming: Class, Object, Inheritance Super Class, Sub Class,
Overriding, Overloading, Encapsulation, Polymorphism, Abstraction, Interfaces,
and Abstract Class.
• Packages: Defining Package, CLASSPATH Setting for Packages, Making JAR
Files for Library Packages, Import and Static Import Naming Convention For
Packages

Program Name: Program Code:


Department of Applied Computational Science & Engg.
Course Code : Course Name:

• Lecture Objectives
To understand Java definition, Java environment, Java program
structure and compilation of java program
Department of Applied Computational Science & Engg.
Course Code : Course Name:

• Lecture Outcomes
Develop the object-oriented programming concept using Java
Department of Applied Computational Science & Engg.
Course Code : Course Name:

Package in Java
• A java package is a group of similar types of classes, interfaces and sub-packages.
• Package in java 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 Java Package
• 1) Java package is used to categorize the classes and interfaces so that they can be easily maintained.
• 2) Java package provides access protection.
• 3) Java package removes naming collision.
• 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.
Department of Applied Computational Science & Engg.
Course Code : Course Name:

Package in Java
• 1) Using package_name.*
• If you use package.* then all the classes and interfaces of this package will be accessible but not sub
packages.
• 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 package_name.*
1. //save by A.java
2. package pack;
3. public class A{
4. public void msg(){System.out.println("Hello");}
5. }
6. //save by B.java
7. package mypack;
8. import pack.*;
9.
10. class B{
11. public static void main(String args[]){
12. A obj = new A();
13. obj.msg();
14. }
15. }
• Output:
• Hello
Department of Applied Computational Science & Engg.
Course Code : Course Name:

Package in Java
• 1) Using package_name.*
• If you use package.* then all the classes and interfaces of this package will be accessible but not sub
packages.
• 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 package_name.*
1. //save by A.java
2. package pack;
3. public class A{
4. public void msg(){System.out.println("Hello");}
5. }
6. //save by B.java
7. package mypack;
8. import pack.*;
9.
10. class B{
11. public static void main(String args[]){
12. A obj = new A();
13. obj.msg();
14. }
15. }
• Output:
• Hello
Department of Applied Computational Science & Engg.
Course Code : Course Name:

Package in Java
• 2) Using packagename.classname
1. //save by A.java
2.
3. package pack;
4. public class A{
5. public void msg(){System.out.println("Hello");}
6. }
7. //save by B.java
8. package mypack;
9. import pack.A;
10.
11. class B{
12. public static void main(String args[]){
13. A obj = new A();
14. obj.msg();
15. }
16. }
• Output:Hello
Department of Applied Computational Science & Engg.
Course Code : Course Name:

Package in Java
• 3) Using fully qualified name
1. //save by A.java
2. package pack;
3. public class A{
4. public void msg(){System.out.println("Hello");}
5. }
6. //save by B.java
7. package mypack;
8. class B{
9. public static void main(String args[]){
10. pack.A obj = new pack.A();//using fully qualified name
11. obj.msg();
12. }
13. }
• Output:
• Hello
Department of Applied Computational Science & Engg.
Course Code : Course Name:

Setting CLASSPATH in Java


Department of Applied Computational Science & Engg.
Course Code : Course Name:

Setting CLASSPATH in Java


Department of Applied Computational Science & Engg.
Course Code : Course Name:

Setting CLASSPATH in Java


Department of Applied Computational Science & Engg.
Course Code : Course Name:

Difference between PATH and CLASSPATH


PATH CLASSPATH
PATH is an environment variable. CLASSPATH is also an environment variable.

It is used by the operating system to find the It is used by Application ClassLoader to locate
executable files (.exe). the .class file.

You are required to include the directory which You are required to include all the directories
contains .exe files. which contain .class and JAR files.

PATH environment variable once set, cannot be The CLASSPATH environment variable can be
overridden. overridden by using the command line option -
cp or -CLASSPATH to both javac and java
command.
Department of Applied Computational Science & Engg.
Course Code : Course Name:

Java Static Import


• Java Static Import
• The static import feature of Java 5 facilitate the java programmer to access any static member of a class
directly. There is no need to qualify it by the class name.
• Advantage of static import:
• Less coding is required if you have access any static member of a class oftenly.
• Disadvantage of static import:
• If you overuse the static import feature, it makes the program unreadable and unmaintainable.
• Simple Example of static import
1. import static java.lang.System.*;
2. class StaticImportExample{
3. public static void main(String args[]){
4.
5. out.println("Hello");//Now no need of System.out
6. out.println("Java");
7.
8. }
9. }

Output:Hello
Java
Department of Applied Computational Science & Engg.
Course Code : Course Name:

Recommended Books
Text books

Reference Book

Additional online materials

Program Name: Program Code:


THANK YOU

You might also like