Introduction to Java
Introduction to Java
• Variables
• Variable is a placeholder for data that can change its
value during program execution.
• Technically, a variable is the name for a storage location
in the computer’s internal memory and the value of the
variable is the contents at that location.
Data types
• Data type determines the type of data to be stored in a
variable.
• Data type tells the compiler, how much memory to
reserve when storing a variable of that type.
• Declaring variable
• <Data type> <variable name>;
• int x;
float degree;
int a,b,c;
char ac_no;
Rules for naming variable
• Variable names can begin with either an alphabetic
character, an underscore (_), or a dollar sign ($).
• Variable names must be one word. Spaces are not
allowed in variable names. Underscores are allowed.
• There are some reserved words in Java that cannot be
used as variable names, for example – int
• Java is a case-sensitive language. Variable names
written in capital letters differ from variable names with
the same spelling but written in small letters.
Creating GUI Project
• Open NetBeans -> click on File -> New Project -> Select
‘Java with Ant’ from Category and ‘Java Application’
from project -> next -> Enter Project Name -> Finish
• NetBeans will create a folder of project name on
designated location in system. Now the next step is to
create a form.
Creating Form
• Right click the project name in Projects window -> New -
> JFrame -> Enter Class Name -> Finish
Adding and modifying components to Form
Adding a Button to Form
• Selection structures
• Repetition structures