Java Naming Conventions and First Program

First code

Let us begin to write the most basic code to exist in any coding language; that is the “ Hello World” program.

From here we begin to understand the coding structure of java language. for that, Let us have a look here.

Code in Java

Run

public class Main
{
	public static void main(String[] args) {
		System.out.println("Hello World");
	}
}

Output

Hello World

Remember guys, Java is a case sensitive language.

Here we are writing a program to print Hello World on the output screen.

  • The class is named as Main.  The outer class can only be either public or default. We make a class public so that it is accessible from outside ( by a JVM ).
  • If there is a dot ( . ) after a class name, it indicates that We are accessing one of its static members.

Here if we look at the statement  System.out.println(“Hello world”);

  • System is a class.
  • System.out indicates that we are accessing ‘ out ‘ which is a static reference variable/ pointer which represents an object.
  • ‘ println ‘ is a member function of the object ‘ out ‘.[ ‘ println ‘ prints the output in a new line automatically while ‘ print ‘ prints the output in the same line. ]

Now if we look at the statement public static void main(String[] args)

  • Here public is an access specifier that allows the main method to be accessible everywhere.
  • Static helps the main method to get loaded without getting called by any instance/object.
  • Void clarifies that the main method will not return any value.
  • Main is the name of the method.
  • String[] args: Here we are defining a String array to pass arguments at command line. args is the variable name of the String array. It can be changed to anything such as String [] a.

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Class and Interfaces:

  • Class names are nouns, in which the first letter of each internal word is capital. This type of representation is also known as the camel case.
  • The use of whole words is preferred rather than abbreviations and acronyms ( except in the case where the abbreviation is more widely used than the actual word ).
  • The interface names should also be capitalized just like done in classes. 

Packages:

  • The prefix of a unique package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names, currently com, edu, gov, mil, net, org.
  • If the name contains multiple words, it should be separated by dots (.) such as java.util, java.lang.
  • Subsequent components of the package name vary according to an organization’s own internal naming conventions.

Variables:

  • Variables: Variable names should be short yet meaningful.
  • It starts with a lowercase letter. The usage of One- character variable should be avoided. Although permitted, initializing variable names with either underscore(‘_’) or dollar sign ‘$’ characters should not be done.

Method:

  • Methods should be verbs, in mixed case with the first letter lowercase, and with the first letter of each internal word capitalized.

 

Constant Variables:

  • The constant variables should all be in upper case with the words separated with the help of an underscore ‘ _ ‘.
  • It may contain digits but not as the first letter.

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription