SlideShare a Scribd company logo
1 of 30
PROGRAMMING IN JAVA
A. SIVASANKARI
ASSISTANT PROFESSOR
DEPARTMENT OF COMPUTER SCIENCE
SHANMUGA INDUSTRIES ARTS AND SCIENCE COLLEGE,
TIRUVANNAMALAI. 606601.
Email: sivasankaridkm@gmail.com
PROGRAMMING IN JAVA
UNIT - 1
 HISTORY OF JAVA
 FEATURES OF JAVA
 CLASSES AND OBJECTS
 BASIC DATATYPES
 VARIABLE AND ITS TYPES
 STRING CLASS
 BASIC OPERATORS
 CONTROL STATEMENTS
 CONSTRUCTORS
 JAVA PACKAGE
 METHOD OVERLOADING
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
UNIT -1 A
 HISTORY OF JAVA
 FEATURES OF JAVA
 CLASSES AND
OBJECTS
 BASIC DATATYPES
 VARIABLE AND ITS
TYPES
 STRING CLASS
A. SIVASANKARI - SIASC-TVM
INTRODUCTION TO JAVA
• Java is a high-level programming language originally developed by Sun
Microsystems and released in 1995. Java runs on a variety of platforms,
such as Windows, Mac OS, and the various versions of UNIX.
• Java is developed by James Gosling at Sun Micro system in the year 1991.
• Initially it was named “OAK”. Oak was renamed as "Java"
• It is a platform independent language
• Java is case sensitive.
• Example: System.in
• Now Java is being used in Windows applications, Web applications,
enterprise applications, mobile applications, cards, and also used to create
a software on electronic device.
• Example: Microwave Oven, Remote Control.
• Java programs run in variety of CPU and different environments. Java was
originally designed for interactive television, but it was too advanced
technology for the digital cable television industry at the time.
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
JAVA VERSIONS
1. JDK Alpha and Beta (1995)
2. JDK 1.0 (23rd Jan 1996)
3. JDK 1.1 (19th Feb 1997)
4. J2SE 1.2 (8th Dec 1998)
5. J2SE 1.3 (8th May 2000)
6. J2SE 1.4 (6th Feb 2002)
7. J2SE 5.0 (30th Sep 2004)
8. Java SE 6 (11th Dec 2006)
9. Java SE 7 (28th July 2011)
10. Java SE 8 (18th Mar 2014)
11. Java SE 9 (21st Sep 2017)
12. Java SE 10 (20th Mar 2018)
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
IMPORTANCE OF JAVA
• Java is forefront of program.
• Java expends the universe of object. We can access and create Object
University.
• Client and server process also access in java.
• It is divided into 3 performance
• Passive
• Dynamic
• Active
• Java divided into applet and applications
APPLICATIONS:
• It is a program that runs on our computer under the operating system of
that computer.
• Example: C, C++, Java
APPLETS:
• It is an application designed to be transmitted over the internet and
executed by a java compatible with browser.
• It is an intelligence program. Applications having Animations is called
applets.
• Example: sound, Image, Video clips.
SECURITY:
• To avoid the viral infection we use security.
• Example: Firewall method, K7, Trojan Horse, etc.
PORTABILITY:
• Many type of computers and operating system are in use throughout the
world and many are connected to the internet.
• It is elegant and efficient.
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
THE BYTE CODE
• Java compiler is not executable code. It is executed by a byte code.
• Byte code is highly optimized set of instructions designed to be executable by the Java Run Time
system is called Java Virtual Machine(JVM).
• JVM is an interpreter for byte code.
• Translating a java program into byte code helps makes it much easier to run s program in a wide
variety of environments.
• It is much faster.
• Java2 release Java In time Compiler(JIT) for byte code.
• JIT is part of JVM. It combines byte code into executable code in real time on a piece by piece.
Difference between JDK, JRE, and JVM
1.A specification where working of Java Virtual Machine is specified. But implementation provider is
independent to choose the algorithm. Its implementation has been provided by Oracle and other
companies.
2.An implementation Its implementation is known as JRE (Java Runtime Environment).
3.Runtime Instance Whenever you write java command on the command prompt to run the java class, an
instance of JVM is created.
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
FEATURES OF JAVA
• Simple
• Object-Oriented
• Portable
• Platform independent
• Secured
• Robust
• Architecture neutral
• Interpreted
• High Performance
• Multithreaded
• Distributed
• Dynamic
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
SIMPLE
• Java is very easy to learn, and its syntax is simple, clean and easy to understand. According to Sun,
Java language is a simple programming language because:
• Java syntax is based on C++ (so easier for programmers to learn it after C++).
• Java has removed many complicated and rarely-used features, for example, explicit pointers,
operator overloading, etc.
OBJECT-ORIENTED
• Basic concepts of OOPs are:
• Object
• Class
• Inheritance
• Polymorphism
• Abstraction
• Encapsulation
SECURED
• Java is best known for its security. With Java, we can develop virus-free systems. Java is secured
because:
• No explicit pointer
• Java Programs run inside a virtual machine sandbox
• Classloader: Class loader in Java is a part of the Java Runtime Environment(JRE) which is used to
load Java classes into the Java Virtual Machine dynamically. It adds security by separating the
package for the classes of the local file system from those that are imported from network sources.
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
ROBUST
• Robust simply means strong. Java is robust because:
• It uses strong memory management.
• There is a lack of pointers that avoids security problems.
• There is automatic garbage collection in java which runs on the Java Virtual Machine to get rid of objects
which are not being used by a Java application anymore.
• There are exception handling and the type checking mechanism in Java. All these points make Java
robust.
HIGH-PERFORMANCE
• Java is faster than other traditional interpreted programming languages because Java bytecode is "close"
to native code. It is still a little bit slower than a compiled language (e.g., C++). Java is an interpreted
language that is why it is slower than compiled languages, e.g., C, C++, etc.
DISTRIBUTED
• Java is distributed because it facilitates users to create distributed applications in Java. RMI and EJB are
used for creating distributed applications. This feature of Java makes us able to access files by calling the
methods from any machine on the internet
MULTI-THREADED
• A thread is like a separate program, executing concurrently. We can write Java programs that deal with
many tasks at once by defining multiple threads. The main advantage of multi-threading is that it doesn't
occupy memory for each thread. It shares a common memory area. Threads are important for multi-media,
Web applications, etc.
DYNAMIC
• Java is a dynamic language. It supports dynamic loading of classes. It means classes are loaded on
demand. It also supports functions from its native languages, i.e., C and C++.
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
CLASSES AND OBJECTS
Object − Objects have states and behaviours. Example: A dog has states - color, name, breed as
well as behaviours – wagging the tail, barking, eating. An object is an instance of a class.
Class − A class can be defined as a template/blueprint that describes the behaviour/state that the
object of its type support.
• SYNTAX OF CLASS:
• Class classname
• {
• Type instance variable 1;
• .
• .
• Type instance variable N;
• Type methodname1(parameter list)
• {
• Body of the method
• }
• Type methodnameN(parameter list)
• {
• Body of the method
• }
• }
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
SAMPLE PROGRAM
• Class Simple
• {
• public static void main(String args[])
• {
• System.out.println(“Welcome to JAVA”);
• }
• }
COMPILATION
• C:> bin> javac Simple.java
RUN
• C:> bin> java Simple
OUTPUT
• Welcome to JAVA
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
CREATING AN OBJECT
There are three steps when creating an object from a class −
• Declaration − A variable declaration with a variable name with an object type.
• Instantiation − The 'new' keyword is used to create the object.
• Initialization − The 'new' keyword is followed by a call to a constructor. This call initializes
the new object.
DECLARING OBJECTS: TWO TYPES
Syntax of Object
1. Classname objectname=new classname()
2. Classname objectname;
Objectname=new classname();
Example of Object Declaration
1. Box mybox=new Box());
2. Box mybox;
mybox=new box();
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
• SAMPLE PROGRAM:
• Class box
• {
• Double width;
• Double height;
• Double depth;
• }
• Class boxdemo
• {
• public static void main(String args[])
• box mybox=new box();
• Double volume;
• Mybox.width=10;
• Mybox.height=20;
• Mybox.depth=15;
• Volume=mybox.width*mybox.height*mybox.depth;
• System.out.println(“The value is :”+ volume);
• }}
OUTPUT: Volume=3000
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
BASIC DATATYPES
• Variables are nothing but reserved memory locations to store values. This means
that when you create a variable you reserve some space in the memory.
• Based on the data type of a variable, the operating system allocates memory and
decides what can be stored in the reserved memory. Therefore, by assigning
different data types to variables, we can store integers, decimals, or characters in
these variables.
There are two data types available in Java
• Primitive Data Types
• Reference/Object Data Types
PRIMITIVE DATA TYPES
Data type long int short byte double float char Boolean
Width
64 32 16 8 64 32 255 True/False
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
• BYTE
• Byte data type is an 8-bit signed two's complement integer
• Minimum value is -128 (-2^7)
• Maximum value is 127 (inclusive)(2^7 -1)
• Default value is 0
• Byte data type is used to save space in large arrays, mainly in place of integers, since a byte
is four times smaller than an integer.
• Example: byte a = 100, byte b = -50
• SHORT
• Short data type is a 16-bit signed two's complement integer
• Minimum value is -32,768 (-2^15)
• Maximum value is 32,767 (inclusive) (2^15 -1)
• Short data type can also be used to save memory as byte data type. A short is 2 times smaller
than an integer
• Default value is 0..
• LONG
• Long data type is a 64-bit signed two's complement integer
• Minimum value is -9,223,372,036,854,775,808(-2^63)
• Maximum value is 9,223,372,036,854,775,807 (inclusive)(2^63 -1)
• This type is used when a wider range than int is needed
• Default value is 0L
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
• FLOAT
• Float data type is a single-precision 32-bit IEEE 754
floating point
• Float is mainly used to save memory in large arrays
of floating point numbers
• Default value is 0.0f
• BOOLEAN
• boolean data type represents one bit of information
• There are only two possible values: true and false
• CHAR
• char data type is a single 16-bit Unicode character
• Minimum value is 'u0000' (or 0)
• Maximum value is 'uffff' (or 65,535 inclusive)
• Char data type is used to store any character
• Example: char letterA = 'A'
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
LEXICAL ISSUES:
• White space
• Identifier
• Literals
• Commends
• Separators
• Java Keywords
JAVA LITERALS
• A literal is a source code representation of a fixed value. They are represented
directly in the code without any computation.
• Literals can be assigned to any primitive type variable. For example −
• byte a = 68;char a = 'A';
• byte, int, long, and short can be expressed in decimal(base 10), hexadecimal(base
16) or octal(base 8) number systems as well.
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
JAVA KEYWORDS
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
VARIABLE AND ITS TYPES
A variable provides us with named storage that our
programs can manipulate. Each variable in Java has a specific
type, which determines the size and layout of the variable's
memory; the range of values that can be stored within that
memory; and the set of operations that can be applied to the
variable.
Example
• int a, b, c; // Declares three int s, a, b, and c.
• int a = 10, b = 10; // Example of initialization
• byte B = 22; // initializes a byte type variable
• B.double pi = 3.14159; // declares and assigns a value of PI.
• char a = 'a'; // the char variable a is initialized with value
'a‘
TYPES OF VARIABLE
• Local variables
• Instance variables
• Class/Static variables
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
LOCAL VARIABLES
• Local variables are declared in methods, constructors, or blocks.
• Local variables are created when the method, constructor or block is entered and the
variable will be destroyed once it exits the method, constructor, or block.
• Access modifiers cannot be used for local variables.
• Local variables are visible only within the declared method, constructor, or block.
INSTANCE VARIABLES
• Instance variables are declared in a class, but outside a method, constructor or any
block.
• When a space is allocated for an object in the heap, a slot for each instance variable
value is created.
• Instance variables are created when an object is created with the use of the keyword
'new' and destroyed when the object is destroyed.
• Instance variables hold values that must be referenced by more than one method,
constructor or block, or essential parts of an object's state that must be present
throughout the class.
• Instance variables can be accessed directly by calling the variable name inside the
class. However, within static methods (when instance variables are given
accessibility), they should be called using the fully qualified
name. ObjectReference.VariableName.
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
STATIC VARIABLES OR CONSTANT VARIABLE
• Class variables also known as static variables are declared with the static
keyword in a class, but outside a method, constructor or a block.
• There would only be one copy of each class variable per class, regardless
of how many objects are created from it.
• Static variables are rarely used other than being declared as constants.
Constants are variables that are declared as public/private, final, and static.
Constant variables never change from their initial value.
• Static variables are stored in the static memory. It is rare to use static
variables other than declared final and used as either public or private
constants.
• Static variables are created when the program starts and destroyed when the
program stops.
• Static variables can be accessed by calling with the class
name ClassName.VariableName.
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
SAMPLE PROGRAM
• import java.io.*;
• public class Employee
• {
• // salary variable is a private static variable
• private static double salary;
• // DEPARTMENT is a constant public static final String DEPARTMENT = "Development ";
• public static void main(String args[])
• {
• salary = 1000;
• System.out.println(DEPARTMENT + "average salary:" + salary);
• }
• }
OUTPUT
• Development average salary:1000
• Note − If the variables are accessed from an outside class, the constant should be accessed as
Employee.DEPARTMENT
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
MODIFIER TYPES
• Modifiers are keywords that you add to those definitions to change their
meanings. Java language has a wide variety of modifiers, including the
following −
1. Java Access Modifiers
2. Non Access Modifiers
ACCESS CONTROL MODIFIERS
• Java provides a number of access modifiers to set access levels for classes,
variables, methods and constructors. The four access levels are −
• Visible to the package, the default. No modifiers are needed.
• Visible to the class only (private).
• Visible to the world (public).
• Visible to the package and all subclasses (protected).
NON-ACCESS MODIFIERS
• Java provides a number of non-access modifiers to achieve many other
functionality.
• The static modifier for creating class methods and variables.
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
• The final modifier for finalizing the implementations of classes, methods,
and variables.
• The abstract modifier for creating abstract classes and methods.
• The synchronized and volatile modifiers, which are used for threads.
DYNAMIC INITIALIZATION
• Class sample
• {
• Public static void main(String args[])
• {
• int a=,b=4; //dynamic intialization
• int c=math.sqrt(a*a + b*b);
• System.out.println(“The value of c is “+c);
• }
• }
• Output:
• The value of c is: 5
TYPE CONVERSIONS AND CASTING
• One data type automatically converted into another.
• Example:
• int a,b;
• float c;
• c=a+b;
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
STRING CLASS
• Strings, which are widely used in Java programming, are a sequence of characters. In Java
programming language, strings are treated as objects.
• The Java platform provides the String class to create and manipulate strings.
• Creating Strings
• The most direct way to create a string is to write
• String greeting = "Hello world!";
• Whenever it encounters a string literal in your code, the compiler creates a String object with
its value in this case, "Hello world!'.
• EXAMPLE
• public class StringDemo
• {
• public static void main(String args[])
• {
• char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.' };
• String helloString = new String(helloArray);
• System.out.println( helloString );
• }}
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
PROGRAMMING IN JAVA
A. SIVASANKARI - SIASC-TVM
A. SIVASANKARI - SIASC-TVM

More Related Content

What's hot

Introduction to java
Introduction to javaIntroduction to java
Introduction to javaSteve Fort
 
Java 101 Intro to Java Programming
Java 101 Intro to Java ProgrammingJava 101 Intro to Java Programming
Java 101 Intro to Java Programmingagorolabs
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java ProgrammingRavi Kant Sahu
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)slire
 
What Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
What Is Java | Java Tutorial | Java Programming | Learn Java | EdurekaWhat Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
What Is Java | Java Tutorial | Java Programming | Learn Java | EdurekaEdureka!
 
Java 101 intro to programming with java
Java 101  intro to programming with javaJava 101  intro to programming with java
Java 101 intro to programming with javaHawkman Academy
 
Java basic-tutorial for beginners
Java basic-tutorial for beginners Java basic-tutorial for beginners
Java basic-tutorial for beginners Muzammil Ali
 
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...Edureka!
 

What's hot (18)

Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java 101 Intro to Java Programming
Java 101 Intro to Java ProgrammingJava 101 Intro to Java Programming
Java 101 Intro to Java Programming
 
Letest
LetestLetest
Letest
 
Presentation on java
Presentation  on  javaPresentation  on  java
Presentation on java
 
Java basic introduction
Java basic introductionJava basic introduction
Java basic introduction
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Basic java part_ii
Basic java part_iiBasic java part_ii
Basic java part_ii
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
What Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
What Is Java | Java Tutorial | Java Programming | Learn Java | EdurekaWhat Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
What Is Java | Java Tutorial | Java Programming | Learn Java | Edureka
 
Java 101
Java 101Java 101
Java 101
 
Java 101 intro to programming with java
Java 101  intro to programming with javaJava 101  intro to programming with java
Java 101 intro to programming with java
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Java basic-tutorial for beginners
Java basic-tutorial for beginners Java basic-tutorial for beginners
Java basic-tutorial for beginners
 
Java 8 Features
Java 8 FeaturesJava 8 Features
Java 8 Features
 
Core Java
Core JavaCore Java
Core Java
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
Java Threads Tutorial | Multithreading In Java Tutorial | Java Tutorial For B...
 
Core Java
Core JavaCore Java
Core Java
 

Similar to Java unit1 a- History of Java to string

Similar to Java unit1 a- History of Java to string (20)

JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptxJAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
 
Java programming and security
Java programming and securityJava programming and security
Java programming and security
 
JAVA-History-buzzwords-JVM_architecture.pptx
JAVA-History-buzzwords-JVM_architecture.pptxJAVA-History-buzzwords-JVM_architecture.pptx
JAVA-History-buzzwords-JVM_architecture.pptx
 
JAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptxJAVA_Day1_BasicIntroduction.pptx
JAVA_Day1_BasicIntroduction.pptx
 
JAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptxJAVAPart1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptx
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Presentation on java
Presentation on javaPresentation on java
Presentation on java
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
Java Programming concept
Java Programming concept Java Programming concept
Java Programming concept
 
1.Intro--Why Java.pptx
1.Intro--Why Java.pptx1.Intro--Why Java.pptx
1.Intro--Why Java.pptx
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
 
L1 basics
L1 basicsL1 basics
L1 basics
 
Chapter 1 (1).pptx
Chapter 1 (1).pptxChapter 1 (1).pptx
Chapter 1 (1).pptx
 
Java notes | All Basics |
Java notes | All Basics |Java notes | All Basics |
Java notes | All Basics |
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
1. JAVA_Module_1-edited - AJIN ABRAHAM.pptx.pdf
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
java full 1.docx
java full 1.docxjava full 1.docx
java full 1.docx
 

More from SivaSankari36

DATA STRUCTURE BY SIVASANKARI
DATA STRUCTURE BY SIVASANKARIDATA STRUCTURE BY SIVASANKARI
DATA STRUCTURE BY SIVASANKARISivaSankari36
 
CLOUD COMPUTING BY SIVASANKARI
CLOUD COMPUTING BY SIVASANKARICLOUD COMPUTING BY SIVASANKARI
CLOUD COMPUTING BY SIVASANKARISivaSankari36
 
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARIMOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARISivaSankari36
 
MOBILE COMPUTING BY SIVASANKARI
MOBILE COMPUTING BY SIVASANKARIMOBILE COMPUTING BY SIVASANKARI
MOBILE COMPUTING BY SIVASANKARISivaSankari36
 
Functional MRI using Apache Spark in Big Data Application
Functional MRI using Apache Spark in Big Data ApplicationFunctional MRI using Apache Spark in Big Data Application
Functional MRI using Apache Spark in Big Data ApplicationSivaSankari36
 
Java unit1 b- Java Operators to Methods
Java  unit1 b- Java Operators to MethodsJava  unit1 b- Java Operators to Methods
Java unit1 b- Java Operators to MethodsSivaSankari36
 

More from SivaSankari36 (6)

DATA STRUCTURE BY SIVASANKARI
DATA STRUCTURE BY SIVASANKARIDATA STRUCTURE BY SIVASANKARI
DATA STRUCTURE BY SIVASANKARI
 
CLOUD COMPUTING BY SIVASANKARI
CLOUD COMPUTING BY SIVASANKARICLOUD COMPUTING BY SIVASANKARI
CLOUD COMPUTING BY SIVASANKARI
 
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARIMOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
MOBILE APPLICATIONS DEVELOPMENT -ANDROID BY SIVASANKARI
 
MOBILE COMPUTING BY SIVASANKARI
MOBILE COMPUTING BY SIVASANKARIMOBILE COMPUTING BY SIVASANKARI
MOBILE COMPUTING BY SIVASANKARI
 
Functional MRI using Apache Spark in Big Data Application
Functional MRI using Apache Spark in Big Data ApplicationFunctional MRI using Apache Spark in Big Data Application
Functional MRI using Apache Spark in Big Data Application
 
Java unit1 b- Java Operators to Methods
Java  unit1 b- Java Operators to MethodsJava  unit1 b- Java Operators to Methods
Java unit1 b- Java Operators to Methods
 

Recently uploaded

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 

Recently uploaded (20)

POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 

Java unit1 a- History of Java to string

  • 1. PROGRAMMING IN JAVA A. SIVASANKARI ASSISTANT PROFESSOR DEPARTMENT OF COMPUTER SCIENCE SHANMUGA INDUSTRIES ARTS AND SCIENCE COLLEGE, TIRUVANNAMALAI. 606601. Email: sivasankaridkm@gmail.com
  • 2. PROGRAMMING IN JAVA UNIT - 1  HISTORY OF JAVA  FEATURES OF JAVA  CLASSES AND OBJECTS  BASIC DATATYPES  VARIABLE AND ITS TYPES  STRING CLASS  BASIC OPERATORS  CONTROL STATEMENTS  CONSTRUCTORS  JAVA PACKAGE  METHOD OVERLOADING A. SIVASANKARI - SIASC-TVM
  • 3. PROGRAMMING IN JAVA UNIT -1 A  HISTORY OF JAVA  FEATURES OF JAVA  CLASSES AND OBJECTS  BASIC DATATYPES  VARIABLE AND ITS TYPES  STRING CLASS A. SIVASANKARI - SIASC-TVM
  • 4. INTRODUCTION TO JAVA • Java is a high-level programming language originally developed by Sun Microsystems and released in 1995. Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. • Java is developed by James Gosling at Sun Micro system in the year 1991. • Initially it was named “OAK”. Oak was renamed as "Java" • It is a platform independent language • Java is case sensitive. • Example: System.in • Now Java is being used in Windows applications, Web applications, enterprise applications, mobile applications, cards, and also used to create a software on electronic device. • Example: Microwave Oven, Remote Control. • Java programs run in variety of CPU and different environments. Java was originally designed for interactive television, but it was too advanced technology for the digital cable television industry at the time. PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 5. JAVA VERSIONS 1. JDK Alpha and Beta (1995) 2. JDK 1.0 (23rd Jan 1996) 3. JDK 1.1 (19th Feb 1997) 4. J2SE 1.2 (8th Dec 1998) 5. J2SE 1.3 (8th May 2000) 6. J2SE 1.4 (6th Feb 2002) 7. J2SE 5.0 (30th Sep 2004) 8. Java SE 6 (11th Dec 2006) 9. Java SE 7 (28th July 2011) 10. Java SE 8 (18th Mar 2014) 11. Java SE 9 (21st Sep 2017) 12. Java SE 10 (20th Mar 2018) PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 6. IMPORTANCE OF JAVA • Java is forefront of program. • Java expends the universe of object. We can access and create Object University. • Client and server process also access in java. • It is divided into 3 performance • Passive • Dynamic • Active • Java divided into applet and applications APPLICATIONS: • It is a program that runs on our computer under the operating system of that computer. • Example: C, C++, Java APPLETS: • It is an application designed to be transmitted over the internet and executed by a java compatible with browser. • It is an intelligence program. Applications having Animations is called applets. • Example: sound, Image, Video clips. SECURITY: • To avoid the viral infection we use security. • Example: Firewall method, K7, Trojan Horse, etc. PORTABILITY: • Many type of computers and operating system are in use throughout the world and many are connected to the internet. • It is elegant and efficient. PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 7. THE BYTE CODE • Java compiler is not executable code. It is executed by a byte code. • Byte code is highly optimized set of instructions designed to be executable by the Java Run Time system is called Java Virtual Machine(JVM). • JVM is an interpreter for byte code. • Translating a java program into byte code helps makes it much easier to run s program in a wide variety of environments. • It is much faster. • Java2 release Java In time Compiler(JIT) for byte code. • JIT is part of JVM. It combines byte code into executable code in real time on a piece by piece. Difference between JDK, JRE, and JVM 1.A specification where working of Java Virtual Machine is specified. But implementation provider is independent to choose the algorithm. Its implementation has been provided by Oracle and other companies. 2.An implementation Its implementation is known as JRE (Java Runtime Environment). 3.Runtime Instance Whenever you write java command on the command prompt to run the java class, an instance of JVM is created. PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 8. FEATURES OF JAVA • Simple • Object-Oriented • Portable • Platform independent • Secured • Robust • Architecture neutral • Interpreted • High Performance • Multithreaded • Distributed • Dynamic PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 9. SIMPLE • Java is very easy to learn, and its syntax is simple, clean and easy to understand. According to Sun, Java language is a simple programming language because: • Java syntax is based on C++ (so easier for programmers to learn it after C++). • Java has removed many complicated and rarely-used features, for example, explicit pointers, operator overloading, etc. OBJECT-ORIENTED • Basic concepts of OOPs are: • Object • Class • Inheritance • Polymorphism • Abstraction • Encapsulation SECURED • Java is best known for its security. With Java, we can develop virus-free systems. Java is secured because: • No explicit pointer • Java Programs run inside a virtual machine sandbox • Classloader: Class loader in Java is a part of the Java Runtime Environment(JRE) which is used to load Java classes into the Java Virtual Machine dynamically. It adds security by separating the package for the classes of the local file system from those that are imported from network sources. PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 10. ROBUST • Robust simply means strong. Java is robust because: • It uses strong memory management. • There is a lack of pointers that avoids security problems. • There is automatic garbage collection in java which runs on the Java Virtual Machine to get rid of objects which are not being used by a Java application anymore. • There are exception handling and the type checking mechanism in Java. All these points make Java robust. HIGH-PERFORMANCE • Java is faster than other traditional interpreted programming languages because Java bytecode is "close" to native code. It is still a little bit slower than a compiled language (e.g., C++). Java is an interpreted language that is why it is slower than compiled languages, e.g., C, C++, etc. DISTRIBUTED • Java is distributed because it facilitates users to create distributed applications in Java. RMI and EJB are used for creating distributed applications. This feature of Java makes us able to access files by calling the methods from any machine on the internet MULTI-THREADED • A thread is like a separate program, executing concurrently. We can write Java programs that deal with many tasks at once by defining multiple threads. The main advantage of multi-threading is that it doesn't occupy memory for each thread. It shares a common memory area. Threads are important for multi-media, Web applications, etc. DYNAMIC • Java is a dynamic language. It supports dynamic loading of classes. It means classes are loaded on demand. It also supports functions from its native languages, i.e., C and C++. PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 11. CLASSES AND OBJECTS Object − Objects have states and behaviours. Example: A dog has states - color, name, breed as well as behaviours – wagging the tail, barking, eating. An object is an instance of a class. Class − A class can be defined as a template/blueprint that describes the behaviour/state that the object of its type support. • SYNTAX OF CLASS: • Class classname • { • Type instance variable 1; • . • . • Type instance variable N; • Type methodname1(parameter list) • { • Body of the method • } • Type methodnameN(parameter list) • { • Body of the method • } • } PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 12. SAMPLE PROGRAM • Class Simple • { • public static void main(String args[]) • { • System.out.println(“Welcome to JAVA”); • } • } COMPILATION • C:> bin> javac Simple.java RUN • C:> bin> java Simple OUTPUT • Welcome to JAVA PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 13. CREATING AN OBJECT There are three steps when creating an object from a class − • Declaration − A variable declaration with a variable name with an object type. • Instantiation − The 'new' keyword is used to create the object. • Initialization − The 'new' keyword is followed by a call to a constructor. This call initializes the new object. DECLARING OBJECTS: TWO TYPES Syntax of Object 1. Classname objectname=new classname() 2. Classname objectname; Objectname=new classname(); Example of Object Declaration 1. Box mybox=new Box()); 2. Box mybox; mybox=new box(); PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 14. • SAMPLE PROGRAM: • Class box • { • Double width; • Double height; • Double depth; • } • Class boxdemo • { • public static void main(String args[]) • box mybox=new box(); • Double volume; • Mybox.width=10; • Mybox.height=20; • Mybox.depth=15; • Volume=mybox.width*mybox.height*mybox.depth; • System.out.println(“The value is :”+ volume); • }} OUTPUT: Volume=3000 PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 15. BASIC DATATYPES • Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory. • Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, we can store integers, decimals, or characters in these variables. There are two data types available in Java • Primitive Data Types • Reference/Object Data Types PRIMITIVE DATA TYPES Data type long int short byte double float char Boolean Width 64 32 16 8 64 32 255 True/False PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 16. • BYTE • Byte data type is an 8-bit signed two's complement integer • Minimum value is -128 (-2^7) • Maximum value is 127 (inclusive)(2^7 -1) • Default value is 0 • Byte data type is used to save space in large arrays, mainly in place of integers, since a byte is four times smaller than an integer. • Example: byte a = 100, byte b = -50 • SHORT • Short data type is a 16-bit signed two's complement integer • Minimum value is -32,768 (-2^15) • Maximum value is 32,767 (inclusive) (2^15 -1) • Short data type can also be used to save memory as byte data type. A short is 2 times smaller than an integer • Default value is 0.. • LONG • Long data type is a 64-bit signed two's complement integer • Minimum value is -9,223,372,036,854,775,808(-2^63) • Maximum value is 9,223,372,036,854,775,807 (inclusive)(2^63 -1) • This type is used when a wider range than int is needed • Default value is 0L PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 17. • FLOAT • Float data type is a single-precision 32-bit IEEE 754 floating point • Float is mainly used to save memory in large arrays of floating point numbers • Default value is 0.0f • BOOLEAN • boolean data type represents one bit of information • There are only two possible values: true and false • CHAR • char data type is a single 16-bit Unicode character • Minimum value is 'u0000' (or 0) • Maximum value is 'uffff' (or 65,535 inclusive) • Char data type is used to store any character • Example: char letterA = 'A' PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 18. LEXICAL ISSUES: • White space • Identifier • Literals • Commends • Separators • Java Keywords JAVA LITERALS • A literal is a source code representation of a fixed value. They are represented directly in the code without any computation. • Literals can be assigned to any primitive type variable. For example − • byte a = 68;char a = 'A'; • byte, int, long, and short can be expressed in decimal(base 10), hexadecimal(base 16) or octal(base 8) number systems as well. PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 19. JAVA KEYWORDS PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 20. VARIABLE AND ITS TYPES A variable provides us with named storage that our programs can manipulate. Each variable in Java has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable. Example • int a, b, c; // Declares three int s, a, b, and c. • int a = 10, b = 10; // Example of initialization • byte B = 22; // initializes a byte type variable • B.double pi = 3.14159; // declares and assigns a value of PI. • char a = 'a'; // the char variable a is initialized with value 'a‘ TYPES OF VARIABLE • Local variables • Instance variables • Class/Static variables PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 21. LOCAL VARIABLES • Local variables are declared in methods, constructors, or blocks. • Local variables are created when the method, constructor or block is entered and the variable will be destroyed once it exits the method, constructor, or block. • Access modifiers cannot be used for local variables. • Local variables are visible only within the declared method, constructor, or block. INSTANCE VARIABLES • Instance variables are declared in a class, but outside a method, constructor or any block. • When a space is allocated for an object in the heap, a slot for each instance variable value is created. • Instance variables are created when an object is created with the use of the keyword 'new' and destroyed when the object is destroyed. • Instance variables hold values that must be referenced by more than one method, constructor or block, or essential parts of an object's state that must be present throughout the class. • Instance variables can be accessed directly by calling the variable name inside the class. However, within static methods (when instance variables are given accessibility), they should be called using the fully qualified name. ObjectReference.VariableName. PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 22. STATIC VARIABLES OR CONSTANT VARIABLE • Class variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block. • There would only be one copy of each class variable per class, regardless of how many objects are created from it. • Static variables are rarely used other than being declared as constants. Constants are variables that are declared as public/private, final, and static. Constant variables never change from their initial value. • Static variables are stored in the static memory. It is rare to use static variables other than declared final and used as either public or private constants. • Static variables are created when the program starts and destroyed when the program stops. • Static variables can be accessed by calling with the class name ClassName.VariableName. PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 23. SAMPLE PROGRAM • import java.io.*; • public class Employee • { • // salary variable is a private static variable • private static double salary; • // DEPARTMENT is a constant public static final String DEPARTMENT = "Development "; • public static void main(String args[]) • { • salary = 1000; • System.out.println(DEPARTMENT + "average salary:" + salary); • } • } OUTPUT • Development average salary:1000 • Note − If the variables are accessed from an outside class, the constant should be accessed as Employee.DEPARTMENT PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 24. MODIFIER TYPES • Modifiers are keywords that you add to those definitions to change their meanings. Java language has a wide variety of modifiers, including the following − 1. Java Access Modifiers 2. Non Access Modifiers ACCESS CONTROL MODIFIERS • Java provides a number of access modifiers to set access levels for classes, variables, methods and constructors. The four access levels are − • Visible to the package, the default. No modifiers are needed. • Visible to the class only (private). • Visible to the world (public). • Visible to the package and all subclasses (protected). NON-ACCESS MODIFIERS • Java provides a number of non-access modifiers to achieve many other functionality. • The static modifier for creating class methods and variables. PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 25. PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM • The final modifier for finalizing the implementations of classes, methods, and variables. • The abstract modifier for creating abstract classes and methods. • The synchronized and volatile modifiers, which are used for threads.
  • 26. DYNAMIC INITIALIZATION • Class sample • { • Public static void main(String args[]) • { • int a=,b=4; //dynamic intialization • int c=math.sqrt(a*a + b*b); • System.out.println(“The value of c is “+c); • } • } • Output: • The value of c is: 5 TYPE CONVERSIONS AND CASTING • One data type automatically converted into another. • Example: • int a,b; • float c; • c=a+b; PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 27. STRING CLASS • Strings, which are widely used in Java programming, are a sequence of characters. In Java programming language, strings are treated as objects. • The Java platform provides the String class to create and manipulate strings. • Creating Strings • The most direct way to create a string is to write • String greeting = "Hello world!"; • Whenever it encounters a string literal in your code, the compiler creates a String object with its value in this case, "Hello world!'. • EXAMPLE • public class StringDemo • { • public static void main(String args[]) • { • char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.' }; • String helloString = new String(helloArray); • System.out.println( helloString ); • }} PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 28. PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 29. PROGRAMMING IN JAVA A. SIVASANKARI - SIASC-TVM
  • 30. A. SIVASANKARI - SIASC-TVM