Skip to main content

Featured

7. Executing our First Java Program in BlueJ | Java Programming | Compiling and Creating java Program @techcomputergyaan Technical Magic

 Executing our First Java Program in BlueJ  We are going to discuss Comments in Java Comments: Text ignored by the compiler To write some notes for future reference To find some errors we can make some statement as comment and can compile the program and in this way we can find errors in the program. Way of writing Comments // for single line comment /* for multiple line comments */ Create our First Project in BlueJ Step 1: To open BlueJ Step 2: Create new project Step 3: Create New Class in Pascal case, I have created HelloJava Step 4: Double click on HelloJava class. A new window in BlueJ with some codes will open. You will see some comments and some codes written over here. So, I am going to delete everything and I will write only codes which is important for our first program. So, here in the above screenshot you can see I have deleted everything except our HelloJava class. Now we will write code for our main() method. Now in the main method we can write our statement. Wri...

4. Anatomy of Java program | Java Programming @techcomputergyaan #technicalmagic | Java language

 Java Program Anatomy

We are discussing

How a simple Java program look like

Classes

Class: A blueprint to create objects. It has the properties for an object.
Object: An instance of a class. We create objects with the help of a class.

Class Structure

class ClassName {
    code for the class
}
Here 'class' is the keyword (syntax).

Methods

Group of instructions to do a specific task.
  • It can be for the product of two numbers.
  • It can be for printing some message.
  • It can be for getting some information from the user.
We have a special method called 'main' method.

Method structure

return_type methodName(parameters) {
    code for the method
}
Parameters: There are the data given to the method which are used inside the method.
Note: Every method is written inside a class.
We can say class is the container of the method. So, no method can be without class.

Calling a method / Using a method

mehodName(give parameters);
Note: main() method is automatically called when we run our java program.
It is the first method that is called. there is no need to call this method.
It is the starting point of execution of the program. We can't write a program without a main method.
So, we have to write our program inside the main method. 

Naming Conventions

The way of writing names in our java program.

Pascal case

ClassNameAreWritten (here first letter of each word is capital)

Camel Case

methodNameAreWritten (here first letter of first word is small and others are in capital)

Java Program Structure

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

Every Java program has at least one class.
Method exists inside the class.
main() is the starting point of execution of the program. 

Packages

Package is container for classes.
A package in Java is used to group related classes. Think of it as a folder in a file directory. We use packages to avoid name conflicts, and to write a better maintainable code.

Comments