Simple Java Program | Some Facts That Nobody Told You - CodingStartup | Coding Startup

Simple Java Program | Some Facts That Nobody Told You - CodingStartup

In this topic, we will be covering some basic and advance details about Some Facts That Nobody Told You About Simple Java Program.


In This Topic:

In this topic, we will be covering some basic and advance details about Simple Java Program, Some Facts That Nobody Told You. Moreover , we will be covering the vision of looking to a programming language. As a result, you will also increase you knowledge about that java programming language.

Simple Java Program article is also helpful in interview purpose. The points which I am considering that will make you understand that how to understand a programming language. If you are new this site and wanted to learn full java then you must watch this Java Programing Course

Java code explained line by line

To explain this code, I will be considering for-instance of program. Firstly, we will have look on a basic java program structure. Last but not the least, we will we discussing about the some points in that simple java program structure. So lets have for-instance of a code and then we will discussing some points.

class CodingStartUp
{
   public static void main (String args[])
    {
    }
}

Now, in the above code, we have just written a simple code in which we define class, method, data types , array and some keywords which are pre-define in java. Now Lets talk about one by one.

What is Class in java ?

Class is user defined map or blueprint that in which objects are created. In other words, class is place where we can create or set some properties of some group by creating objects. Objects are nothing that have some properties like place ,thing or a name of person.

In the above, code we define class like this

class CodingStartUp

Here class is keyword and after that space, the class name which user has to decide.Before deciding name, there are some condition while selecting the name of program or name of class. Firstly, the first letter should be capital always if there is a single word. Secondly, If there are two or more words you cannot give space but you can use underscore like this Coding_start_up and if you don't want to use underscore then you can follow this standard CodingStartUp. Thirdly,and most importantly, you can not use space in any case while selecting the name.

What is public static void main (String args[]) in java ?

what is public static void main in java

 After considering the first line of code , now we will be considering second line. In second line, we got public static void main (String args[]) what it means, why we use it.

First one is public, it is a pre-defined keyword and access specifier. Access specifier is an term which we use to define access range of class and method. Now the Question arises that How many access specifier are in java? There are total Four access specifier i.e Default, Public, Private and Protected. Now here only, we will be talking about Public access specifier. Public access specifier define by its name only that everyone can you and from everywhere like public transport. Now, we will discuss it why main method is public in java?

why main method is public in java?

We use public access specifier only because main method is an entry point for running a program in JVM. To access the program details which we have written should accessible to JVM so that we use public with main. Now we will talk about Static.

What is Static modifier and use in java code ?

As the Question tells that Static is modifier and pre-define keyword. It is assign for the management of the object memory. In other words, Static is used for object memory management. Now, The question arises that What is the use of it? Static means that on creation of an object. This means that when we create a method in java we have to create its instance (object). While using main method we also have to create object in java for using it. If we create, then ambiguity we be create. So to avoid that we use static modifier that will run code without creating an object.

What is void in java ?

Void is a data type which give no return value. We are using void with main method because this method does not give any return value. Now, That is the reason we use void with main method.

What is String []args in java ?

Now, Here String []args is parameter for the main function. This parameter comes with two section words i.e String and [] args. String is data type and also a pre-define class in java. [] args is an array with the name called args. We can use other names which we want to but we should use [] these brackets because it define array. We can also use these bracket after name declaration like this String codingstartup[]. String []args is used in main method for passing command line args while running a program. Now One question came to our mind that Why we use String data type in main method in java?

Why we use String data type in main method in java?

As we Know that Java is comes from C and C++. In C and C++, We can declare int in main method and it accepts that. The reason behind this is that C and C++ are both directly connected OS. While passing int parameter it will return value to OS. That are only two value i.e exit code and exit status. These values help to tell that program have successfully ended or error terminated. After getting these codes, OS will cleans up the process that is allocated to task. When exit code return 0 that means code has been successfully run without ant error. On another hand, non zero status tells about the error or problem.

In Java, we know that JVM runs the code in main thread and no direct interaction between OS and our code. Moreover, There is no direct link in resource and memory allocation between program and OS. JVM is directly connected to the hardware. Then JVM complete the work of main method by sending status of exit code and exit status with the help of one lib i.e java.lang.Runtime.exit. Moreover, if you want full explanation you can visit this site Why we use String data type in main method in java?

Conclusion

On the ending note, I would like to say that java language is a puzzle. More you you solving it , more you getting about it. This from my side. I hope you like to read my article and you get alot of knowledge from this article.

Code Startup

Author & Editor

0 Comments:

Post a Comment