
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 Static keyword
Static keyword mainly used for memory management in java. It can apply with variables, blocks, methods, and nested class. It belongs to the class than an instance of the class.
Static keyword can be used in java:
- variable (called as class variable)
- method (called as class method)
- block
- nested class
Java Static variable
When a variable is declared static, then it is called a static variable.
-
It is used to refer to the common property of all objects. Like, school name of students, company name of employees, etc. Name of the school is common for all the students.
- It allocates memory only once in the class area at the time of class loading.
Advantage
It saves memory, so it is memory efficient for the program.
Why we use static keyword
When we store the details of all the students any college, then student id is unique for every student, but the college name is same. When we create a static variable as a college name, then only once memory is allocated a memory space each time for every student.
Syntax to declare a static variable
public static variable name;
Syntax to declare a static method
Public static void methodname() { …. …. }
Syntax to access static method and static variable
className.variableName=20;
className.methodName();
Example of static variable
class Student { int roll_no; String name; static String College_Name="MNIT"; } class StaticDemo { public static void main(String args[]) { Student s1=new Student(); s1.roll_no=54; s1.name="Raj"; System.out.println(s1.roll_no); System.out.println(s1.name); System.out.println(Student.College_Name); Student s2=new Student(); s2.roll_no=90; s2.name="Geeta"; System.out.println(s2.roll_no); System.out.println(s2.name); System.out.println(Student.College_Name); } }
Output
54
Raj
MNIT
90
Geeta
MNIT
Java Static Method
When we apply a static keyword with any method, then it called a static method. It belongs to the class rather than the object of a class. It can be invoked without the need for creating an instance of a class. It accesses static data member and the change the value of it.
Example of static method
class Student{ int rollno; String name; static String college = "BBS"; static void change(){ college = "DU"; } Student(int r, String n){ rollno = r; name = n; } void display(){System.out.println(rollno+" "+name+" "+college);} } public class TestStaticMethod{ public static void main(String args[]){ Student.change();//calling change method Student s1 = new Student(101,"Raj"); Student s2 = new Student(202,"Geeta"); Student s3 = new Student(303,"Rahul"); s1.display(); s2.display(); s3.display(); } }
Output
101 Raj DU
202 Geeta DU
303 Rahul DU
Conditions of static method
- It cannot use non-static data member or cannot call the non-static method directly.
- this and super keyword cannot use in static context.
NOTE:
Java main method is static because to call static method object is not required. When there is a non-static method JVM creates an object first then call main() method.
Java Static Block
It is a set of the statement, which is used to initialize static data member. JVM executes it before main method at the time of class loading.
Syntax
Static { …. //Set of statement …. }
Example
class Block{ static{System.out.println("static block call");} public static void main(String args[]){ System.out.println("Hello main method"); } }
Output
static block call
Hello main method
NOTE:
We cannot execute the program without main() method because in previously the only way was a static block, but it was not possible. So it is not possible to execute a java class without the main method.
Apply now for Advanced Java Training Course