Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 469 Vote(s) - 3.4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A Basic Explanation of a "Hello World" program by a Java beginner.

#1
So, I've been recently working on Java, just started today, but I remember the basics of a hello world program.


So, here's the code, but I'll try my best to explain what I know.


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


So, from what I know, I can tell you that a "class" is where a java program stores information, and you have to have a certain class.
And "System.out.println("Test");" is telling your program to send out a line from the system, ("Test") being the message. Keep in mind that the parenthesis nor the quotation marks show up. So if you want to have quotation marks in the line, it'll have to be (""Test""), which would make "Test", instead of just Test. And if you want parenthesis, it'd have to be ("("Test")") which would print out the whole ("Test").

That was my first post, just explaining how shit goes.

(The reason it says "That was my first post," was because I posted this on another forum. Ask MxRE. :smile: )
^_^
Reply

#2
I really like this explanation, it's very simple and to the point. But I hope you don't mind me going into a little more detail! :smile:

Class
Simply put; A class is a way of applying a structure to code, it stores Data & Methods as class members and allows the programmer to apply strict rules to each member. Classes can be instanced and thus allows them to be used & re-used in an application. This keeps code functional & tidy.

In the case of this class definition:

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

The class has been declared with the name "testclass" and has been defined as a 'Public' class.
This 'Public' Modifier entitles any other classes to access this class and any 'public' class members. Although since this is the main class, the 'public' modifier is not needed.

Class-Members

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

The above code demonstrates a class member being defined, this member has been defined with the following modifiers; public, static & void.
These modifiers are easily explained:
Public - This modifier entitles all classes (Parent, Sub & world) to access this member. (E.g. "testclass.main(MyStringArray);")
Static - This modifier means that only one instance of this class-member will be spawned and shared, regardless of how many instances of the class are created.
Void - This modifier means that that the class-member does not return anything. Had it been "public int main(String args[])" then an integer result would be expected when the member was called.

The main class-member also has a parameter: "String Args[]" - This means that when 'main' is called an Array of the type string is parsed to it, allowing the method main to access this data. In this instance, the Array of Strings parsed to the method are Command Line Parameters. The Array can be accessed like so:

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

A Command-Line Parameter is data that is parsed to the program upon execution. For instance, if you compiled the above code and then executed "java AboveCode.java hello world" the variable "foo" would contain "hello" and the variable "doo" would contain "world".

Since our class is the only class within the application to contain "public static void main(String[] args)", on run-time our class will be instanced first and the the method 'main' will be executed.

Printing out
To help understand the class system, I will explain a little more about what we are doing when we use "System.out.println("");".
When we use System.out.println we are accessing 2 Public Classes and 2 Public Class-Members.

(class) System - This is the first public class we access.
(class) out - This is the first Public Class-Member we access and the Second Public Class (Class-Member of 'System')
(function) println - This is the second Public Class-Member we access, and this is what will print to the console (Class-Member of 'out')

So, when we break it down: 'println' is a class-member of 'out', and 'out is a class-member of 'System'.

The final code:

Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.

When we are parsing data to 'println' that is in raw form (compiled-constant as opposed to variable), we have to put that data in quotation marks. When parsing a variable, this is not necessary.

More about println
println is a something called an 'Overloaded Function', this means that there are many different instances of the function 'println' declared in the class 'out' each accepting different data as Parameters. This is why parsing an Integer or String to 'println' works without any errors.

I hope you don't mind me going into a little more detail, I think it will help people gain a further understanding once they have read your post.

Regards,

Logic.
Reply

#3
I'm glad your learning Java. It's a great language, it's all about dedication, so stay with it.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through