OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
OOPS and its application in Java, Super class AND This Keyword,Java Bean, POJO ,Memory management in Java ,Packages ,Miscellaneous (Var-Args, toString(), Double equals operator(==))
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Sagar Verma
Collection Framework in Java,Generics,Input-Output in Java,Serialization,Inner Classes
Collection Framework in Java
The Collections Framework - Set Interface- List Interface - Map Interface - Queue Interface -Sorting collections using utility methods
equals () and hash Code contract in Java collections
Overriding equals and hash Code methods in Java
Generics
Generics for Collections, class and methods
Input-Output in Java
What is a stream? ,Bytes vs. Characters, Java IO API ,Reading a file; writing to a file using various APIs
Reading User input from console , PrintWriter Class
Serialization
Object Serialization , Serializable Interface , De-Serializable
Inner Classes
Inner Classes ,Member Classes, Local Classes, Anonymous Classes, Static Nested Classes
Core Java Programming | Data Type | operator | java Control Flow| Class 2Sagar Verma
This document provides an introduction to Java programming concepts including:
- Data types like primitives, classes, and objects
- Variables, identifiers, and naming conventions
- Control structures like if/else statements and loops
- Arrays and array initialization
- Methods and built-in classes
- Import statements and packages
- Output with System.out.println
It covers these concepts over multiple pages with examples and explanations of Java syntax and semantics.
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Sagar Verma
16. Threads in Java
Non-Threaded Applications
Threaded Applications
Process based multitasking Vs Thread based multitasking
Thread API in Java
Creating Threads
States of a Thread
Synchronization for threads; static and non-static synchronized methods; blocks; concept of object and class locks
Coordination between threads - wait, notify and notifyAll methods for inter-thread communication
17. Applets
What are applets?
Need for Applets
Different ways of running an applet program
Applet API hierarchy
Life Cycle of an applet
Even Handlers for applets, mouse events, click events
18. Swing GUI
Introduction to AWT
Introduction to Swing GUI
Advantages of Swing over AWT
Swing API
Swing GUI Components
Event Handlers for Swing
Sample Calculator application using Swing GUI and Swing Event handling
19. JDBC
What is JDBC; introduction
JDBC features
JDBC Drivers
Setting up a database and creating a schema
Writing JDBC code to connect to DB
CRUD Operations with JDBC
Statement types in JDBC
Types of Rowset, ResultSet in JDBC
20. Access Modifiers in Java
What are access modifiers?
Default
Protected
Private
Public
The document discusses key concepts of object-oriented programming including objects, classes, inheritance, polymorphism, encapsulation, and abstraction. It provides examples of constructors, method overloading and overriding, interfaces, and packages in Java.
This document discusses Java packages and access control. It defines packages as namespaces that group related classes, and describes how to declare packages and import other packages. It then covers the four access modifiers in Java (public, protected, no modifier, private) and their effects on class, package, subclass and other package access. Code examples are provided to demonstrate how to define packages and use different access modifiers to control visibility and accessibility of classes, variables and methods in Java.
This document provides an overview of object-oriented programming concepts in Java, including classes, objects, variables, methods, constructors, abstraction, encapsulation, inheritance, and polymorphism. It defines classes and objects, and describes how classes act as blueprints for objects. It explains the syntax for defining classes and class members like variables and methods. It also covers method overloading, different types of methods, and how constructors are used to initialize objects. The document concludes with brief explanations of abstraction, encapsulation, inheritance, and polymorphism as fundamental principles of object-oriented design.
The document discusses the static keyword in Java and its uses for variables, methods, blocks and nested classes. It explains that static members belong to the class rather than instances, and provides examples of static variables, methods, blocks and how they work. Key points include static variables having only one copy in memory and being shared across instances, static methods that can be called without an instance, and static blocks that initialize static fields when the class loads.
This document provides an overview of key concepts in Java including classes, objects, class members, packages, constructors, interfaces, abstract classes, object-oriented programming characteristics like encapsulation, inheritance, polymorphism and abstraction. It also discusses overriding, overloading, non-access modifiers, passing variables and strings. The presentation contains definitions and examples to explain each concept in 1-3 sentences.
This document provides an overview of object-oriented programming concepts in Java. It discusses the differences between procedural and object-oriented programming, with OOP comprising objects that communicate with each other. The main OOP concepts covered are objects, classes, inheritance, and encapsulation. Objects have an identity, attributes, and services. Inheritance allows subclasses to inherit and extend superclass attributes and behaviors. Encapsulation separates an object's internal state from its external interface. The document also discusses other Java topics like interfaces, collections framework, exceptions, and final keywords.
Object Oriented Programming (OOP) allows developers to organize complex programs using classes and objects. OOP uses concepts like encapsulation, inheritance and polymorphism to keep data and functionality together in objects. The basic building blocks in OOP are classes, which define the properties and methods of an object, and objects, which are instances of classes. Classes can inherit properties and methods from parent classes, and objects can be identified and compared using operators like instanceof. Magic methods allow objects to override default behavior for operations like property access, method calling and object destruction.
The document discusses the final keyword in Java and provides examples of using final with variables, methods, and classes. It then summarizes abstract classes and interfaces in Java, including how to declare abstract classes and methods and how interfaces are used to achieve abstraction and multiple inheritance. The document also covers packages, access modifiers, encapsulation, and arrays in Java.
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.
This document introduces Java programming concepts including object-oriented programming, primitive data types, control structures, predefined classes like Math and String, writing and documenting classes, and summarizing key characteristics of Java like being platform independent. It also covers topics like processing Java code, defining and using classes and objects, arrays, input/output streams, and more.
OOPS Concepts, Java Evolution, Class Object basic, Class Object Constructor overloading, Inheritance, Array and String, Final Abstract class and interfaces, Exceptions, Streams, GUI Applications, Applet Programming, Network Programming and Java Sockets, Multi Threading
This document provides information about various concepts related to classes in C++, including defining a class, creating objects, special member functions like constructors and destructors, implementing class methods, accessing class members, and class abstraction. It defines a Circle class with private data member radius and public member functions to set and get radius and calculate diameter, area, and circumference. It demonstrates defining member functions inside and outside the class and using operators like dot and arrow to access class members.
The document provides an introduction to object-oriented programming concepts in Java, including objects, classes, encapsulation, inheritance, polymorphism, and constructors. It defines key OOPs concepts such as a class acting as a blueprint for an object. Features like data hiding, abstraction, encapsulation, and different types of inheritance relationships are explained. The differences between method overloading and overriding are highlighted. Default and parameterized constructors are demonstrated with examples.
This document discusses classes and objects in Java, including:
- Classes should implement object models and reflect real-world objects.
- Constructors prepare objects for use and finalizers perform cleanup before objects are discarded.
- Reference objects and the garbage collector determine how reachable objects are.
- Cloning objects allows copying but a deep copy duplicates contained objects.
- The Reflection API supports introspection to access class information at runtime.
- Nested and inner classes can be defined inside other classes.
The static keyword in Java is used for memory management. It allows variables and methods to belong to the class rather than instances of the class. Static variables and methods are associated with the class, not objects, so they can be accessed without creating an object of the class. Static variables only have one copy in memory and static methods can access static variables and change their values without creating an object. Examples demonstrate how to declare static variables and methods and how they differ from non-static variables and methods.
This document provides an overview of object-oriented programming (OOP) concepts in Java. It defines OOP as a style of programming that focuses on using objects to design and build applications. It describes what objects are, how they model real-world things, and how they use variables to store state and methods to define behavior. It then defines key OOP concepts like classes, objects, abstraction, encapsulation, polymorphism, method overriding, inheritance, and interfaces. For each concept, it provides a definition and example in Java code. The document is intended to help the reader learn more about these fundamental OOP concepts in Java.
This document discusses object-oriented programming concepts in Java including classes, objects, inheritance, encapsulation, and interfaces. It defines key terms like class, object, inheritance, and encapsulation. It explains that a class acts as a template that defines common attributes and behaviors of objects. Inheritance allows subclasses to extend and specialize the behaviors of parent classes. Encapsulation separates an object's internal state from its external interface. The document also covers other concepts like polymorphism, abstraction, and interfaces.
This presentation is ideal for a beginner of Java or someone who wants to brush up their Java Knowledge. It's simple to understand and well organized in a way most of the area in core Java has been covered.
The document provides an overview of lecture 03 on objects and classes in Java, including reviewing basic concepts, declaring and using classes, implementing inheritance, and discussing abstract classes and interfaces. It also includes examples of declaring classes, using constructors and methods, and implementing inheritance and polymorphism. The lecture aims to help students understand object-oriented concepts in Java like classes, objects, inheritance and polymorphism.
Java , basics of java programming, JVM, JRE, JDK detailed explanation. primitive datatype. this ppt explains the basic concepts of java clearly starting from variables to complex programmes. It has 55 slides which gives you better understanding
BCA, Department of Information Technology and Software Development teaches JAVA Language in the fourth semester. The curriculum of the BCA Course of JIMS is very well updated. In this PDF, the Constructor topic is explained. It is one of the very important Concepts and you need to understand it thoroughly.
The document provides examples of various Java programming concepts like displaying messages, using control structures like if-else, for loops, methods, constructors, access specifiers, static variables and more. It shows how to write simple Java programs to print messages, integers, use conditional and looping statements. It also explains concepts like default and parameterized constructors, static and non-static methods, different access specifiers and their usage. The examples help learn how different Java features can be used to develop programs with classes, objects and methods.
This document provides an overview of key concepts in Java including classes, objects, class members, packages, constructors, interfaces, abstract classes, object-oriented programming characteristics like encapsulation, inheritance, polymorphism and abstraction. It also discusses overriding, overloading, non-access modifiers, passing variables and strings. The presentation contains definitions and examples to explain each concept in 1-3 sentences.
This document provides an overview of object-oriented programming concepts in Java. It discusses the differences between procedural and object-oriented programming, with OOP comprising objects that communicate with each other. The main OOP concepts covered are objects, classes, inheritance, and encapsulation. Objects have an identity, attributes, and services. Inheritance allows subclasses to inherit and extend superclass attributes and behaviors. Encapsulation separates an object's internal state from its external interface. The document also discusses other Java topics like interfaces, collections framework, exceptions, and final keywords.
Object Oriented Programming (OOP) allows developers to organize complex programs using classes and objects. OOP uses concepts like encapsulation, inheritance and polymorphism to keep data and functionality together in objects. The basic building blocks in OOP are classes, which define the properties and methods of an object, and objects, which are instances of classes. Classes can inherit properties and methods from parent classes, and objects can be identified and compared using operators like instanceof. Magic methods allow objects to override default behavior for operations like property access, method calling and object destruction.
The document discusses the final keyword in Java and provides examples of using final with variables, methods, and classes. It then summarizes abstract classes and interfaces in Java, including how to declare abstract classes and methods and how interfaces are used to achieve abstraction and multiple inheritance. The document also covers packages, access modifiers, encapsulation, and arrays in Java.
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.
This document introduces Java programming concepts including object-oriented programming, primitive data types, control structures, predefined classes like Math and String, writing and documenting classes, and summarizing key characteristics of Java like being platform independent. It also covers topics like processing Java code, defining and using classes and objects, arrays, input/output streams, and more.
OOPS Concepts, Java Evolution, Class Object basic, Class Object Constructor overloading, Inheritance, Array and String, Final Abstract class and interfaces, Exceptions, Streams, GUI Applications, Applet Programming, Network Programming and Java Sockets, Multi Threading
This document provides information about various concepts related to classes in C++, including defining a class, creating objects, special member functions like constructors and destructors, implementing class methods, accessing class members, and class abstraction. It defines a Circle class with private data member radius and public member functions to set and get radius and calculate diameter, area, and circumference. It demonstrates defining member functions inside and outside the class and using operators like dot and arrow to access class members.
The document provides an introduction to object-oriented programming concepts in Java, including objects, classes, encapsulation, inheritance, polymorphism, and constructors. It defines key OOPs concepts such as a class acting as a blueprint for an object. Features like data hiding, abstraction, encapsulation, and different types of inheritance relationships are explained. The differences between method overloading and overriding are highlighted. Default and parameterized constructors are demonstrated with examples.
This document discusses classes and objects in Java, including:
- Classes should implement object models and reflect real-world objects.
- Constructors prepare objects for use and finalizers perform cleanup before objects are discarded.
- Reference objects and the garbage collector determine how reachable objects are.
- Cloning objects allows copying but a deep copy duplicates contained objects.
- The Reflection API supports introspection to access class information at runtime.
- Nested and inner classes can be defined inside other classes.
The static keyword in Java is used for memory management. It allows variables and methods to belong to the class rather than instances of the class. Static variables and methods are associated with the class, not objects, so they can be accessed without creating an object of the class. Static variables only have one copy in memory and static methods can access static variables and change their values without creating an object. Examples demonstrate how to declare static variables and methods and how they differ from non-static variables and methods.
This document provides an overview of object-oriented programming (OOP) concepts in Java. It defines OOP as a style of programming that focuses on using objects to design and build applications. It describes what objects are, how they model real-world things, and how they use variables to store state and methods to define behavior. It then defines key OOP concepts like classes, objects, abstraction, encapsulation, polymorphism, method overriding, inheritance, and interfaces. For each concept, it provides a definition and example in Java code. The document is intended to help the reader learn more about these fundamental OOP concepts in Java.
This document discusses object-oriented programming concepts in Java including classes, objects, inheritance, encapsulation, and interfaces. It defines key terms like class, object, inheritance, and encapsulation. It explains that a class acts as a template that defines common attributes and behaviors of objects. Inheritance allows subclasses to extend and specialize the behaviors of parent classes. Encapsulation separates an object's internal state from its external interface. The document also covers other concepts like polymorphism, abstraction, and interfaces.
This presentation is ideal for a beginner of Java or someone who wants to brush up their Java Knowledge. It's simple to understand and well organized in a way most of the area in core Java has been covered.
The document provides an overview of lecture 03 on objects and classes in Java, including reviewing basic concepts, declaring and using classes, implementing inheritance, and discussing abstract classes and interfaces. It also includes examples of declaring classes, using constructors and methods, and implementing inheritance and polymorphism. The lecture aims to help students understand object-oriented concepts in Java like classes, objects, inheritance and polymorphism.
Java , basics of java programming, JVM, JRE, JDK detailed explanation. primitive datatype. this ppt explains the basic concepts of java clearly starting from variables to complex programmes. It has 55 slides which gives you better understanding
BCA, Department of Information Technology and Software Development teaches JAVA Language in the fourth semester. The curriculum of the BCA Course of JIMS is very well updated. In this PDF, the Constructor topic is explained. It is one of the very important Concepts and you need to understand it thoroughly.
The document provides examples of various Java programming concepts like displaying messages, using control structures like if-else, for loops, methods, constructors, access specifiers, static variables and more. It shows how to write simple Java programs to print messages, integers, use conditional and looping statements. It also explains concepts like default and parameterized constructors, static and non-static methods, different access specifiers and their usage. The examples help learn how different Java features can be used to develop programs with classes, objects and methods.
This document provides an overview of Java basics including where Java is used, its key features, object-oriented programming concepts, platform independence, the structure of a basic Java program, variable types, operators, naming conventions, and constructors. Java is commonly used in desktop applications, web applications, enterprise applications, mobile apps, embedded systems, and more. It is a simple, secure, robust, portable, and interpreted language that is object-oriented, platform independent and supports multithreading. The document defines classes, inheritance, polymorphism, abstraction, and encapsulation. It also explains Java data types, variables, operators, and naming conventions. Constructors are special methods used to initialize objects that are invoked during object creation.
This document provides an overview of object-oriented programming concepts including classes, objects, inheritance, encapsulation, and polymorphism. It also discusses Java programming fundamentals such as primitive data types, variables, flow control, arrays, and methods. Additionally, it covers object-oriented principles in Java like abstraction, interfaces, exceptions, and collections.
Modern Compiler Design Java Tutorial provides an overview of object-oriented programming concepts in Java including objects, classes, inheritance, encapsulation, and polymorphism. It also covers key Java features like packages, access control modifiers, exceptions, input/output streams, and collections. The document is intended as an introduction to Java for programmers familiar with C++.
This document provides an overview of object-oriented programming concepts in Java including:
- Objects communicate by sending and receiving messages. A program is composed of objects that interact.
- The main concepts of object-oriented programming are objects, classes, inheritance, and encapsulation.
- A class defines the type of an object and groups similar objects. An object is an instance of a class.
- Inheritance allows subclasses to inherit and extend the behavior of superclasses through generalization and specialization.
- Encapsulation separates the internal state of an object from its external interface through access control and information hiding.
Class is a blueprint for creating objects that share common attributes and behaviors. A class defines the data and methods that describe the object. Classes in Java can contain data members, methods, constructors, nested classes, and interfaces. Objects are instances of classes that occupy memory at runtime and can access class members like variables and methods. Constructors initialize an object when it is created and have the same name as the class. The this keyword refers to the current object in a method or constructor. Command line arguments can be passed to a program as strings and accessed via the args parameter in the main method.
This document provides an introduction to the Java programming language. It discusses that Java is an object-oriented, platform-independent language that uses a runtime environment and API. It explains how Java code is compiled and executed. It also covers Java applications, data types, operators, keywords, variables, constructors, inheritance, polymorphism, arrays and other core Java concepts. The document provides examples to illustrate different Java programming concepts.
Mahika Tutorials sharing PPT slide for core java programming language. Go threw this slide and visit our YouTube page too
https://www.youtube.com/c/mahikatutorials
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Soumen Santra
Features
JVM
Architecture
Security
Data Types
Class and Object
Program
First Java Application
Declaring and creating objects
Arrays
Constructors
this keyword
static keyword
Inheritance
Overriding
Access Modifiers
super keyword
final keyword
abstract classes
interfaces
Exceptions (error handling)
User Defining exceptions
Java is a widely used programming language that is mainly used for application programming. It is platform-independent and supports features like multi-threading and documentation comments. The key aspects of a simple Java program are that it must contain a class with a main method that can be the starting point of execution. The main method has a specific signature of public static void main(String[] args). When a Java program is run, the JVM (Java Virtual Machine) loads and executes the program by performing operations like loading code, verifying code, and providing a runtime environment.
The document discusses the static keyword in Java. It explains that static members belong to the class rather than objects, and are loaded when the class is loaded. Static variables and methods can be accessed without creating an object. Constructors are used to initialize non-static variables when an object is created. Static blocks run when the class is loaded and can initialize static variables.
An interface in Java is a blueprint of a class that defines a standard for what methods a class must include. Interfaces provide full abstraction since none of its methods have a body, while abstract classes provide partial abstraction since they can contain both abstract and concrete methods. Interfaces are used to achieve abstraction and multiple inheritance in Java. Common functionalities can be defined in an interface and implemented differently in classes.
Introduction to JAVA Programming
When Java?
Why Java?
How Java?
Where Java?
Architecture of java
Byte code of class file
Java class file to byte code class file.
Tools and Technology
Net-beans, Eclipse
The document discusses JPA/Hibernate, object-relational mapping, and web services. It defines Hibernate as an open source ORM for Java that makes data persistent by storing it in a database. It notes that Hibernate automatically generates SQL queries and reduces development time compared to manually handling data with JDBC. The architecture of Hibernate and web services is described, including how Hibernate sits between code and the database to map objects to tables. Common web service types like SOAP and REST are also summarized.
This document provides an overview of Spring Boot. It discusses the history of Spring Boot and how it evolved from earlier Spring Framework releases to reduce configuration. Spring Boot makes it easy to create Spring-based applications and services with features like auto configuration, embedded servers, and starter dependencies. It also discusses current Spring Boot versions, supported template engines, ways to create Spring Boot apps using IDEs, CLI or Spring Initializr, and some advantages and limitations of Spring Boot.
This document contains a list of 85 software projects related to data mining with codes ranging from DatMng2015-1 to DatMng2015-85. It also contains lists of 20 cloud computing projects, 33 dependable and secure computing projects, and 16 mobile computing projects. Each project listing includes a code and project name.
The document lists 15 paper titles related to mobile computing and wireless sensor networks. The papers cover topics such as location-based routing protocols, duty cycle control, cooperative packet delivery, void-aware pressure routing, cache inconsistency, cross-layer scheduling, relay selection, position update, channel allocation, message authentication, neighbor discovery, mobile relay configuration, and vampire attacks that drain sensor network life.
This document summarizes techniques for privacy-preserving data publishing. It discusses k-anonymity, which anonymizes data by suppressing or generalizing attributes until each record is identical to at least k-1 other records. The document also covers limitations of k-anonymity, including that it does not protect against background knowledge attacks. It proposes addressing these limitations by combining k-anonymity with generalization and slicing techniques.
WIRELESS COMMUNICATION SECURITY AND IT’S PROTECTION METHODSsamueljackson3773
In this paper, the author discusses the concerns of using various wireless communications and how to use
them safely. The author also discusses the future of the wireless industry, wireless communication
security, protection methods, and techniques that could help organizations establish a secure wireless
connection with their employees. The author also discusses other essential factors to learn and note when
manufacturing, selling, or using wireless networks and wireless communication systems.
David Boutry - Mentors Junior DevelopersDavid Boutry
David Boutry is a Senior Software Engineer in New York with expertise in high-performance data processing and cloud technologies like AWS and Kubernetes. With over eight years in the field, he has led projects that improved system scalability and reduced processing times by 40%. He actively mentors aspiring developers and holds certifications in AWS, Scrum, and Azure.
Blood bank management system project report.pdfKamal Acharya
The main objective of the “Blood Bank management System” all the details in the Blood
Bank’sprocess. This project has some tasks to maintain the Blood Bank through computerization.
Using this blood bank system people can search blood group available which they are needed.
They check it on using our blood bank management website. If in case blood group is not available
in blood bank they can also contact numbers of the persons who has the same blood group he is
need. And he can request the person to done the blood for saving someone life.
The Project describes the smart Blood Bank management system. This report will help you
to know in deep the actual work that has been done as a team work. The main objective of this
application is to automate the complete operations of the blood bank. They need to maintain
hundreds of thousands of records. Also searching should be very faster, so they can find required
details instantly. Main objective is to create a system which helps them to complete their work
faster in simple way by using computer not the oldest way which is used paper. Also our project
contains updated information and many things else.
The project consists of a central repository containing various blood deposits available
along with associated details. These details include blood type, storage area and date of storage.
These details help in maintaining and monitoring the blood deposits. The project is an online
system that allows checking weather required blood deposits of a particular group are available in
the blood bank. Moreover the system also has added features such as patient name and contacts,
blood booking and even need for certain blood group is posted on the website to find available
donors for a blood emergency. This online system is developed on PHP platform and supported
by an MYSQL database to store blood and user specific details.
本資料「To CoT or not to CoT?」では、大規模言語モデルにおけるChain of Thought(CoT)プロンプトの効果について詳しく解説しています。
CoTはあらゆるタスクに効く万能な手法ではなく、特に数学的・論理的・アルゴリズム的な推論を伴う課題で高い効果を発揮することが実験から示されています。
一方で、常識や一般知識を問う問題に対しては効果が限定的であることも明らかになりました。
複雑な問題を段階的に分解・実行する「計画と実行」のプロセスにおいて、CoTの強みが活かされる点も注目ポイントです。
This presentation explores when Chain of Thought (CoT) prompting is truly effective in large language models.
The findings show that CoT significantly improves performance on tasks involving mathematical or logical reasoning, while its impact is limited on general knowledge or commonsense tasks.
Understanding Amplitude Modulation : A GuideCircuitDigest
Discover how amplitude modulation works through a detailed guide covering its principles, waveform behavior, and hands-on AM circuit demo using simple electronic components. Great for students and RF beginners.
Read more : https://circuitdigest.com/electronic-circuits/what-is-amplitude-modulation-complete-guide-formula-circuit-diagram-practical-demonstration
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdfdjiceramil
Statics in java | Constructors | Exceptions in Java | String in java| class 3
1. Java Class 4
“Code is like humor. When you have to explain it, it’s
bad.”
•Statics in java
•Constructors
•Exceptions in Java
•String in java
2. Java Values 2
What is Static Keyword ?
The static keyword in Java is used for
memory management mainly. We can apply
static keyword with variables, methods,
blocks and nested classes. The static
keyword belongs to the class than an
instance of the class.
Variable (also known as a class variable)
Method (also known as a class method)
Block
Nested class
3. Java Values 3
Static Variable
Fields that have the static modifier in their
declaration are called static fields or class
variables.
They are associated with the class, rather
than with any object.
Every instance of the class shares a class
variable, which is in one fixed location in
memory.
Any object can change the value of a class
variable, but class variables can also be
manipulated without creating an instance of
the class.
Syntax : <class-name>.<variable-name>
4. Static methods
The Java programming language supports
static methods as well as static variables.
main method is static , since it must be
accessible for an application to run , before any
instantiation takes place.
Static methods, which have the static modifier
in their declarations, should be invoked with the
class name, without the need for creating an
instance of the class, as in
ex. ClassName.methodName(args)
Java Values 4
5. Static methods
A common use for static methods is to
access static fields.
For example, we could add a static method
to the Bicycle class to access the static field
numberOfBicycles :
Java Values 5
public static int getNumberOfBicycles() {
return numberOfBicycles;
}
6. Static methods
Not all combinations of instance and class
variables and methods are allowed:
• Instance methods can access instance
variables and instance methods directly.
• Instance methods can access class variables
and class methods directly.
• Class methods can access class variables and
class methods directly.
• Class methods cannot access instance
variables or instance methods directly—they
must use an object reference. Also, class
methods cannot use the this or super keywords,
as there is no instance to refer to.
Java Values 6
7. Constants
Constant fields are often declared as static.
For example NUM_OF_WHEELS which is a
characteristic of any Bicycle, and not of a
certain instance.
If there’s a sense to expose a constant field
to the outside world, it is common to declare
the field as public, rather than through a
getter.
Java Values 7
8. Singleton pattern
Restricting the instantiation of a certain class
to exactly one object.
This is useful when exactly one object is
needed to coordinate actions across the
system.
A singleton object is accessible globally
using a static method.
Java Values 8
9. Singleton
Java Values 9
public class Controller {
private static Controller instance = null;
private Controller () { ... }
public static Controller getInstance() {
if (instance == null) {
instance = new Controller ();
}
return instance;
}
...
}
* Not thread-safe
Notice the private
constructor
10. A static block
The static block, is a block of statement
inside a Java class that will be executed
when a class is first loaded in to the JVM.
A static block helps to initialize the static
data members, just like constructors help to
initialize instance members.
public class Controller {
private static Controller instance;
static {
instance = new Controller ();
}
private Controller () { }
public static Controller getInstance() {
return instance;
}
}
Java Values 10
11. Example of static
EX: 1
class A2{
static{
System.out.println("static block is
invoked");
}
public static void main(String args
[]){
System.out.println("Hello main");
}
}
output : ?
Java Values 11
EX: 2
class TestOuter1{
static int data=30;
static class Inner{
void msg(){
System.out.println("data is : "+data);
}
}
public static void main(String args[]){
TestOuter1.Inobj=new TestOuter1.Inner();
obj.msg();
}
}
12. Java static nested class
A static class i.e. created inside a class is called
static nested class in java. It cannot access non-
static data members and methods. It can be
accessed by outer class name.
It can access static data members of outer class
including private.
Static nested class cannot access non-static
(instance) data member or method.
For Example Refer previous slide EX:2 output?
Java Values 12
13. What is Constructors ?
In Java, a constructor is a block of codes
similar to the method. It is called when an
instance of the class is created. At the time
of calling constructor, memory for the object
is allocated in the memory.
It is a special type of method which is used
to initialize the object.
Every time an object is created using the
new() keyword, at least one constructor is
called.
Java Values 13
14. Rules for creating constructor
There are two rules defined for the constructor.
Constructor name must be the same as its class
name
A Constructor must have no explicit return type.
A Java constructor cannot be abstract, static, final,
and synchronized
class Bike1{
Bike1(){ //creating a default constructor
System.out.println("Bike is created");
}
public static void main(String args[]){
Bike1 b=new Bike1(); //calling a default constructor
}
}
Java Values 14
15. Type of Constructors
There are two types of constructors in Java:
1. Default constructor (no-arg constructor)
2. Parameterized constructor
If there is no constructor in a class, compiler automatically creates a
default constructor.
Java Values 15
16. class Student4{
int id; // default value 0
String name; //default value null
// if we not pass the int I and string n value it will give default value
Student4(int i,String n){ //creating a parameterized constructor
id = i;
name = n;
}
//method to display the values
void display(){System.out.println(id+" "+name);}
public static void main(String args[]){
//creating objects and passing values
Student4 s1 = new Student4(111,"Karan");
Student4 s2 = new Student4(222,"Aryan");
//calling method to display the values of object
s1.display();
s2.display();
}
}
Java Values 16
Output:?
17. Constructor Chaining
Calling a constructor from the another
constructor of same class is known as
Constructor chaining..
Java Values 17
18. This and Super constructors
this() and super() are used to call
constructors explicitly.
1. Using this() you can call the current class’s constructor
2. Using super() you can call the constructor of the super
class.
Java Values 18
19. class A
{
public int x, y;
public A(int x, int y) {
this.x = x; this.y = y;
}
}
class B extends A {
public int x, y;
public B() {
this(0, 0);
}
public B(int x, int y) {
super(x + 1, y + 1); // calls parent
class constructor
this.x = x;
this.y = y;
}
Java Values 19
public void print() {
System.out.println("Base class : {" + x + ", "
+ y + "}");
System.out.println("Super class : {" +
super.x + ", " + super.y + "}");
}
}
class Point
{
public static void main(String[] args) {
B obj = new B();
obj.print();
obj = new B(1, 2);
obj.print();
}
}
? Answer
20. Constructors for Enumerated Data Types
enum Car {
lamborghini(900),tata(2),audi(50),fiat(15),honda(12); //Enum datatype
private int price;
Car(int p) {
price = p; }
int getPrice() {
return price;
}
}
public class Main {
public static void main(String args[]){
System.out.println("All car prices:");
for (Car c : Car.values())
System.out.println( c + " costs " + c.getPrice() + " thousand dollars.");
}
} Java Values 20
23. What ? Why ? How?
In Java, an exception is an event that disrupts the
normal flow of the program. It is an object which is
thrown at runtime.
Exception Handling is a mechanism to handle
runtime errors such as ClassNotFoundException,
IOException, SQLException, RemoteException,
etc.
The core advantage of exception handling is to
maintain the normal flow of the application. An
exception normally disrupts the normal flow of the
application that is why we use exception handling.
Java Values 23
28. Catching Exceptions
The try-catch Statements
● Syntax:
try {
<code to be monitored for exceptions>
} catch (<ExceptionType1> <ObjName>) {
<handler if ExceptionType1 occurs>
}
...
} catch (<ExceptionTypeN> <ObjName>) {
<handler if ExceptionTypeN occurs>
} finally {
<code to be executed before the try block ends>
}
Java Values 28
29. Throwing Exceptions
The throw Keyword
● Java allows you to throw exceptions (generate exceptions)
ex. throw <exception object>;
● An exception you throw is an object
– You have to create an exception object in the same way you create
any other object
● Example:
throw new ArithmeticException(“testing...”);
class TestHateString {
public static void main(String args[]) {
String input = "invalid input";
try {
if (input.equals("invalid input")) {
throw new HateStringExp();
}
System.out.println("Accept string.");
Java Values 29
} catch (HateStringExp e) {
System.out.println("Hate string!”);
}
}
}
30. Example 2
class InvalidAgeException extends Exception{
InvalidAgeException(String s){
super(s);
}
}
class TestCustomException1{
static void validate(int age)throws InvalidAgeException{
if(age<18)
throw new InvalidAgeException("not valid");
else
System.out.println("welcome to vote");
}
public static void main(String args[]){
try{
validate(13);
}catch(Exception m){System.out.println("Exception occured: "+m);}
System.out.println("rest of the code...");
}
}
Java Values 30
Output:?
32. Strings
String is a sequence of characters placed in
double quote(“ ”). //(“JAVA”)
Strings are constant , their values cannot be
changed in the same memory after they are
created.
There are two ways to create String
object:
1)By string literal.
2)By new keyword.
Java Values 32
33. String Creation
By string literal:
For Example: String s1=“welcome";
String s2=“welcome”;
//no new object will be created
Java Values 33
34. By new keyword:-
For Example:
String s=new String(“Sachin");
String s=newString(“SachinTendulkar");
//create two objects and one reference variable
Java Values 34
35. Immutability
In java, string objects are immutable.
Immutable simply means unmodifiable or
unchangeable.
Once string object is created its data or state
can't be changed but a new string object is
created.
Advantage of immutability is Use of less
memory
Disadvantages of Immutability: Less efficient —
you need to create a new string and throw away
the old one even for small changes
Java Values 35
37. String Methods
substring(int begin):
Returns substring from begin index to end of the String.
Example: String s=“nacre”;
System.out.println(s.substring(2));//cre
equals():
To perform content comparision where case is important.
Example: String s=“java”;
System.out.println(s.equals(“java”));//true
concat(): Adding two strings we use this method
Example: String s=“nacre”;
s= s.concat(“software”);
System.out.println(s);// nacresoftware
Java Values 37
38. length() , charAt()
int length(); Returns the number of characters in the string
char charAt(i); Returns the char at position i.
Character positions in strings are numbered starting from
0 – just like arrays.
Returns:
“Problem".length(); 7
“Window”. charAt (2); ’n'
Java Values 38
40. Limitation of String in Java ?
What is mutable string?
A string that can be modified or changed is known
as mutable string. StringBuffer and StringBuilder
classes are used for creating mutable string.
Differences between String and StringBuffer in java?
Main difference between String and StringBuffer is
String is immutable while StringBuffer is mutable
Java Values 40
41. StringBuffer
StringBuffer is a synchronized and allows us to
mutate the string.
StringBuffer has many utility methods to manipulate
the string.
This is more useful when using in multithreaded
environment.
Always modified in same memory location.
Methods:
1. Append 2. Insert 3.Delete 4.Reverse
5.Replacing Character at given index
Java Values 41
42. StringBuilder
StringBuilder is the same as the StringBuffer class.
The StringBuilder class is not synchronized and
hence in a single threaded environment, the
overhead is less than using a StringBuffer.
public class Test
{
public static void main(String[] args)
{
String str = “Java";
StringBuffer sbr = new StringBuffer(str);
sbr.reverse();
System.out.println(sbr);
// conversion from String object to StringBuilder
StringBuilder sbl = new StringBuilder(str);
sbl.append(“Values");
System.out.println(sbl);
}
}
Java Values 42
Output?
43. StringTokenizer
A token is a portion of a string that is separated from another
portion of that string by one or more chosen characters (called
delimiters).
The StringTokenizer class contained in the java.util package
can be used to break a string into separate tokens. This is
particularly useful in those situations in which we want to read
and process one token at a time; the BufferedReader class
does not have a method to read one token at a time.
Java Values 43
44. Java Values 44
Java Values
“Hello world welcome to Java Values”
String Tokenizer
Token
Hello
world
welcome
to
Java
Values