DEV Community

Janardhan Pulivarthi
Janardhan Pulivarthi

Posted on • Edited on

Day 8 of 100 - Java: Use cases

Thoughts

The Java is there from a number of years. A lot of articles, docs, solutions are available. I find it difficult to follow what is it that I should learn about.

To my knowledge (hands-on), Java is used for

  1. coding as high-level language for building systems,
  2. compilers (examples, https://github.com/apache/systemds),
  3. Java API Clients (https://cloud.google.com/java/docs/reference),
  4. Building websites (https://github.com/JetBrains/kotlin-web-site)

Java as a API client is powerful.

Space Rocket loading project

https://github.com/j143/java-basic-space-challenge

phase-1.txt

building tools=2000 building tools=2000 building tools=2000 building tools=5000 building tools=5000 building tools=2000 building tools=1000 building tools=5000 building tools=6000 shelter equipment=5000 construction equipment=5000 plants=1000 steel=8000 books=1000 water=5000 
Enter fullscreen mode Exit fullscreen mode

phase-2.txt

habitat=3000 colony=5000 food=5000 habitat=3000 colony=5000 food=3000 colony=5000 food=3000 
Enter fullscreen mode Exit fullscreen mode

static keyword

Static fields

// Person.java public class Person { public static int instanceCount; public int localCount; public Person() { instanceCount++; localCount++; } } 
Enter fullscreen mode Exit fullscreen mode
//Main.java public class Main { public static void main(String [] args) { for(int i=0; i < 4; i++) { Person person = new Person(); System.out.println("(" + person.localCount + ", " + + person.instanceCount + ")"); } } } 
Enter fullscreen mode Exit fullscreen mode

output will be: (1, 4)

Static Method

Like static fields, static methods belong to class not objects.

Points:

  1. This is a method independent of the object
  2. A static method takes in input arguments and returns result based on input only nothing else
  3. The static method does not need any field values
  4. But, a static method can still access static fields since they belong the Class
public class Compute { public static int add(int x, int y) { return x + y; } public static int subtract(int x, int y) { return x - y; } } 
Enter fullscreen mode Exit fullscreen mode

add and subtract methods can be called without creating the object.

Compute.add(2,3); 
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
sadiejay profile image
Sadie

Wishing you success on your journey to learn Java!

Collapse
 
j143 profile image
Janardhan Pulivarthi

Thanks. :)