
Quick Contact
Java Tutorial
- What is Java?
- History of Java
- Hello Java Program
- Features of Java
- Basic Syntax
- Java Setup
- Data Types in Java
- Java Variables
- Operators in Java
- JVM
- Java If-else Statement
- Switch Case Statement
- Java Loops
- Do-While Loop
- Java While Loop
- Continue Statement
- Break Statement in Java
- Constructors in Java
- Oops Concept in Java
- Features of OOPs
- Inheritance
- Exeception handeling
- Aggregation (HAS-A relationship) in Java
- Method Overriding in Java
- Method Overloading
- Java Static Keyword
- Java This Keyword
- Java Final Keyword
- Polymorphism
- Static Binding and Dynamic Binding
- Abstract class in Java
- Access Modifiers in Java
- Difference between abstract class and interface
- Interface in Java
- Garbage Collection in Java
- Java Package
- Encapsulation
- Serialization and Deserialization in Java
- Java Inner Classes
- Java Applets
- Multithreading in Java
- Thread Priorities in Java
- Thread Creation
- Inter Thread Communication
- Wrapper Classes in Java
- Java Input Output
- Java AWT Introduction
- Java Layout Manager
- Java Layout Policy
- Java AWT Events
- Collection Framework
- Collection Framework List Interface
- Swing in Java
- Swing Utility Classes
- Swing Layout Managers
- Java JDBC
- Hibernate Framework Overview – Architecture and Basics
Springboot
- Spring Environment Setup
- Spring Boot CRUD REST API Project using IntelliJ IDEA | Postman | MySQL
- Dockerizing Spring Boot Application | Spring Boot Docker Tutorial
- spring-boot-restapidocumentation with swagger
- Spring Boot HttpClient Overview
- Apache HttpClient POST HTTP Request Example
- Apache HttpClient PUT HTTP Request Example
- Apache HttpClient DELETE HTTP Request Example
- Apache HttpClient HTML Form POST Request Example
- Spring Boot JSP Exampl
- Deploying Spring Boot WAR file with JSP to Tomcat
- Spring Boot Annotations
- Spring Core Annotations
- Spring MVC Annotations with Examples
- Spring Scheduling Annotations
- Spring - Java-based Container Configuration
- Spring Java Based Configuration Example
Hibernate
- Hibernate 5 hello world
- Hibernate- One to One Unidirectional Mapping Annotation Example
- Hibernate - Batch Processing
- Hibernate - Interceptors
- Hibernate 5 - Create, Read, Update and Delete (CRUD) Operations Example
- Hibernate Transaction Management
- Hibernate One to Many Unidirectional Mapping Example
- Hibernate One to Many Bidirectional Mapping Example
- Hibernate Many to Many Annotation Mapping Example
- Hibernate Primary KeyJoin Column
- Hibernate First Level Cache with Example
- Hibernate XML Configuration Example with Maven + Eclipse + MySQL Database
- Hibernate Java Configuration Example
- JPA 2 with Hibernate 5 Bootstrapping Example
- JPA and Hibernate Cascade Types
- Hibernate/JPA - Primary Key Generation
- Hibernate 5 - Enum Type Mapping Example
- Hibernate Component Mapping
- Hibernate Object States – Transient,Persistent and Detached
- Hibernate 5 - Save an Entity Example
- Hibernate 5 - Persist an Entity Example
- Hibernate 5 - saveOrUpdate() Method Example
- Hibernate 5 - get(), load() and byId() Method Examples
- Hibernate 5 - merge() Example
- Hibernate 5 - Delete or Remove an Entity Example
- Hibernate 5 - load() Method Example
- Hibernate Session Interface Methods
- Hibernate Session.clear() Method Example
- Introduction Of Java strutes to Architecture
- Struts 2 - Architecture
- Struts 2 - Configuration Files
- Struts 2 - Actions
- Struts 2 - Interceptors
- Struts 2 - Results & Result Types
- Struts 2 - Value Stack/OGNL
- Struts 2 - File Uploading
- Struts 2 - Database Access
- Struts 2 - Validations Framework
JAVA FX
- JavaFX Tutorial
- Introduction to JavaFX Pane
- JavaFX Popup
- JavaFX group
- JavaFX Controller
- JavaFX Gradient Color
- JavaFXAnchorPane
- JavaFXTabPane
- JavaFX Scene
- JavaFX Stage
- JavaFXWebView
- JavaFX Timeline
- JavaFX Timer
- JavaFX Image
- JavaFX Background
- JavaFX dialog
- JavaFX Font
- JavaFXTextArea
- JavaFXObservableList
- JavaFX GUI
- JavaFX FXML
- JavaFXEventHandler
- JavaFXGradle
- JavafxScrollpane
- JavaFXAPI
Java Package
A Package can be described as collecting related types (classes, interfaces, counts and annotations) giving access security and namespace administration. Packages are utilized as a part of Java to avert naming clashes, control access, make seeking/placing and utilization of classes, interfaces, identifications and annotations less demanding, and several others.
In java, a package can be classified in two forms, i.e. built-in package and user-defined package.
A few packages available in Java are:
- java.io – all the classes for output and input are available in this package java.
- java.lang – all the major classes are available in this package
Developers can create their packages or package collections of classes/interfaces, and so on. It is a decent practice to collect related classes executed by you so that a software engineer can undoubtedly discover that the interfaces, classes, annotations and counts can be connected. Since the package makes another namespace, there won’t be any name clashes with different packages. Utilizing packages, it is less demanding to give access control and it is likewise simpler to find the related classes.
When you create a package, you ought to pick a name and explain with that name at the highest point of each source record that contains the classes, interfaces, lists, and annotation sorts that you need to incorporate in the package. The package declaration ought to be the first line in the source record. There can be the only declaration in each one source record, and it applies to various sorts in the file. In the event that a declaration of interface is not utilized, then the interfaces, class, annotation and specifications will be put in a package, which will be unnamed.
The package Keyword
Package hierarchy is specified via the package keyword preceding a class definition as shown below. Here, class Demo belongs within package A. Its complete qualified name is thus A.Demo.
package A; class Demo { int h; void j() { ... } }
It follows that a “package B.C” prefix before “class Demo2” definition makes class Demo2 belong to the C package that is in the B package.
package B.C; class Demo2 { int y; void z() { ... } }
Thus far, we have been using class definitions but without any package prefix. Such classes belong to the top-level anonymous package The Java virtual machine maps the package hierarchy onto its directory structure for locating and loading code files. As such, code for A.Demo will be at Demo.class in directory A, or more succinctly, the pathname A/Demo.class. Similarly, B.C.Demo2 will be found at B/C/Demo2.class.
The import keyword
The import keyword provides the complement function of the package facility. While the package keyword places succeeding class definitions in a separate namespace of the said package, the import keyword makes package constituents visible.
Continuing from our earlier Demo2 example, any client code outside of package B.C must either refer to it in its qualified form:
class another { B.C.Demo2 x = new B.C.Demo2(); ... } or, import the complete name space of B.C package import B.C.*; class another { Demo2 x = new Demo2(); ... } or, import the complete name space of B.C package import B.C.*; class another { Demo2 x = new Demo2(); ... } import B.C.Demo2; class another { Demo2 x = new Demo2(); ... } Since the class RST is now used outside its package, RST must be a public class. package B.C; public class Demo2 { int y; void z() { ... } }
Access Package without import keyword
Suppose we use fully qualified name to import any class into your program. In that case, only that particular class of the package will be accessible in our program, other classes in the same package will not be accessible. For this approach, there is no need to use the import statement. But we will have to use the fully qualified name every time we are accessing the class or the interface. This is generally used when two packages have classes with same names. For example: java.util and java.sql packages contain Date class.
Example
//save by X.java package example; public class X{ public void msg(){System.out.println("Hello Java ");} } //save by Y.java package myexample; import example.*; class Y{ public static void main(String args[]){ X obj = new X(); obj.msg(); } }
Output
Hello Java
Import Specific Class
To access only specific class in our program, then import package.classname to declared class of this package.
//save by Demo.java package example; public class Demo { public void msg() { System.out.println("Hello java class"); } } //save by Test.java package myexample; import example.Demo; class Test { public static void main(String args[]) { Demo obj = new Demo(); obj.msg(); } }
Output
Hello java class
Import all classes of package
//save by Example1.java package learnjava; public class Example1{ public void msg() { System.out.println("Hello Example"); } } //save by Example2.java package Java; import learnjava.*; class Example2 { public static void main(String args[]) { Example1 obj = new Example1(); obj.msg(); } }
Output
Hello Example
Apply now for Advanced Java Training Course