Advanced Programming with Java-1
Advanced Programming with Java-1
t’s designed to be platform-independent, meaning code written in Java can run on any device
that has the Java Virtual Machine (JVM). This idea is summed up in the Java slogan: "Write once,
run anywhere."
It was originally called Oak by James Goslin (One of the inventors of Java)
-Object Oriented Programming tries to map code instructions with real world making the code
short and easier to understand.
-Solving a problem by creating objects is one of the most popular approaches in programming.
This is called Object Oriented Programming.
What is DRY?
Java Architecture:
Java is compiled into the bytecode and then it is interpreted to machine code.
Java Installation
Go to Google and type “Install JDK” -> Install JAVA JDK
Go to Google and type “install IntelliJ Idea” -> Install JAVA IDE
JDK-> JAVA Development Kit = Collection of tools used for developing and running Java
programs.
• The filename should match the public class name (Main in this example).
main Method:
• public: accessible from anywhere
Objects-: In Java programming, objects are the core building blocks of object-oriented
programming (OOP). An object is an instance of a class, and it represents a real-world entity
with state and behavior.
Class-: A class is a blueprint for creating objects.
Filled by students
MBBS form Form for student
Naming Conventions: -
For Classes, we use Pascal Convention. Example Main, MyScanner, MyEmployee
1. Default Constructor
2. Parameterized Constructor
Packages-
In Java, packages are used to group related classes, interfaces, and sub-
packages. Think of them like folders on your computer that organize files to keep
things neat and manageable.
-Access modifiers determine whether other classes can use a particular field or invoke a method
can be public, private, protected or default (no modifier)
1. public
2. default
3. protected
4. private
1. Public -:
-Accessible from everywhere – any other class, whether in the same package or different
package.
2. private-: Accessible only within the same class.
- Not visible to other classes or even subclasses.
-Commonly used to hide internal details (encapsulation).
3. protected
• Accessible within the same package and in subclasses (even in other packages).
• Great for inheritance when you want to limit but still allow access in child classes.
What is an Exception?
An exception is an unwanted or unexpected event that
disrupts the normal flow of the program.
Examples:
• Dividing a number by zero
• Accessing an array index that doesn’t exist
• Opening a file that doesn't exist
Exception Handling Keywords in Java
1. try – contains the code that might throw an exception
2. catch – handles the exception
3. finally – block that always executes (used to clean up)
4. throw – used to throw an exception
5. throws – declares exceptions in method signature
Java Collections-: Collections refer to a framework that provides architecture to
store, retrieve, and manipulate groups of objects (like lists, sets, and maps).
-A collection represents a group of objects. Java collections provide Classes and Interfaces
for us to able to write code quickly and efficiently.
-We need Collections for efficient storage and better manipulation of data in java.
-To store, retrieve, manipulate, and communicate aggregate data.
- Provides ready-made data structures like Lists, Sets, Queues, Maps, etc.
-Saves time and effort (instead of creating your own data structures from scratch).
-Collections in Java are available as Classes and Interfaces. Following are few commonly used
collections in Java.