💻Step 8: Java Modifiers Explained – Easy Guide with Code (5th Hour)

Learn with our youtube video

Modifiers-

💡Definition-

These are the keywords which  modifies properties of classes and fields.

💡Types of modifiers-

1- Access modifiers
2-Non-access modifiers

Quick overview –

Modifier TypeModifierDescription
Access ModifierspublicAllows the member to be accessed from anywhere.
protectedAllows the member to be accessed within the package and by subclasses.
defaultAllows the member to be accessed within the package. This is the default accessibility if no modifier is specified.
privateAllows the member to be accessed only within the class.
Non-Access ModifiersabstractSpecifies that the member does not have an implementation and must be implemented by a subclass.
finalPrevents the member from being overridden or modified.
staticMakes the member a class member, rather than an instance member.
synchronizedEnsures that only one thread can access the member at a time.
transientIndicates that the member should not be serialized.
volatileIndicates that the member can be modified by multiple threads and its value should be refreshed from memory when accessed.
nativeIndicates that the method is implemented in native code using the Java Native Interface (JNI).
strictfpEnsures that the floating-point calculations performed by the method are compliant with the IEEE 754 standard.

💡1-Access modifier-

Modifies accessibility of   classes and fields.

-Controls visibility.

(i)Private    – only within class

(ii)Default   – only within package.

(iii)Protected  – within package and outside the package using inheritance

(iv)Public        – everywhere

Note- classes can’t be private and protected.
Note- Local variables can’t have any access modifier

code samples are here

1- Program to demonstrate access modifiers on variables

i- Program for class ExUsingVar


package AccessModifiers8;
public class ExUsingVar {
public int a=10;
private int b=20;
protected int c=30;
int d=40;

public static void main(String[] args) {
ExUsingVar e1 =new ExUsingVar();
System.out.println(e1.a);
System.out.println(e1.b);
System.out.println(e1.c);
System.out.println(e1.d);
}
}

ii-Program for class ExUsingVar1


package AccessModifiers8;
public class ExUsingVar1 {

public static void main(String[] args) {
ExUsingVar e1 =new ExUsingVar();
System.out.println(e1.a);
System.out.println(e1.b);
System.out.println(e1.c);
System.out.println(e1.d);
}
}

iii-Program to show ExUsingVar3


package AccessModifiers8_1;
import AccessModifiers8.ExUsingVar;

public class ExUsingVar3 {

public static void main(String[] args) {
ExUsingVar e1 =new ExUsingVar();
System.out.println(e1.a);
 System.out.println(e1.b);
 System.out.println(e1.c);
 System.out.println(e1.d);
}

}

💡2-Non Access Modifiers-  (Final,Static,abstract,Transient,Synchronized,Volatile, native, strict)

💡1-Final-

used to restrict the user.

💡(a)final variable  –

can’t change the value

💡(b) final method

can’t override

💡(c) final class

can’t inherit

💡2-Static-

-static belongs to class rather than objects.
💡(a) static variable
-gets memory only once at the time of class loading.
-used to refer the common property of all objects

💡(b) static method
– can be invoked without an instance/object
-can access static variable

💡(c) static nested Class
-can access static data members of outer class

-object is created in scope of outer class

💡(d) static block
– executes even before main method
-used to initialize static data members

💡(E) STATIC method in interface-
– Static methods in interface can have body
– Can be invoked on Interface name only
– Can’t be override by inheritance

💡3- Abstract –

-Used in abstraction(oops concept)
-can be applied on-
a- Abstract class
b- Abstract method

💡4-Transient-

– prevents serialization of value.(Io package concept)
-only for variable

💡5-Synchronized-(multi-threading concept)

-prevents sharing by more than one threads at a time
– can be
a- synchronized method
b- synchronized block

💡6-Volatile-(multi-threading concept)

– Allows modification at run-time.
– only for variable


💡7- Native- JNI (Java Native Interface)


– Only for native/foreign methods
– Methods which are implemented in c/c++ are called as native/foreign methods

