1. Compiling the First Java Program
•Printing Hello World On Screen
•Understanding the keywords
•Understanding the Syntax of program
•How to compile a java program
•How to execute a java Program
•What is camel case syntax.
4/10/2019 1Jamsher Bhanbhro(F16CS11)
2. Hello World!
• public class HelloWorld{
public static void main (String args[]){
System.out.println(“Hello World!”);
}
}
4/10/2019 Jamsher Bhanbhro(F16CS11) 2
3. Understanding the syntax
• Here public is the access modifier which tells
the accesses of our program/class i.e where our
class can be called and where it can’t.
• Public means we can call our class throughout
the program it can run any where it is public.
• Further we will discuss in the access modifier
lecture.
4/10/2019 Jamsher Bhanbhro(F16CS11) 3
4. Cont…
• Class is the keyword which makes our
program’s class.
• Class is the collection of the object’s properties
and behavior.
• HelloWorld is the name of the calss.
• Curly braces are the body of the program.
4/10/2019 Jamsher Bhanbhro(F16CS11) 4
5. Cont…
• public static : static is the reference variable or
the keyword which is used to call a function or
a program without creating an object.
• We have used static keyword with main
method because we may call it several times
so we want to call it directly without creating
it’s object many times.
• Void: this is the type the method it tells
methods will return some value.
4/10/2019 Jamsher Bhanbhro(F16CS11) 5
6. Cont…
• main: it is name of the method.
• String args[]: it is the array which tells that main method will take
arguments.
• We will further discus string args in the upcoming lectures.
• System: It is the class which is predefined in which there are built-in
functions for showing outputs.
• .out: it is an object or the reference variables which use the inner
functions of the System Class like printing some ting etc.
• println: print on new line.
• the square braces tells the args of the method.
• In the double square text is written which will show as it is on the
screen. In the above case there is Hello World
• And the last bracket use to end the program.
4/10/2019 Jamsher Bhanbhro(F16CS11) 6
7. Syntax
The above program uses the followings…
1. Classes
2. Objects
3. Keywords
4. Identifiers
5. Methods/Functions
6. Braces
4/10/2019 Jamsher Bhanbhro(F16CS11) 7
8. How to compile the java program
• After writing the code save it as Classname.java
• Name of the file and the class should be the same.
• If the path of your machine is than open command window and type javac and the
name of your program.java
• javac is the java compiler.
• After typing this in cmd press enter if there will be error of path set or errors in
your program than that will be shown here if not than .class file will be developed
in the directory where your program is saved.
• If .class file is formed it means your code is compiled successfully.
4/10/2019 Jamsher Bhanbhro(F16CS11) 8
9. How to execute a java program
• If there no any error occur during the compile
time it means your path is set and your code is
also right.
• So now for the execution or checking the
output functionality of our program we have to
write java class-name i.e java HelloWorld
4/10/2019 Jamsher Bhanbhro(F16CS11) 9
10. What is Camel Case in java
• Camel case stands that the first latter of the
each class should be written in the capital
letter.
• This is more useful because we will easy
understand that which is class when there is
large code in our program.
• In the above case there are three classes
• i- HelloWorld ii-System iii-String
4/10/2019 Jamsher Bhanbhro(F16CS11) 10