Lest's Start JAVA Programming
How to create a JAVA program.
- create a file with extension .java.
- ex:- Example.java
- open that file in a text editor and type source code inside it.
class Example { public static void main(String[] args) { System.out.println("Hello"); } }
- then save the file.
- open a terminal and navigate to the location that file saved in.
- then to compile source code need to type this line in terminal and press enter.
- javac Example.java
- press enter.
- then to run program type this line in terminal and press enter.
- java Example
- press enter.
- then you will see "Hello" in terminal as output.
Outline of a JAVA program
When we run a Java program it runs from top to bottom.
Let's say we have following code. after you run it you can see the out put in order of how card have.
Let's say we have following code. after you run it you can see the out put in order of how card have.
class Example { public static void main(String[] args) { System.out.println("1");
System.out.println("2");System.out.println("3");
System.out.println("4"); } }
Output of this example
1
2
3
4
Different between println and print
System.out.println("a"); - with this code, text print after this in the terminal will print in a new line.
System.out.print("a"); - with this code, text print after this in terminal will print in same line. with this text.
Basic computer data/ computer literals
- Integers - 100, 200, 500, .....
- Floating Points - 0.32, 1.5, 5.67
- Characters - "A", 'B'
- String - "Example", 'Hello'
- logical values - true, false
Not only this things there are some special characters, that use with a word.
- "\b" - backspace
- "\n" - new line
- "\t" - tab
Examples,
class Example { public static void main(String[] args) { System.out.print("A\nB");
System.out.print("CD");System.out.println("E\n");
System.out.print("F"); } }
A
BCD
E
F
class Example { public static void main(String[] args) { System.out.print("A");
System.out.println("B");System.out.print("C");
System.out.println("D");
System.out.print("E");.System.out.print("F");} }
AB
CD
EF
Comments
Post a Comment