Learn java basic program for beginners

We can treat Java programs as a set of objects that can exchange each other using methods. Here are some basic definitions of class, object, method, and variable in Java for beginners learn java basic program:
  • Objects - Objects have states and behaviors. For example: A dog has the state of skin color, name, food as well as behaviors such as barking, eating, wagging tail.
  • Class- A class can be defined as a design template, which can describe the state or behavior of an object that it supports.
  • Method - A simple method is a behavior. A class can consist of many methods. In each method there are logical operations, data is processed and all actions are executed.
  • Variables - Each object has a unique set of variables. Each state of the object is initialized by values and assigned to variables.

Basic syntax in java program for beginners learning:

     In Java basic programs for beginners, when naming any component, you need to follow their naming convention. Naming conventions in Java are the rules you need to follow when deciding what to name your identifier, such as naming classes, packages, variables, methods, and so on. Forcing you to follow. So it is called conventional, not rules.
  • Java is case sensitive, which means that JACK and jack have different meanings in Java.
  • Class Name - All Class names in Java should capitalize the first letter and be a noun. Without the capitalization, the IDE will warn you (of course Java still accepts if you deliberately write the first letter). Ex: class System.
  • Interface Name - Should start with capitalization and be an adjective, eg Runnable, ActionListener ...
  • Method name - All method names should begin with lowercase and be a verb. Ex: public void actionPerformed()
  • Variable name - Should start with lower case, eg firstName, orderNumber ...
  • package name - should start with lowercase, eg java, lang, sql, util ...
  • Constant name - Should start with upper case, eg RED, YELLOW, MAX_PRIORITY ...
  • Program file name - File name should be identical to the class name.When you save the file, you should use the class name and add the `.java` suffix.For example, with the class name `MyfirstJavaProgram`, you should save the file as` MyFirstJavaProgram.java`.
  • public static void main (String args []) - The Java program starts with the main () method for all J2SE programs.

CamelCase in Java:

     Java follows the camelcase syntax for naming classes, interfaces, methods, and variables. If the name is a combination of two words, the second word will always begin with uppercase, for example: actionPerformed (), firstName, ActionEvent, ...

Identifier in java:


    All Java components require a name. The name used for the class, variable, and method is called the identifier. In Java, there are some important points to keep in mind with the identifier:
  • All idenfier should start with a letter (A to Z or a to z), character ($) or underscore (_).
  • After the first character can be any character.
  • Key words in Java can not be used as an identifier.
  • Identifiers are case-sensitive.
  • Eligible: age, $ name, value, __1_value
  • Invalid case: 123abc, -fee

Modifier in java:

   Like other languages, you can modify the class, method, .., by using the Modifier. In Java, there are two types of modifiers:
  • Access Modifier: Include default, public, protected, private.
  • Non-access Modifier: Include final, abstract, strictfp

Variables in java:

  • Local variable
  • Variable of the class (static variable)
  • Variable object (not static variable)

Array in java:

    Arrays are objects that store multiple variables with the same data type. However, an array itself is also an object in memory. We will also learn the initialization, declaring this object in the upcoming chapters.

Java enum example:

   Enum introduced by Java 5.0 Enums limits the number of variables by predefining them. Variables in the list are listed as enums.
With the use of enum will be able to limit the number of errors in the code.
For example, let's say an application for a fruit juice shop, which can limit types of sizes to include small, medium and large sizes. This can help make it impossible for everyone else to add other sizes.
Ex:
java-enum-example
The output:
Note: Enums can be declared as either own itself or inside a class. Methods, variables, constructors can also be defined inside Enums.

Keywords in java:

The following list prints keywords that are reserved in Java. These reserved keywords are not used as a variable name or identifier name.
key-word-in-java

Comment in java:

       Java supports commenting on a command line or multiple lines similar to C and C ++. All characters in comment lines are ignored by the Java compiler.
comment-in-java

Blank line:

     One line contains only white space, possibly with a comment, known as a blank line, and Java completely ignores it.

Multiple inheritance in Java:

      In Java, classes can be inferred from other classes. Basically, if you need to create a new Class and here already exists a Class that has some of the code you need, then it is possible to derive a new class from the existing code.
This concept gives you the ability to reuse existing classes and methods of an existing class without rewriting the code in the new class. In this situation, the existing class is called a super class and the class is inferred from being called a subclass.

Interface in java:

       In the Java language, an interface can be defined as a contract between objects on how to communicate with each other. Interfaces play an essential role when it comes to the concept of inheritance.
An interface defines methods, the subclasses should use. But the implementation of the methods is entirely subclass.

Difference between print and println:

     Java supports two commands, println and print to print information on a standard screen. However, between these two commands there is a slight difference in pointers in the two commands. While the print command holds the cursor position on the same line, the println command moves the cursor to the next line (equivalent to the newline).You follow the simple example below to distinguish these two commands:
difference-between-print-and-println-in-java
The output:
difference-between-print-and-println-in-java-1

Comments