Java Keywords and Concepts To Know

And Concepts!

Hello friends, hope you are all doing great as the holidays approaches. Today, I want to talk about some keywords and concepts that are important to understand as a beginner Java developer. In the Java programming language, it contains 51 keywords that have a predefined meaning. We are not allowed to change their meanings, so developers are not allowed to use these keywords as names for methods, classes, variables, or as any other identifiers. Concepts in Java also help the flow of how code blocks and programs should run. The 13 keywords and concepts I will be mentioning are:

  • Package: Is a namespace that organizes a set of related classes and interfaces.
  • Import: It declares a Java class to use in the code below the import statement.
  • Class: Is the blueprint from which individual objects are created.
  • Public: Declares a member’s access as public. Public members are visible to all other classes. This means that any other class can access a public field or method. Further, other classes can modify public fields unless the field is declared as final.
  • Void: Used at method declaration and definition to specify that the method does not return any type, the method returns void.
  • CamelCase: A way to format identifiers that contain more than one word, an example of a CamelCase is…“iPhone”.
  • Colon: It shows the compiler where an instruction ends and where the next instruction begins. It allows the java program to be written in one line or multiple lines, by letting the compiler know where to end the instructions.
  • Variable: Is a piece of memory that can contain a data value.
  • Variable Declaration: When you create a variable, you must declare what kind of data type it will be. It can be an integer, character, boolean, float, long, strings, and etc.
  • Dot(.): Indicates as Object accessor. An object that was made from this class will be able to access a method by using the dot notation.
  • Object: An instance of a class that have states and behaviors.
  • Method: is a block of code which only runs when it is called.
  • Constructor: is a special method that is used to initialize objects. It is called when an object of a class is created.
Using all the keywords mentioned and most of the concepts for good coding practices.

When you first create a project on IntelliJ, you’re already utilizing a package, a public class, and a public static void main method. In the example above, I am asking for the user’s name and age in one method. Usually a method should not be longer than 5 lines of code, but for teaching purposes I am putting them all in the main method. If you take a look at all the line of codes, you can see a semicolon at the end of every line. This is an instruction that tells the compiler where the code should end and start. If you write code in JavaScript and Ruby, you are not forced to end the code with a semicolon but it is highly recommended that you should for good practice. On line 10, I am declaring a variable and giving it a data type of int (integer). The variable age is taking in an integer input from the user and that input is being allowed from line 8. The Scanner is one of Java’s classes that is being imported for our purpose. If you also take a look on line 9 and 10, we’re using dot notations to access a method in the Scanner class. In IntelliJ, you can easily access any class method by typing the “.” and will show all the methods that are available for that object.

We are creating puppies for this class and we’re going to have a name and age. Then we will be able to access their name age with the class method of setAge and getAge.

I love puppies which is why we are going to create some puppies for this blog. From lines 12 through 19 are class methods that we will be able to use on our puppy instance. We will be able to set an age for our puppy and have the compiler tell us the age of our puppy by returning the global variable of puppyAge (setting it by using the setAge method). On lines 8 through 10 is an example of a constructor, when we create our puppy the compiler will always read us the name of our newly created object from our class. Think of constructors as the materials for a blueprint. Sometimes methods doesn’t require a return type which is why on line 12, when we set the age of our puppy we have void instead of int. If the method doesn’t require a return type it is best to set it as void. If we compare it to the method getAge, we are returning a value of an integer and we have to set that method as int to be consistent.

We want to be consistent with placing a semicolon at the end of every line of code to tell our compiler where our code starts and ends. Then we have our packages which helps organize our files and we could also import them into a file so that we can have access to some of their methods and properties. Next we have our classes which are like blueprints to make an object and constructors that are materials to create our object, just like how we made puppies. When we were able to create a puppy, we accessed our class methods by using dot notations and we could use dot notations on other imported classes such as Scanner. And within all of our classes we had methods and variables that required a return type. One thing to note variables cannot be void, but methods can (look at the setAge method). Finally for naming convention we used camel casing to help us indicate variables names, methods names, and class names. You can use snack casing too which is this_is_snake_casing. Whichever works better for you! With all this I hope you follow these concepts and memorize these keywords to help further increase your Java skills! Be consistent with your methods and variables and have fun.

Interested in the structure of codes and chasing the Dopamine rush as I start to understand their structures.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store