Java: Java Programming For Beginners a simple Start To Java Programming (Written By a software Engineer)


Download 0.82 Mb.
Pdf ko'rish
bet3/95
Sana09.01.2022
Hajmi0.82 Mb.
#261112
1   2   3   4   5   6   7   8   9   ...   95
Bog'liq
Java Programming For Beginners - A Simple Start to Java Programming ( PDFDrive )

First Java Program:
In  order  to  start  with  basic  basic  Java  programming,  let  us  look  at  the  standard  Hello
World program.
public class MyFirstJavaProgram {
public static void main(String []args) {
System.out.println(“Say Hello World To The World!”);
}
}
As you can see, the program uses a single line of code in the main() function, which prints


the  statement  ‘Hello  World!’.  However,  before  that  can  be  done,  let  us  look  at  the  steps
that you must follow in your quest to execute the file.
Open any text editor and paste this code in that file.
Save  the  file  with  a  .java  extension.  For  example,  you  can  save  the  file  as
Sample.java.
The  next  step  is  to  to  open  the  command  prompt  of  the  system  and  relocate  its
reference to the directory in which the file is saved. For instance, if you have saved
the file in C:\, then you must take the prompt to the same directory.
In order to compile the code, you must type the following:
javac Sample.java
If there are no errors, you will automatically be taken to the next line. You can now
execute the code using the following command:
java Sample.java
You should be able to see the following output on the screen.
Say Hello World To The World!
Basic Syntax
About Java programs, it is paramount to remember the accompanying points.
Class Names –
For all class names, the first letter ought to be in Upper Case.
On  the  off  chance  that  few  words  are  utilized  to  structure  a  name  of  the  class,
every  internal  word’s  first  letter  ought  to  be  in  Upper  Case.  For  example,  a
standard class name is as follows:
class Sampleclass
Case Sensitivity - Java is case sensitive, which implies that the identifier Hi and hi
would have distinctive importance in Java.
Method Names - All system names ought to begin with a Lower Case letter. In the
event that few words are utilized to structure the name of the method, then every
internal  word’s  first  letter  ought  to  be  in  Upper  Case.  An  example  of  this
convention is follows:
public void mysamplemethod ()


Filename –
The  name  of  the  system  record  ought  to  precisely  match  the  class  name.  At  the
point  when  you  are  saving  the  file,  you  ought  to  save  it  utilizing  the  class  name.
Remember  Java  is  case  touchy  and  affix  “.java”  to  the  end  of  the  name.  If  the
document  name  and  the  class  name  don’t  match  your  system  won’t  assemble.
Consider the example of a class name Sample. In this case, you must name the file
as sample.java.
public static void main(string args[])
Java system handling begins from the main() function, which is a required piece of
each Java program.

Download 0.82 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   ...   95




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling