The document discusses basic Java concepts including identifiers, keywords, literals, primitive data types, variables, operators, control flow statements, classes, methods, inheritance, polymorphism, packages and modifiers. It provides definitions and examples of key concepts like classes, objects, methods, inheritance, polymorphism, packages, modifiers, variables and data types. It also lists Java keywords, reserved words and literals.
The document discusses several core Java concepts including:
1) Comments in Java code can be single-line or multiline javadoc comments.
2) Classes are fundamental in Java and describe data objects and methods that can be applied to objects.
3) Variables and methods have scopes determined by curly braces and a variable is only available within its scope.
This document discusses arrays in Java. It defines an array as a fixed-size collection of elements of the same type that can store a collection of data. It describes how arrays allow storing multiple variables of the same type at once. The document covers declaring, constructing, initializing single and multi-dimensional arrays, and gives an example of how arrays can solve the problem of needing to store exam scores for 100 students.
The static keyword in Java is used for memory management and can be applied to variables, methods, blocks, and nested classes. Static variables and methods belong to the class rather than objects. A static variable is loaded when the class is loaded and there is only one copy per class, while instance variables are loaded each time an object is created. The main method must be static since it is called before any objects are created to start the program execution. Static blocks are used to initialize static variables and are executed when the class is loaded.
Constructors in Java are special methods that are used to initialize objects. There are two types of constructors: default (no-arg) constructors that take no parameters, and parameterized constructors that allow passing parameters to initialize an object. Constructors must have the same name as the class and cannot have a return type. They are automatically called when an object is created using the new keyword to allocate memory and initialize fields.
Conditional statements in Java include if-else statements, nested if-else statements, and switch statements. If-else statements execute code based on a boolean condition, while switch statements allow testing multiple conditions. Type conversion in Java includes widening (automatic) conversions between compatible types like int to double, and narrowing (manual) conversions between incompatible types using explicit casting like double to int. Methods like parseInt() allow converting between types like String to int.
This document provides an overview of key Java concepts including identifiers, literals, statements, variables, operators and expressions, references, objects, and classes. It discusses how identifiers are used to name variables, methods, and classes. It describes different types of literals and rules for specifying values. It outlines common Java statement types and syntax. It explains that variables can be primitive types or reference types, and must be declared before use. It covers precedence rules for operators and common expression examples. It distinguishes between object references and objects themselves. And it provides examples of creating objects from classes and accessing object properties through references.
This document summarizes data types in C#, including value types (such as int, float, enumerations, and structs), reference types (such as objects, strings, classes, arrays, and delegates), and how everything inherits from System.Object. It explains that value types directly contain variable data while reference types contain a reference to the data. The document also outlines the hierarchies for value types and reference types.
The document discusses Java methods, including creating and calling methods, passing parameters, overloading methods, and method abstraction. It provides examples of void and non-void methods. Key points covered include defining method headers and bodies, passing arguments by value, variable scope, and using built-in Math class methods like random, min, max, and trigonometric functions.
- Java uses streams to perform input and output operations which allow for fast processing. Streams are sequences of data composed of bytes.
- The main stream classes in Java are InputStream for reading data and OutputStream for writing data. These classes handle byte-oriented input/output.
- FileInputStream and FileOutputStream classes allow reading and writing of data to files by extending InputStream and OutputStream respectively. They are used for file handling operations in Java.
This document discusses object oriented programming concepts in Java including packages, interfaces, and how they relate. It provides details on how to define and use packages to organize classes. Interfaces are introduced as a way to specify common behaviors without defining how they are implemented. The key points covered are how to define interfaces, implement interfaces in classes, access implementations through interface references, allow for partial implementations, and extend interfaces.
Strings in Java are objects of the String class that represent sequences of characters. Strings are immutable, meaning their contents cannot be modified once created. The StringBuffer class represents mutable strings that can be modified by methods like append(), insert(), delete(), and replace(). Some key String methods include length(), charAt(), equals(), concat(), and indexOf(), while common StringBuffer methods allow modifying the string through insertion, deletion, replacement and reversal of characters.
The document provides an overview of key Java concepts including classes, objects, methods, constructors, inheritance, polymorphism, abstraction, and encapsulation. It defines classes like Circle and Shape that demonstrate these concepts. Circles have fields like radius and methods like area() and circumference(). The Shape class is abstract with abstract area() and circumference() methods that concrete subclasses like Circle must implement. Access modifiers like public, private, and protected are used to control access to class members.
The document discusses different types of control statements in Java programming including selection statements (if/else, switch), iteration statements (for, while, do-while), and jump statements (break, continue, return). Examples are provided for each type of statement to illustrate their usage in loops and conditional execution. Selection statements allow a program to choose different paths of execution based on variable values or expressions. Iteration statements allow code to repeat execution. Jump statements allow skipping the rest of the current block and transferring control elsewhere.
This document contains the slides for a presentation on Java 8 Lambdas and Streams. The presentation will cover lambdas, including their concept, syntax, functional interfaces, variable capture, method references, and default methods. It will also cover streams. The slides provide some incomplete definitions that will be completed during the presentation. Questions from attendees are welcome. A quick survey asks about past experience with lambdas and streams.
1. Array is a collection of similar type elements stored in contiguous memory locations. It allows random access to elements and optimized code.
2. There are two types of arrays in Java: single dimensional and multidimensional. Single dimensional arrays store elements in one dimension while multidimensional arrays store elements in two or more dimensions.
3. Strings in Java are objects that represent a sequence of characters. Strings can be created using string literals or the new keyword and various methods are available to manipulate strings.
Tokens are the smallest individual units in a Java program. There are five types of tokens: keywords, identifiers, literals, operators, and separators. Keywords are reserved words that are essential for the Java language syntax. Identifiers are names given to classes, methods, variables and other program elements and have specific naming rules. Literals represent constant values like integers, floats, characters and strings. Operators perform operations on operands. Separators delineate different parts of code like parentheses, braces, brackets and semicolons.
The document provides information about Core Java concepts including:
1. James Gosling initiated the Java language project in 1991 and Sun released the first public implementation as Java 1.0 in 1995 with the promise of "Write Once, Run Anywhere".
2. Oracle acquired Sun Microsystems in 2010 and has worked to build fully integrated systems optimized for performance.
3. The document discusses the differences between C++ and Java and covers Java concepts like objects, classes, methods, variables, data types, identifiers, arrays and the Java Virtual Machine (JVM).
This document discusses various control flow statements in Java including branching statements, looping statements, and jump statements. It provides examples of if, if-else, if-else-if statements, switch statements, for loops, while loops, do-while loops, break, continue, and return statements. Key points include:
- Branching statements like if, if-else, if-else-if are used to control program flow based on boolean conditions. Switch statements provide an alternative for multiple if-else statements.
- Looping statements like for, while, do-while repeat a block of code while/until a condition is met.
- Jump statements like break and continue control flow within loops, while
This document provides an agenda and overview for a Python training course. The agenda covers key Python topics like dictionaries, conditional statements, loops, functions, modules, input/output, error handling, object-oriented programming and more. The introduction section explains that Python is an interpreted, interactive and object-oriented language well-suited for beginners. It also outlines features like rapid development, automatic memory management and support for procedural and object-oriented programming. The document concludes by explaining Python's core data types including numbers, strings, lists, tuples and dictionaries.
Our trainers having vast experience in real time environment. If anyone has a dream for their career in software programming, then go for java because it is a popular route to establish and fulfill your dreams.
We offer the best quality and affordable training, so you get trained from where you are, from our experienced instructors, remotely using Webex / Gotomeeting.
Java Multi Threading Concept
By N.V.Raja Sekhar Reddy
www.technolamp.co.in
Want more...
Like us @ https://www.facebook.com/Technolamp.co.in
subscribe videos @ http://www.youtube.com/user/nvrajasekhar
Class <class name> contains a main method that declares instance variables and calls other methods without creating objects. The main method has a string array as a parameter and does not return a value. Import is used to include packages that contain classes needed for input/output and other operations.
This chapter discusses recursion, including recursive definitions, algorithms, and methods. It covers key concepts like base cases, general cases, and tracing recursive calls. Examples are provided for recursive functions like factorial, finding the largest value in an array, Fibonacci numbers, Towers of Hanoi, and drawing Sierpinski gaskets. Both designing recursive methods and choosing between recursion and iteration are addressed.
This document discusses methods in Java. It defines a method as a collection of instructions that performs a specific task and provides code reusability. There are two types of methods in Java: predefined methods and user-defined methods. Predefined methods are methods already defined in Java class libraries that can be directly called, while user-defined methods are written by programmers according to their needs. Examples of both types of methods are provided.
This document summarizes constructors in Java. Constructors are methods that have the same name as the class and are executed during object creation. Constructors do not have a return type. Constructors are categorized as having no parameters, parameters, or being a default constructor added by the compiler. Constructors without parameters are called with the new keyword, while parameterized constructors pass arguments to the constructor. Default constructors are added by the compiler if no other constructor is defined.
Type casting involves assigning a value of one data type to a variable of another type. There are two types of casting: widening (implicit) and narrowing (explicit). Widening casting converts data to a broader type without needing explicit casting, like converting an int to a long. Narrowing casting converts to a narrower data type and requires explicit casting, such as converting a double to a long.
The document provides an overview of key Java programming concepts including: the features of Java technology; the primary goals and functions of the Java Virtual Machine and garbage collection; how Java source files are compiled and executed; the three main tasks of the JVM; modeling concepts like abstraction and encapsulation; and how to declare classes, methods, and constructors in Java. It also summarizes how packages, imports, and the Java API documentation work.
This document provides an introduction to Java programming, covering topics such as its origins, key features like being simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high-performance, and dynamic. It also discusses how to program in Java, including the Java platform which consists of the Java Virtual Machine and Java Application Programming Interface, and different types of programs like applets, applications, and servlets.
This document summarizes data types in C#, including value types (such as int, float, enumerations, and structs), reference types (such as objects, strings, classes, arrays, and delegates), and how everything inherits from System.Object. It explains that value types directly contain variable data while reference types contain a reference to the data. The document also outlines the hierarchies for value types and reference types.
The document discusses Java methods, including creating and calling methods, passing parameters, overloading methods, and method abstraction. It provides examples of void and non-void methods. Key points covered include defining method headers and bodies, passing arguments by value, variable scope, and using built-in Math class methods like random, min, max, and trigonometric functions.
- Java uses streams to perform input and output operations which allow for fast processing. Streams are sequences of data composed of bytes.
- The main stream classes in Java are InputStream for reading data and OutputStream for writing data. These classes handle byte-oriented input/output.
- FileInputStream and FileOutputStream classes allow reading and writing of data to files by extending InputStream and OutputStream respectively. They are used for file handling operations in Java.
This document discusses object oriented programming concepts in Java including packages, interfaces, and how they relate. It provides details on how to define and use packages to organize classes. Interfaces are introduced as a way to specify common behaviors without defining how they are implemented. The key points covered are how to define interfaces, implement interfaces in classes, access implementations through interface references, allow for partial implementations, and extend interfaces.
Strings in Java are objects of the String class that represent sequences of characters. Strings are immutable, meaning their contents cannot be modified once created. The StringBuffer class represents mutable strings that can be modified by methods like append(), insert(), delete(), and replace(). Some key String methods include length(), charAt(), equals(), concat(), and indexOf(), while common StringBuffer methods allow modifying the string through insertion, deletion, replacement and reversal of characters.
The document provides an overview of key Java concepts including classes, objects, methods, constructors, inheritance, polymorphism, abstraction, and encapsulation. It defines classes like Circle and Shape that demonstrate these concepts. Circles have fields like radius and methods like area() and circumference(). The Shape class is abstract with abstract area() and circumference() methods that concrete subclasses like Circle must implement. Access modifiers like public, private, and protected are used to control access to class members.
The document discusses different types of control statements in Java programming including selection statements (if/else, switch), iteration statements (for, while, do-while), and jump statements (break, continue, return). Examples are provided for each type of statement to illustrate their usage in loops and conditional execution. Selection statements allow a program to choose different paths of execution based on variable values or expressions. Iteration statements allow code to repeat execution. Jump statements allow skipping the rest of the current block and transferring control elsewhere.
This document contains the slides for a presentation on Java 8 Lambdas and Streams. The presentation will cover lambdas, including their concept, syntax, functional interfaces, variable capture, method references, and default methods. It will also cover streams. The slides provide some incomplete definitions that will be completed during the presentation. Questions from attendees are welcome. A quick survey asks about past experience with lambdas and streams.
1. Array is a collection of similar type elements stored in contiguous memory locations. It allows random access to elements and optimized code.
2. There are two types of arrays in Java: single dimensional and multidimensional. Single dimensional arrays store elements in one dimension while multidimensional arrays store elements in two or more dimensions.
3. Strings in Java are objects that represent a sequence of characters. Strings can be created using string literals or the new keyword and various methods are available to manipulate strings.
Tokens are the smallest individual units in a Java program. There are five types of tokens: keywords, identifiers, literals, operators, and separators. Keywords are reserved words that are essential for the Java language syntax. Identifiers are names given to classes, methods, variables and other program elements and have specific naming rules. Literals represent constant values like integers, floats, characters and strings. Operators perform operations on operands. Separators delineate different parts of code like parentheses, braces, brackets and semicolons.
The document provides information about Core Java concepts including:
1. James Gosling initiated the Java language project in 1991 and Sun released the first public implementation as Java 1.0 in 1995 with the promise of "Write Once, Run Anywhere".
2. Oracle acquired Sun Microsystems in 2010 and has worked to build fully integrated systems optimized for performance.
3. The document discusses the differences between C++ and Java and covers Java concepts like objects, classes, methods, variables, data types, identifiers, arrays and the Java Virtual Machine (JVM).
This document discusses various control flow statements in Java including branching statements, looping statements, and jump statements. It provides examples of if, if-else, if-else-if statements, switch statements, for loops, while loops, do-while loops, break, continue, and return statements. Key points include:
- Branching statements like if, if-else, if-else-if are used to control program flow based on boolean conditions. Switch statements provide an alternative for multiple if-else statements.
- Looping statements like for, while, do-while repeat a block of code while/until a condition is met.
- Jump statements like break and continue control flow within loops, while
This document provides an agenda and overview for a Python training course. The agenda covers key Python topics like dictionaries, conditional statements, loops, functions, modules, input/output, error handling, object-oriented programming and more. The introduction section explains that Python is an interpreted, interactive and object-oriented language well-suited for beginners. It also outlines features like rapid development, automatic memory management and support for procedural and object-oriented programming. The document concludes by explaining Python's core data types including numbers, strings, lists, tuples and dictionaries.
Our trainers having vast experience in real time environment. If anyone has a dream for their career in software programming, then go for java because it is a popular route to establish and fulfill your dreams.
We offer the best quality and affordable training, so you get trained from where you are, from our experienced instructors, remotely using Webex / Gotomeeting.
Java Multi Threading Concept
By N.V.Raja Sekhar Reddy
www.technolamp.co.in
Want more...
Like us @ https://www.facebook.com/Technolamp.co.in
subscribe videos @ http://www.youtube.com/user/nvrajasekhar
Class <class name> contains a main method that declares instance variables and calls other methods without creating objects. The main method has a string array as a parameter and does not return a value. Import is used to include packages that contain classes needed for input/output and other operations.
This chapter discusses recursion, including recursive definitions, algorithms, and methods. It covers key concepts like base cases, general cases, and tracing recursive calls. Examples are provided for recursive functions like factorial, finding the largest value in an array, Fibonacci numbers, Towers of Hanoi, and drawing Sierpinski gaskets. Both designing recursive methods and choosing between recursion and iteration are addressed.
This document discusses methods in Java. It defines a method as a collection of instructions that performs a specific task and provides code reusability. There are two types of methods in Java: predefined methods and user-defined methods. Predefined methods are methods already defined in Java class libraries that can be directly called, while user-defined methods are written by programmers according to their needs. Examples of both types of methods are provided.
This document summarizes constructors in Java. Constructors are methods that have the same name as the class and are executed during object creation. Constructors do not have a return type. Constructors are categorized as having no parameters, parameters, or being a default constructor added by the compiler. Constructors without parameters are called with the new keyword, while parameterized constructors pass arguments to the constructor. Default constructors are added by the compiler if no other constructor is defined.
Type casting involves assigning a value of one data type to a variable of another type. There are two types of casting: widening (implicit) and narrowing (explicit). Widening casting converts data to a broader type without needing explicit casting, like converting an int to a long. Narrowing casting converts to a narrower data type and requires explicit casting, such as converting a double to a long.
The document provides an overview of key Java programming concepts including: the features of Java technology; the primary goals and functions of the Java Virtual Machine and garbage collection; how Java source files are compiled and executed; the three main tasks of the JVM; modeling concepts like abstraction and encapsulation; and how to declare classes, methods, and constructors in Java. It also summarizes how packages, imports, and the Java API documentation work.
This document provides an introduction to Java programming, covering topics such as its origins, key features like being simple, object-oriented, distributed, interpreted, robust, secure, architecture-neutral, portable, high-performance, and dynamic. It also discusses how to program in Java, including the Java platform which consists of the Java Virtual Machine and Java Application Programming Interface, and different types of programs like applets, applications, and servlets.
This document provides an introduction to the Java programming language. It describes how Java was created in 1991 at Sun Microsystems to be platform-independent. The key features of Java include being distributed, simple, multithreaded, object-oriented, secure, portable, and robust. It then discusses the major versions of Java and provides a simple example Java program to demonstrate how a program is written, compiled, and executed.
The document introduces Jena, a Java framework for building Semantic Web applications. It discusses key Semantic Web technologies like RDF, RDFS, OWL and SPARQL. It also provides an overview of Jena's features for manipulating RDF graphs and querying them using SPARQL. Examples are given of how to use Jena's RDF and SPARQL APIs.
Intuit Commissions Manager is a web application that integrates with QuickBooks to help businesses easily manage commissions for sales reps. It allows users to view invoices, apply commissions at the invoice or line item level, track commissions payable and paid, and provides sales reps with view-only access to their commission details. The tool is designed to save time over manual processes by automating commission calculations and record keeping.
Chapter 1. java programming language overviewJong Soon Bok
油
This document provides an overview of the Java programming language and environment. It discusses what Java is, its uses as both a programming language and platform, and the key components of the Java platform including the JRE and JDK. It also covers downloading and installing the JDK, configuring the environment, and creating a simple "Hello World" Java program. The document includes many screenshots to illustrate the various steps and configurations.
This document provides an overview of Module 02 - Basic Java Programming which covers basic Java programming concepts such as variables, data types, operators, classes, objects, and methods. It also discusses compiling and running Java applications from the command line and with an IDE. Hands-on labs are included to build a simple Java application with JDeveloper IDE, create a JAR file, and use JConsole to monitor a Java application.
The document discusses object-oriented programming concepts like classes, objects, inheritance, encapsulation, and composition. It provides examples of how these concepts can be implemented in Java. It explains that a class defines common attributes and behaviors of objects, while an object is an instance of a class. Inheritance allows classes to extend and override methods of parent classes. Encapsulation involves making attributes private and accessing them via getter/setter methods. Composition refers to objects having other objects as members.
The document discusses various Java programming concepts including comments, identifiers, keywords, primitive data types, variables, objects, and access modifiers. It provides examples and definitions for each concept. The key points covered are the eight primitive data types in Java (boolean, char, byte, short, int, long, float, double), how to declare and initialize variables, how to construct objects using the new keyword, and the differences between public, private, protected, default, final, and abstract access modifiers.
The document outlines an agenda for learning core Java concepts over 15 sections. It introduces key Java topics like primitive data types, variables, arrays, control flow statements, classes and objects, inheritance, polymorphism, exceptions, strings and characters, files and streams, and generic collections. The agenda also covers defining classes and methods, passing arguments, encapsulation, and memory concepts like objects, references, and the heap.
This document provides an overview of key concepts in Java programming including:
1) The components of a Java program such as statements, blocks, classes, and methods.
2) How to structure Java source code files with classes and the main method.
3) Common elements in Java programs like variables, data types, operators, and comments.
4) Details on specific concepts like declaring and initializing variables, arithmetic operators, and increment/decrement operators.
The document discusses key concepts in Java including classes, objects, methods, and command line arguments. A class defines common properties and behaviors for objects through fields and methods. Objects are instantiated from classes and can access fields and methods using dot notation. Command line arguments allow passing data into a Java application and are accessed through the args parameter in the main method.
This document discusses primitive data types, variables, classes, methods, constructors, and interfaces in Java. It provides details on the different primitive data types including their sizes and ranges. It describes how variables store values of a particular type. It outlines the syntax for class declarations including fields, methods, and constructors. It also covers method overloading, overriding, and parameter passing. Finally, it summarizes interfaces and how they define requirements for classes to implement.
This document provides an overview of advanced Java programming concepts covered in the unit, including object-oriented programming, data types, variables, arrays, operators, inheritance, and control statements. It defines key concepts like classes, objects, encapsulation, polymorphism, and inheritance. For data types, it covers primitive types like int, float, boolean and char, as well as arrays. Operators covered include unary, arithmetic, relational, logical, and assignment operators. The document also discusses variables, arrays, and control statements like selection, iteration, and jump statements.
The document provides an overview of key concepts in the Java programming language including:
1. Java language fundamentals including building blocks like identifiers, literals, variables, and wrapper classes. Different types of literals like integral, floating point, character, string and boolean are described.
2. Control structures in Java including selection statements like if-else and switch statements, and iterative statements like while, do-while and for loops. Jump statements like break, continue and return are also covered.
3. Other concepts discussed include arrays, declaring and initializing array variables, and creating arrays using the new operator in Java.
Data types ^J variables and arrays in Java.pptxsksumayasumaya5
油
Build your presentation Structure Importantly, before you start creating your data charts, you should plan your presentation structure. This will ensure your presentation answers the right questions. Here is a template that we would use at Accenture to create a presentation. You need to download this template and populate slides 2-6.
For each slide, think about: Agenda - What will your presentation cover? Project Recap - What are the key points from the brief? Problem - What is the problem that you answer in this presentation? The Analytics team - Who is on your team? As a reminder from the earlier task - this includes: Andrew Fleming (Chief Technical Architect), Marcus Rompton (Senior Principle), and yourself! Process - How did you complete your analysis?
Once youve populated slides 2-6 - complete the quick knowledge check to move onto the next step.
In the next step, well review what youve included before we start charting
This document provides an overview of the Java programming language, including its structure, keywords, data types, variables, operators, expressions, statements, and control flow structures. It discusses the structure of Java programs, including classes, packages, and the main method. It also covers Java APIs, documentation, errors, and examples of basic Java programs.
This document provides an overview of key concepts in Java programming including:
- Comments can be added using //, /* */, or /** */.
- Java has primitive data types like int, double, boolean and reference types like String.
- Variables are declared with a type and initialized through assignment.
- Operators perform tasks like arithmetic, comparison, and assignment.
- Control flow is managed through conditionals like if/else and loops like for.
- Arrays store multiple values of the same type and can be one or multi-dimensional.
The document discusses key concepts in C# programming including data types, operators, control flow statements, methods, classes, and arrays. It provides examples and descriptions of common language elements like namespaces, classes, methods, variables, operators, loops, and conditional statements. Type conversion methods and how to accept user input and initialize arrays are also summarized.
The document discusses key concepts in C# programming including data types, operators, control flow statements, methods, classes, arrays, and more. It provides definitions and examples of common terms like namespaces, classes, methods, operators, loops, and exceptions. Type conversion methods in C# are also summarized in a table listing common conversion functions.
Presented By:
N.V.Raja Sekhar Reddy
www.technolamp.co.in
Want more interesting...
Watch and Like us @ https://www.facebook.com/Technolamp.co.in
subscribe videos @ http://www.youtube.com/user/nvrajasekhar
Full CSE 310 Unit 1 PPT.pptx for java languagessuser2963071
油
This document discusses Java programming fundamentals including naming conventions, data types, literals, and writing a basic Java program. It covers lowercase and uppercase naming rules for variables, methods, and classes. It also describes numeric, boolean, character, and string literals. Key data types like int, float, char, and their ranges are explained. The document provides examples of type conversion, casting, and type promotion in expressions. It concludes with steps for compiling and running a Java program.
Chapter 01 Introduction to Java by Tushar B KuteTushar B Kute
油
The lecture was condcuted by Tushar B Kute at YCMOU, Nashik through VLC orgnanized by MSBTE. The contents can be found in book "Core Java Programming - A Practical Approach' by Laxmi Publications.
2. Basic Language Elements
Identifiers, Keywords, Literals, White Spaces and Comments
Identifiers
A name in a program is called an identifier.
An identifier in java is composed of a sequence of characters, where
each character can be either a letter or digit or connecting symbol($,_).
The first character in an identifier cant be a digit.
Identifiers in java are case sensitive.
Keywords
Key words are reserved identifiers.
In java, all keywords are in lower case.
Literals
A literal denotes a constant value of a particular data type, the value a
literal represents remains unchanged in the program.
3. Primitive Data Types
DataType Bit Depth
1. boolean jvm specific
2. byte 8 bits
3. short 16 bits
4. int 32 bits
5. long 64 bits
6. char 16 bits
7. float 32 bits
8. double 64 bits
All numeric data types except char are
signed data types.
The default data type of an integer
(byte, short, int, long) literal is always
int.
long can be specified by appending L
or l as a suffix.Theres no way to
represent a byte or short literal.
The dafault data type of floating point
literal is double.
float can be specified by appending F
or f as a suffix.
4. Javas Keywords
boolean byte char short int long float double
public private protected abstract static final native synchronized
transient volatile strictfp if else do while for
switch case default break continue assert class interface
extends implements import package new instanceof super this
try catch finally throw throws void return enum
Javas Reserved words
const goto
Javas reserved Literals
true false null
丱Java doesnt allow us to use any of the above as an identifier.
Q] /* // */ is it legal ?
Q] which of the following are keywords in java ?
a) instaceof b) object c) void d) main e) String f) enum g) null h) thrown
i)finalize j) native
5. Java Source file structure
損 An optional package declaration
損 Zero or more import declarations
損 Any no.of top level classes and interface declarations
At the most one public class definition per source class can be defined.
If a public class is defined, the file name must match this class name.
Except for package and import statements, all code is encapsulated in
classes and interfaces.
like any other method, the main method can also be overloaded and
overrided.
Q] which of the following are valid main() method declarations in order to
start the execution of java application ?
a) Public static void main(String args) throws Exception
b) static public void main(String[] args)
c) final public static void main(String args[])
6. Class (a user defined data type)
class is a logical construct upon which the entire java language is built.
Objects are basic run time entities in java. class acts as a blue print for
similar type of objects.
when you design a class, think about the objects that will be created from
that class, think about
1. Things the object knows (state)
2. Things the object does (behavior)
Alarm
alarmTime
setAlarmTime()
getAlarmTime()
isAlarmSet()
Things an object knows itself are called
instance variables.
Things an object can do are called
methods.
classes give modularity in java.
7. [class modifiers] class <class name> [extends clause] [implements clause]
{
[variable declarations]
[method declarations]
[constructor declarations]
[initializer blocks]
[nested class declarations]
[nested interface declarations]
}
class Syntax
8. Java Variables
A variable stores a value of a particular type.
in java variables come in two flavors
1. primitive
2. reference
Variables that store references to objects are called reference variables.
java has three types of variables
1. instance variables
2. static variables
3. local variables
9. Instance variables
損 Every object of the class will have its own copies of these variables, which
are local to object
損 The values of these variables at any given time constitute the state of the
object
損 Instance variables exist as long as object they belong to exist
Static variables
損 Belong only to the class, but not created for only object of the class
損 All objects of the class share the same copy of this variable
損 Class variables exist as long as class exist
Local Variables
損 Variables declared in methods including parameters or blocks are called
Local variables
損 After execution of the method or block completes local variables are no
longer accessible
10. Local variables must be explicitly initialized before being used.
The compiler will report attempt to use un initialized local variables.
if no initialization is provided for static or instance variable they
are initialized by default value of their type.
Default values of static/instance variables
Data Type Default Value
boolean false
char u0000
int or short or byte 0
long 0L
float 0.0f
double 0.0
reference types null
11. Java operators
() [] .
++ -- ~ !
* / %
+ -
<< >> >>>
>= < <=
== !=
&
^
|
&&
||
?:
= op=
Precedence table
Precedence rules are used to determine which
operator should be applied first if there are two
operators with different precedence.
The associative rules are used to determine
which operator should be applied first if there are
more than one operand with the same precedence.
the precedence and associative rules together
determine the evolution order of operators in an
expression.
All binary operators, except for the assignment
operator associate from left to right
Except for unary postfix increment and
decrement operators, all unary operators, all
assignment operator and ternary conditional
operator associate from right to left.
12. new operator is used to create objects and declare array
sizes.
instanceof operator is used to test an objects type.
<source reference type> instanceof <destination type>
Q] int x=3;
x<<4;
s.o.p(x);
Q] int i=--4*2--;
s.o.p(i);
13. Type Conversions
Java being a strongly typed language , checks for compatibility at compile
time. How ever some checks are only possible at runtime.
Java demands that a cast be used to explicitly indicate the
type conversion (narrowing or downcasting)
(<type>) expression;
Casting the value of a super class reference to a subclass type is
downcasting and the reverse is called upcasting.
Casting between primitive types and reference types is not possible
Boolean values cant be cast to other data types and vice versa
Widening and upcasting are implicit conversions
Narrowing typically requires explicit casting.
widening
byte short char int long float double
14. Numeric promotions
Numeric promotion is implicitly applied on the operands to convert them
to permissible types.
Unary numeric promotion
if the single operand of the operator has a type narrower than int, it is
converted to int by an implicit widening primitive conversion;
Binary numeric promotion
Given T to be the broadest numeric type of two operands the operands are
promoted as follows
If( T is broader than int)
both operands are converted to T
else
both operands are converted to int
15. Implicit narrowing conversions
implicit narrowing conversions on assignment can occur in cases where all
of the following conditions are full filled
1. The source is a constant expression of either byte, short, char, or int type
2. The destination type is either byte, short or char type
3. The value of the source is determined to be in the range of the destination
type at compile time
Type conversion contexts
Assignments
Method invocation involving parameters
Arithmetic expression involving numeric types
String Concatenation involving String objects and other data types
Q] byte b=17;
b=b+2; //illegal
b+=2; //legal
16. Arrays
In java, arrays are objects
Array declaration
<element type>[] <array name>
(or)
<element type> <array name>[]
<array name> =new <element type>[size];
when the array is constructed, all its elements are initialized to the default
value of their element type. This is true for both members and local arrays.
Java supports declaring , constructing, and explicitly initializing an array
in one stmt.
eg: int[] a={4,3,78,3};
Anonymous array
new <element type>[] {array list}
eg:new int[] {4,7,3,8,9};
Multi dimensional arrays
17. Method
[method modifiers] <return type> <method name> ([formal parameters]) [throws
clause]
{
[local variable declarations]
[statements]
[nested class declarations]
}
Parameter passing
The parameter strategy in java is pass-by-value regardless of the type of
the parameter.
The order of the evolution in actual parameter list is always from left to
right.
if the actual parameter is a reference to an object then the reference value is
passed and not the object itself.
18. Method Over Loading
Several methods may have the same name, as long as the method
signatures differ.
For the over loading method,
The arguments list must be different
The return types can be different
You can vary access levels in any direction
<Theres no polymorphism with over loading methods>
19. Method Overriding
For the overriding method ,
Signature must be same as original method.
Return type must be compatible with original method return type
The new method definition cant narrow the accessibility
The new method definition can only specify all or none or a subset of
exception classes in the throws clause.
An instance method in a sub class cant override a static method in the
super class and vice versa.
We cant override static methods rather we can hide them
20. Interfaces
[access modifier] interface <interface name> <extends interface clause>
{
[constant declarations]
[method prototype declarations]
}
The methods in an interface are implicitly abstract and public and the
constants are implicitly public, static and final.
An interface can extend other interfaces
An interface which has no methods to implement is known as Marker or
tag or ability interface.
21. Inheritance
It allows new classes to be derived from existing classes. And it is the
main thing in Java for code reuse.
private members of a class are not inherited and also members that have a
package accessibility in the super class are also not inherited by sub classes
in other packages.
Since constructors and initializer blocks are not members of a class they
are not inherited by a sub class.
To avoid D3(Deadly Diamond of Death) problem java doesnt support
multiple inheritance. So a class in java can extend at most one other class.
java gives multiple interface inheritance through interfaces. So a class can
implement many interfaces.
Any class that doesnt explicitly extend another class, implicitly extends
<Object> class.
So any class in java, either directly or indirectly extends Object class.
22. classes up the inheritance hierarchy are more generalized and classes down
the hierarchy are more specialized.
Inheritance defines the is-a relationship between a super class and its sub
class. This means that an object of a sub class can be used where ever an
object of the super class can be used.
It is not possible for two classes to be the super classes of each other
If A extends B then A is-a B
Aggregation
Aggregation defines has-a relationship between objects.
If A has a reference to B then A has-a B
23. Polymorphism
The ability of a super class or super type reference to denote objects of its
own class and its sub classes at runtime is called polymorphism.
polymorphism is achieved through inheritance and interface
implementation
The instance method invocation is dependent on the type of the actual
object denoted by the reference at runtime.
Field access and static method access is determined by the reference
type not by the actual object.
you can call a method on an object only if the class of the reference
variable has that method.
24. Static Block
static
{
//code
}
The code in a static block is executed once only when the class is loaded .
These are primarily used for initializing static fields.
Static block is not contained in any method
A class can have more than one static block. In this case the blocks are
executed in the order of their declarations in the class.
25. Instance Block
{
//code
}
The code in an instance block is executed every time an object is created.
Instance block is not contained in any method
A class can have more than one instance block. In this the blocks are
executed in the order of their declarations in the class.
An instance initializer block can be used to factor out common
initialization code that will be executed regardless of which constructor is
invoked.
26. Control Flow stmts
Control flow statements govern the flow of control in a program during
execution.
There are three categories of control flow stmts
1. Selection stmts [if, if-else, switch]
2. Iteration stmts [for, while, do-while]
3. Transfer stmts [break, continue, return, throw, try-catch-flow and
assert]
27. Packages
A package in java is an encapsulation mechanism that can be used to group
related classes, interfaces and sub packages.
package <fully qualified package name>
At most one package declaration can appear in a source file, and it must
be the first statement.
The package name is saved in java byte code for the types contained in
the package.
If a package stmt is omitted in a source file, then respective class files
are placed in a unnamed package (current working directory)
packages prevent class name conflicts.
(java convention) preface your packages with your reverse domain name
to prevent package name conflicts.
To put your class in package, The package hierarchy must match the
directory structure
28. Using packages,
we can use the existing package in two ways
1. Using the fully qualified name of the type.
2. Using import declarations.
Import
import <fully qualified name> // single type import
import <fully qualified name>.* //import on demand
An import declaration doesnt recursively import sub packages.
29. Modifiers
1. Access modifiers
public
protected
no modifier (package access)
private
2. static
3. final
4. abstract
5. synchronized
6. native
7. transient
8. volatile
9. threadsafe
30. Top level classes and
interfaces
public, no modifier
abstract and final
Inner classes All Access modifiers
abstract, static and final
Fields All access modifiers
static, final, transient and volatile
Methods All access modifiers
abstract, static, final, synchronized and native
Member Type Possible modifiers
31. Modifier Class Package Sub class
(out side
package)
World
public Y Y Y Y
protected Y Y Y N
default Y Y N N
private Y N N N
Access modifiers
Use most restrictive access level that makes sense for a particular
member.
Avoid public fields accept for constants
public fields limit your flexibility in changing your code.
32. Abstract method
An abstract method has no implementation (no body) it just specifies
method prototype
You cant have an abstract method in a non abstract class
If you put even a single abstract method in a class, you have to make the
class abstract.
Only an instance method can be declared as abstract (we cant override a
static method)
A final method cant be abstract
33. Abstract class
Abstract class means, The class which is partially implemented
We cant instantiate an abstract class. We can still use the abstract type as
a reference type, for the purpose of polymorphism
If you put even a single abstract method in a class you have to make the
class abstract.
Even if there are no abstract methods you can declare class as abstract
just make it as a non concrete class.
You can mix both abstract and non-abstract methods in an abstract class.
The sub class which extends abstract class must implement all the
abstract methods or declare it also as abstract.
34. static
Static members belong to the class in which they are declared.
We can access static members through class name or through object
reference of that class.
We cant access non-static members in static context.
Static context =>static initializer expression
static initializer blocks
static methods
static inner classes
Object neednt be instantiated to access its static members.
Only inner classes can be declared as static
static variables are not part of a object state
we cant override static methods in sub classes, rather we can hide them
35. Final variable
A final variable of primitive data type cant change its value
once it has been initialized
A final variable of a reference type cant change its reference
value once it has been initialized but the state of the object it
denotes can still be changed.
Applicable to instance, static, and local variables.
Blank finals
Final method
We cant override a final method in sub classes.
Final class
A Final class cant be extended
only a class whose definition is complete can be declared final.
36. Make a class that doesnt extends any thing when your new classes
doesnt passes is-a test for any other type.
Make a sub class only when you need to make a more specific version
of a class and need to override or add new behavior
Use an abstract class when you want to define a template for a group
classes and at least you have some implementation that all classes could
use.
Use an interface when you want to define a role that other classes can
play regardless of where those classes are in the inheritance tree.
37. This was my first KT.
Given in honing solutions in 2006.