Thursday, December 27, 2018

Java Tutorial: Setting up workspace, Fundamental Concept, Letter Cases, Java Naming Convention

References/Links: http://pasted.co/da9190bf

Chapters

Setting up our workspace

Hello everybody and welcome to my tutorial! In this tutorial we will discuss the OOP fundamental concept, naming convention, some basic java syntax and the definition of java package. We will also create some folders and a source file 

First, create a folder to store our codes I'll name it "java codes" you can name your folder anything you want then inside that folder create another folder and I'll name it "basic" this folder will be the package for our codes. You can decide  what your folder name would be but remember this, when naming a java package it should be in lowercase according to java naming convention rules. You might ask, what is lowercase? lowercase is a letter case where all letters in a word are written without any capitalization.

Next, create a text file in the package/folder that we created earlier. I'll name my text file to "Basic_codes" then change the file extension to "java". If you can't change the file extension of your file just go to "Control Panel" if you're using windows then go to "Folder Options" then select the "View" tab and uncheck "Hide extensions for known file types", click ok and close the "Control Panel". Also remember, our source file name should be in camelcase according to java naming convention rules because most of the time, our source file name represents a public class in it. We will declare a public class in our source file when we start coding.

Brief Introduction to Java Package

java package group classes, interfaces, enumerations and annotation types which are somewhat related to each other. You will learn more about classes, interfaces, enumerations and annotation as you progressed don't bother understanding them for now.

Java packages can be categorized in two forms, the built-in package and user-defined package, java built-in package are like Math,swing,io,javax,awt,etc. user-defined package is a package that has been created by us or other individuals that is not part of java built-in packages, we will learn more about packages as we progress further.

Java Application Fundamental Elements

Java is case-sensitive means that the identifier Hello in uppercase is different from hello in lowercase. Identifier are the names of variables, methods, classes, packages and interfaces. You will learn how to use identifier soon once we start coding. The main() method is a mandatory part of most java applications.

The main() is a method where the java application process starts. That's why we need the main() method because our program can't process input and output without main(). You will learn more about methods,main method and java syntax as you progress further, just absorb all the information I discusssed for now.

The name of the source file should exactly match the main class name, main class is a class with the main method.That's why the name of our source file must follow the java naming convention for classes because the class name that we will write in our source file and the source file name must be the same. Whitespace can't be part or used to name packages, classes, variables, interface, etc. use underscore instead.

Java Fundamental Concept

Now let's tackle the OOP fundamental concept, As you can see there are many fundamental concept to be discussed but for now we will focus on the class, objects and instance. Class can be defined as template/blueprint that tells the behavior/state of the object.

Objects have states,fields and behavior, An object is an instance of class. Instance is a definite realization of an object. The making of a realized instance is called instantiation example: objects, instance variables, instance methods.

It's alright if those definitions make you more confuse or they don't make sense, all things that we discussed here will be more clearer and start having sense as you progress further in learning java.

Letter Cases

Now that we know the concept of naming convention let's view the java naming convention rules but before that let's study the letter cases first to make naming convention much easier to understand. We will study four letter cases.

Lowercase is where all letters in a word are written without capitalization(e.g. bundle,stringpackage)

Uppercase is where all the letters in a word are capitalized(e.g.MAX_RPM,MAX_SPEED).

Mixed Case a combination of lowercase and uppercase(e.g. DoberMan,maxVelocity).

Now that we're done on letter cases we can continue to java naming convention rules.

Java Naming Convention Rules

Next is the naming convention rules for java, naming convention is a set of rules for choosing sequence to be used for identifiers which denotes variable, method/function, and other entities in source code and documentation. Naming convention helps our code to be more readable to ourselves and to other programmers.

You won't feel the impact of naming convention when you are just writing a small simple program but when you're writing a big and complex programs then that's a different story, learning to use java naming convention will be a great help in your java programming career. Here are the rules for java naming convention.

1.) When you name a variable, package, class, etc it must be meaningful, somewhat related to its value or somewhat related to the project you're working on.

2.) Package name should be in lowercase I already mentioned this earlier(e.g. package textpackage, package mypackage). 

3.) Class name should be in mixed case with the first letter of each internal word capitalized. Use nouns because class is a representation of something in the real world(e.g. class DoberMan, class SaveFile).

4.) Interface name should be in mixed case same as class names. (e.g. interface Storable, interface Movable), some programmers like to differentiate interfaces by adding "I" at the beginning of  the name of the interface (e.g. interface IStrorable, interface IMovable). 

5.) Method name should be in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Use verbs to describe what the method does(e.g. void calculateValue(), char[] sortCharacters()).

6.) Variable name should be in mixed case same as method names.  (e.g. int initialSpeed, int firstName).

7.) Constants should be in uppercase(e.g. MAX_VALUE, MAX_RPM).

java compiler doesn't enforce naming convention mistakes, it means that the compiler doesn't care if you follow the naming convention rule or not but that doesn't mean that you won't follow the naming convention rule, you may not follow the rules or not but I recommend you to follow the rules because first you and the potential readers of your code will benefit from it, second it will make you look more professional!

No comments:

Post a Comment