📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
🎓 Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
Key points about long Java Keyword
- The long keyword is used to declare a variable as a long primitive type.
- The long primitive type is a signed 64-bit type and is useful for those occasions where an int type is not large enough to hold the desired value.
- The Long class is a wrapper class for the long primitive type. It defines MIN_VALUE and MAX_VALUE constants representing the range of values for this type.
long Java Keyword Example
// Compute distance light travels using long variables.
class Light {
public static void main(String args[]) {
int lightspeed;
long days;
long seconds;
long distance;
// approximate speed of light in miles per second
lightspeed = 186000;
days = 1000; // specify number of days here
seconds = days * 24 * 60 * 60; // convert to seconds
distance = lightspeed * seconds; // compute distance
System.out.print("In " + days);
System.out.print(" days light will travel about ");
System.out.println(distance + " miles.");
}
}
In 1000 days light will travel about 16070400000000 miles.
Comments
Post a Comment
Leave Comment