💡8- Strict – (strictfp as keyword)

– Ensures that result is same for every platform while performing floating point calculations

Interview Questions —

  • What is difference between access and non-access modifiers?
  • What is default access modifiers, how to use it on class?
  • What is difference static and final modifiers?

19 comments

  1. Excellent post! The information you shared is practical and easy to apply in daily life. I appreciate the positive tone and the emphasis on healthy habits instead of extreme methods. Looking forward to reading more of your content.

  2. This post offers a refreshing perspective on weight loss. I like that you didn’t promote extreme diets or unrealistic workouts. Instead, you focused on habits that people can actually stick to long term. This kind of advice is especially helpful for beginners who want to make lasting changes.

  3. I found this article very motivating. The reminder that weight loss is a journey, not a race, really stood out to me. It’s easy to get discouraged when results take time, but content like this helps people stay focused on the bigger picture. Thanks for sharing such positive and realistic advice.

  4. What i do not understood is in reality how you’re not really much more neatly-liked than you may be now.
    You are very intelligent. You realize thus considerably when it comes to this topic, produced me
    personally imagine it from a lot of various angles.
    Its like men and women don’t seem to be involved unless it’s one
    thing to accomplish with Girl gaga! Your own stuffs
    nice. Always take care of it up!

  5. I think what you posted was actually very logical.

    However, what about this? suppose you were to create a killer post title?

    I ain’t saying your information is not good., but what
    if you added something to possibly get people’s attention? I mean 💻Step 8: Java Modifiers Explained – Easy Guide with Code (5th Hour) – Java Programmatic Universe is
    kinda vanilla. You should look at Yahoo’s front page and watch how they create post headlines to get viewers interested.
    You might try adding a video or a pic or two to get readers excited
    about what you’ve written. Just my opinion, it might bring your posts a little bit more interesting.

  6. I enjoyed reading this post because it focuses on long-term health, not just losing weight quickly. The emphasis on balance, patience, and healthy choices makes this advice much more valuable than typical weight loss articles.

  7. Really useful article. The tips you shared about staying consistent and building routines are very practical. Many people give up because they expect fast results, but your content does a great job of setting realistic expectations.

  8. This was a very informative and easy-to-read post. I liked how you explained that everyone’s weight loss journey is different and that there’s no one-size-fits-all solution. That’s an important message that many people need to hear.

  9. Great article! I appreciate how you addressed common weight loss mistakes and explained how to avoid them. Many people struggle because of misinformation, and posts like this help clear things up. The tone is encouraging and informative, which makes it enjoyable to read.

  10. This is a very well-structured post with practical tips anyone can follow. I especially liked the advice about making small changes instead of trying to overhaul everything at once. That approach feels much more sustainable and realistic for long-term success.

  11. This was a really helpful article, especially the part about focusing on sustainable habits instead of quick fixes. A lot of people underestimate how small daily changes can make a big difference over time. I also liked the emphasis on consistency rather than perfection, which is something many beginners struggle with. Thanks for sharing practical advice that feels realistic and achievable.

  12. This post offers a refreshing perspective on weight loss. I like that you didn’t promote extreme diets or unrealistic workouts. Instead, you focused on habits that people can actually stick to long term. This kind of advice is especially helpful for beginners who want to make lasting changes.

  13. Great post! I appreciate how clearly you explained the importance of creating a calorie deficit without going to extremes. Many weight loss articles promote unrealistic expectations, but this one keeps things balanced and healthy. The tips about meal planning and staying active are especially useful for people with busy schedules. Keep up the great work.

  14. This is a very well-structured post with practical tips anyone can follow. I especially liked the advice about making small changes instead of trying to overhaul everything at once. That approach feels much more sustainable and realistic for long-term success.

  15. I enjoyed reading this post because it focuses on long-term health, not just losing weight quickly. The emphasis on balance, patience, and healthy choices makes this advice much more valuable than typical weight loss articles.

Leave a Reply

Your email address will not be published. Required fields are marked *