CodeGym /Java Course /Java Syntax /Introducing the program

Introducing the program

Java Syntax
Level 1 , Lesson 1
Available

"Hello, my young friend. I hope you haven't forgotten that I'm a 16th generation bureaucrat. If I hadn't systematized all my knowledge, I would never have achieved what I have. I'm full of useful information. I'm going to help you with some tasks. For starters, let me tell you about a typical Java program."

"I'm listening."

"Fact number one. A Java program consists of classes. Each class is stored in an individual file, whose name coincides with the class name. The file extension is java."

"So, a program consists of a series of files with the 'java' file extension, and each file contains code for just one class, right?"

"Absolutely correct, Amigo. If a file is called MyCat.java, it contains the MyCat class."

"Fact number two. When we have many class files, we group them into folders and subfolders. Additionally, classes are grouped into packages and sub-packages. The names of packages and sub-packages must be indicated in class code, and they must be identical to the folder and subfolder names on the drive."

"Thus, on the one hand, we have files stored in folders, and on the other – classes stored in packages. A class name must also coincide with the name of the file describing the class. The package name coincides with the name of the folder where the class is stored."

"Can you give me any more details?"

"The names of the nested packages are divided by periods, almost like URLs."

"In other words, suppose you have a class named Cat, stored in an animals.pets package. That means:

The hard drive has some folder (we'll call it src) where all the project files are stored.

It contains a folder named animals, which in turn contains a pets subfolder.

The pets folder contains a Cat.java file, which in turn contains code for the Cat class."

"I'm not quite sure I understand."

"Look. The structure of the classes and packages mirrors the structure of folders and files on the drive. If we have a file named House.java, stored in the src/com/houses folder, then there is a class named House, stored in the com.houses package."

"Got it."

"You seem to be picking this up rather quickly. Look at the screen. This is code for a small class. I've labeled all the key parts:"

        PACKAGE NAME
package com.futujava.lesson2;
import java.io.IOException;
/**
 * User: General
 * Date: 12/21/12
 * Time: 11:59
 */
             CLASS NAME
public class Task1
{
                                                              
   private static String TEXT = "Kiss my metal rear actuator";⎥ CLASS VARIABLE
                                                              
                                                                
   public static void main(String[] args) throws IOException    
   {                                                            
      SCREEN OUTPUT                    SINGLE-LINE COMMENT      
      System.out.println(TEXT); //Display a single string  
        MULTILINE COMMENT                                       
      /*                                                        
        This is a multiline comment.                            
        The code below will display three identical strings.    ⎥ main() METHOD
       */                                                       
      VARIABLE DECLARATION                                      
      String s = "Ho-ho-ho!";                                   
      METHOD CALL                                               
      printTextMoreTimes(s, 3);                                 
   }                                                            
                                                                
                                          METHOD PARAMETERS   
   public static void printTextMoreTimes(String s, int count) ⎥ METHOD SIGNATURE
                                                            
                                                                
   {                                                            
      LOOP                                                      
      for (int i = 0; i < count; i++)                           
      LOOP BODY                                                 ⎥ METHOD BODY/CODE
      {                                                         
         System.out.println(s);                                 
      }                                                         
   }                                                            

}

"Heh, it's as clear as can be after just one explanation."

"Good! That's all we need. Just try to understand at least something. A complete understanding will come with time. Now, I'm going to catch some Z's. Somebody else will continue your training."

Comments (325)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Mojib Mayahi Level 1, United States of America
18 February 2024
Got it
Tyler Mills Level 1, Ukraine
20 May 2022
this was never explained to me properly in my java class
Captain Anton. Pirate of Asteroids Level 2, New Nebula Galactic City, India
29 December 2021
Perfect explanation
AJ Lopez Level 1, La Paz
19 December 2021
got it
Colton Martindale Level 2, Bullard, United States
10 September 2021
Got it
Anonymous #10817526 Level 1, Пасадена, United States
9 September 2021
Got it
NaeRae Level 11, United Kingdom
10 August 2021
What happens when we don't give any value to the variables? The i and count are empty or did I miss something?
Riya Iqbal Level 2, Coimbatore , India
15 September 2021
see in the printTextMoreTime method.they give the value i=0 and calling method they sends 3 as value of count
Ms. Anonymous Level 2
2 August 2021
A bit confused, but I will know better later
Indranil Chakraborty Level 3, United Kingdom
2 August 2021
So this is where it really starts =D
VISHWA K ANGOLKAR Level 2, India
21 July 2021
got it perfect :)