Unit 1-Chapter 1&2 - Basics of Programming
Unit 1-Chapter 1&2 - Basics of Programming
Java
Unit 1 / Chapter 1
Basics of java
programming
1.1 HISTORY
• Java is high-level object-oriented programming language developed by the
sun microsystems.
• It was developed for the electronics and communication equipment.
• Later, it came into existence as a part of web application, web services and
platform independent programming language in 1990s
• Sun released the first public implementation as java 1.0 in 1995 as “write
once, Run anywhere”.
1.2 JAVA FEATURES
Objected Distributed Complied and
Simple Portability
Oriented computing Interpreted
High Multimedia
Performance Support
1.3 DIFFERENCE BETWEEN JAVA AND C
Sl. No C JAVA
Java is OOP language, everything in java is a
1 C is structured and POP language
part of the class
2 Pointers in C No pointers
Memory allocation and deallocation is Java Virtual Machine takes care of memory
3
handled by programmer management
4 Automatic type casting is available in C In some cases, implicit casting available in java
#define, typedef and header files are
5 No such files will be used.
used in C
6 Supports global variables No global variables in java
7 Supports structure and union No such methods
1.4 JAVA
ENVIRONMENT
• The java environment contains both
development tools and class libraries.
• The development tools are part of Java
Development Kit (JDK).
• Class libraries are part of java Application
Program Interface (API).
JAVA DEVELOPMENT KIT
• Appletviewer
• Javac (java compiler)
• Java (java interpreter)
• Javap (java disassembler)
• Javah (for c header files)
• Javadoc (for creating HTML documents)
• Jdb (java debugger)
SL.
TOOL DESCRIPTION
NO
Java interpreter, which runs applets and applications by reading the interpreting
2 Java
bytecode files
The java compiler, which translate java source code to bytecode files that the
3 Javac
interpreter can understand
4 Javadoc Creates HTML – format documentation from java source code files.
• Here class is a keyword and declares that a new class definition, SampleOne
is a java identifier that specifies the name of the class
2. BRACES
• Every java application program must include main() method and it’s the
starting point for the interpreter to begin the execution of the program.
Comments must explain why and what of classes and how of algorithms, this
will help in maintaining the program.
This statement declares a package name and informs the compiler that the classes
defined here belongs to this package.
Package statement is optional. That is, our classes do not have to be part of
package.
This is similar to #include statement in c
language.
Import student.test;
IMPORT
STATEMENTS
This statement instructs the interpreter to
load the test class contained in the
package student.
CLASS These classes are used to map the objects of real world
DEFINITION problems.
These keywords will combine with operators and separators according to the syntax, from the
definition of java language.
• They are used for naming classes, methods, variables, objects, labels, packages and
interfaces in a program.
They can have alphabets, digits and the underscore and dollar sign characters.
1. Name of all public methods and instance variables start with a lowercase letter.
2. When more than one words are used in a name, the second and subsequent words are
marked with uppercase letters.
1. Integer Literals
2. Floating_point Literal
3. Character Literal.
4. String Literal
5. Boolean Literal
Arithmetic Operators
Relational Operators
Logical Operators
Assignment Operators
operators Increment and decrement Operators
Conditional Operators
Bitwise Operators
Special Operators
SEPARATORS
• Separators are symbols used to indicate where groups of code are divided and
arranged.
• They basically define the shape and function of our code.
Name Used for
Parentheses() Used to enclose parameters
Braces {} Used to contain the values of automatically initialized arrays
Brackets [] Used to declare array types
Semicolon ; Used to separate statements
Comma , Used to separate consecutive identifiers
Period . Used to separate package names from sub-packages and classes
JAVA STATEMENTS
• Statements are usually executed in sequence in the order in which they appear.
There are3 types of integers; decimal integer, octal and hexadecimal integer.
Decimal integer consist of set of digits [0-9], preceded by an optional minus sign.
• Example: 123, -254, 25477
Embedded spaces, commas, and non-digit characters are not permitted between digits.
• Example: 12 750 30.000 $100 are illegal numbers.
An octal integer constant A sequence of digits
consist of any combination preceded by 0x or 0X is
of digits from the set 0 considered as hexadecimal
through 7, with a leading 0. integer.
Example: 0X2
Example: 037
ox9F
00 0437 0661
oxbd
Integer constants are inadequate to represent
quantities that vary continuously, such as
distance, heights, temperature and so on.
The characters may be alphabets, digits, Example: “Hello Java”, “1997”, “!@...,”
special characters and blank spaces
output methods.
2.
VARIABLE • A variable is an identifier that denotes a
storage location used to store a data
S value.
• Unlike constants that remain unchanged
during the execution of a program, a
variable make take different values at
different times during the execution.
• Example :height, length, total
• Variable names may consist of alphabets,
digit, the underscore and dollar character,
subjected to the following condition,
• They must not begin with digit
• As a result, the print() method prints output on one line until a new line character is
encountered.
System.out.println (“Hello”);
System.out.println (“Java”);
The println() method, by contrast, takes the information provided and displays it
on a line followed by a line feed
System.out.println(“Hello”); System.out.println(“JAVA”);
THANK YOU