Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

JAVA PROGRAMMING

Code : 05201201

MCA [ Semester-I ]
Faculty of IT & Compute Science
PARUL UNIVERSITY
Code : 05201201
UNIT-1 Introduction to Java
[Datatypes, Operators, Statements]

Lecture – 5

• Java program structure


• Java and Unicode
• Variables, literals, characters, variable declaration
• symbolic constants.
Java Program Structure

Documentation Section
Package Section

Import Section

Interface Section

Class Definitions

Main Class
{
main() method Definition
}
Sample program to understand the structure of basic
java program

/* This is a simple Java program named "Example1.java". */


class Example
{
// Your program begins with a call to main().
public static void main(String args[])
{
System.out.println("This is a simple Java program.");
}
}
Unicode System in Java

• Unicode = universal international standard character


encoding that is capable of representing
most of the world's written languages.

• Before Unicode, there were many language standards like


ASCII, ISO 8859-1, KOI-8, GB18030 and BIG-5 and so on.

• But, they have problems:


• A particular code value supports different language.

• The encodings for languages with large character sets have


variable length. Some common characters are encoded as
single bytes, other require two or more byte.
Unicode in java

• To solve these problems, a new language standard was


developed i.e. Unicode System.
• In unicode, character holds 2 byte, so java also uses 2 byte for
characters.
• lowest value:\u0000
• highest value:\uFFFF
• Java Unicode:
• Java was designed for using Unicode Transformed Format (UTF)-16,
when the UTF-16 was designed.
• The ‘char’ data type in Java originally used for representing 16-bit
Unicode.

• These days the Unicode standard defines values for over 100,000
characters. It has several character encoding forms like UTF-8,
UTF-16 and UTF-32.
JAVA Variables
• Java has three kinds of variables:
• instance variables,
• class variables, and
• local variables.

• Instance variables are used to define attributes of a particular


object. For exam: color, size, height of ITEM object.

• Class variables are similar to instance variables, except their


values apply to all that class’s instances (and to the class
itself) rather than having different values for each object.
For Example: static variables in class

• Local variables are declared and used inside method


definitions. They can also be used inside blocks ({}). For
example, index counters in loops, as temporary variables.
• For Example:
class FamilyMember
{
static String surname = “Johnson”;
String name;
int age;
...
}
• Class variable surname has only one value for all family
members.
• To access class variables, you use the same dot notation as you
do with instance variables. To get or change the value of the
class variable, you can use either the instance or the name of
the class.
• Both the lines of output in this example print the same value):
FamilyMember dad = new FamilyMember()
System.out.println(“Family’s surname is: “ + dad.surname);
System.out.println(“Family’s surname is: “ +FamilyMember.surname);

You might also like