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...

5. Displaying message in Java | Java Programming | #technicalmagic9 @techcomputergyaan | String in Java | Numbers in Java

 Displaying Message in Java

We are going to discuss

Strings

Group of characters (text)
Strings in Java should be put in double quotes "
eg.
"hello"
"hi"
"123"
""
"!@#56456**"

All the above characters in double quotes are string.

println() and print() methods

Calling println()

It will display the parameter on the console window
System.out.println("hello");
System.out.println("hi");
System.out.println("123");
System.out.println("");
System.out.println("!@#56456**");

Output

hello
hi
123

!@#56456**

calling print()

It will also display the output on the console window
System.out.print("hello");
System.out.print("hi");
System.out.print("123");
System.out.print("");
System.out.print("!@#56456**");

Output

hellohi123!@#56456**
So, here we can see the output. All the strings are in same line. Means there is no line break. 

System class

What is System.out

  • out is an object of the PrintStream class
  • out has the print() and println() methods
    • we use "." to access print()/println() of out
  • out refers to the standard output device.(Screen)
  • System is a class.
  • out is inside System.
    • use "." to access out of System.
  • So the statement is System.out.println();

Displaying Numbers in Java

Numbers in Java are just like mathematics
eg.
0
10
-9
129
-0.9
10.23
There is no need of " in printing numbers.
System.out.println(10);
System.out.println(-9);

Output

10
-9

Comments