SlideShare a Scribd company logo
CORE JAVA
Comments are almost like C++
• The javadoc program generates HTML API
documentation from the “javadoc” style comments in
your code.
/* This kind comment can span multiple lines */
// This kind is of to the end of the line
/* This kind of comment is a special
* ‘javadoc’ style comment
*/
JAVA Classes
• The class is the fundamental concept in JAVA (and other
OOPLs)
• A class describes some data object(s), and the operations (or
methods) that can be applied to those objects
• Every object and method in Java belongs to a class
• Classes have data (fields) and code (methods) and classes
(member classes or inner classes)
• Static methods and fields belong to the class itself
• Others belong to instances
An example of a class
class Person { Variable
String name;
int age; Method
void birthday ( )
{
age++;
System.out.println (name +
' is now ' + age);
}
}
Scoping
As in C/C++, scope is determined by the placement of curly braces {}.
A variable defined within a scope is available only to the end of that scope.
{ int x = 12;
/* only x available */
{ int q = 96;
/* both x and q available */
}
/* only x available */
/* q “out of scope” */
}
{ int x = 12;
{ int x = 96; /* illegal */
}
}
This is ok in C/C++ but not in Java.
Scope of Objects
• Java objects don’t have the same lifetimes as
primitives.
• When you create a Java object using new, it hangs
around past the end of the scope.
• Here, the scope of name s is delimited by the {}s but
the String object hangs around until GC’d
{
String s = new String("a string");
} /* end of scope */
The static keyword
• Java methods and variables can be declared static
• These exist independent of any object
• This means that a Class’s
– static methods can be called even if no objects of that
class have been created and
– static data is “shared” by all instances (i.e., one rvalue per
class instead of one per instance
class StaticTest {static int i = 47;}
StaticTest st1 = new StaticTest();
StaticTest st2 = new StaticTest();
// st1.i == st2.I == 47
StaticTest.i++; // or st1.I++ or
st2.I++
// st1.i == st2.I == 48
Example
public class Circle {public class Circle {
// A class field// A class field
public static final double PI= 3.14159; // A usefulpublic static final double PI= 3.14159; // A useful
constantconstant
// A class method: just compute a value based on the// A class method: just compute a value based on the
argumentsarguments
public static double radiansToDegrees(double rads) {public static double radiansToDegrees(double rads) {
return rads * 180 / PI;return rads * 180 / PI;
}}
// An instance field// An instance field
public double r; // The radius of thepublic double r; // The radius of the
circlecircle
// Two methods which operate on the instance fields of// Two methods which operate on the instance fields of
an objectan object
public double area() { // Compute the area ofpublic double area() { // Compute the area of
the circlethe circle
return PI * r * r;return PI * r * r;
}}
public double circumference() { // Compute thepublic double circumference() { // Compute the
circumference of the circlecircumference of the circle
return 2 * PI * r;return 2 * PI * r;
}}
}}
Array Operations
• Subscripts always start at 0 as in C
• Subscript checking is done automatically
• Certain operations are defined on arrays of
objects, as for other classes
– e.g. myArray.length == 5
An array is an object
• Person mary = new Person ( );
• int myArray[ ] = new int[5];
• int myArray[ ] = {1, 4, 9, 16, 25};
• String languages [ ] = {"Prolog", "Java"};
• Since arrays are objects they are allocated dynamically
• Arrays, like all objects, are subject to garbage collection when
no more references remain
– so fewer memory leaks
– Java doesn’t have pointers!
Example
Programs
Echo.java
• C:UMBC331java>type echo.java
• // This is the Echo example from the Sun tutorial
• class echo {
• public static void main(String args[]) {
• for (int i=0; i < args.length; i++) {
• System.out.println( args[i] );
• }
• }
• }
• C:UMBC331java>javac echo.java
• C:UMBC331java>java echo this is pretty silly
• this
• is
• pretty
• silly
NSIT ,Jetalpur
Factorial Example
/* This program computes the factorial of a number
*/
public class Factorial { // Define a class
public static void main(String[] args) { // The program starts
here
int input = Integer.parseInt(args[0]); // Get the user's
input
double result = factorial(input); // Compute the
factorial
System.out.println(result); // Print out the
result
} // The main() method
ends here
public static double factorial(int x) { // This method
computes x!
if (x < 0) // Check for bad input
return 0.0; // if bad, return 0
double fact = 1.0; // Begin with an
initial value
while(x > 1) { // Loop until x equals
fact = fact * x; // multiply by x
each time
x = x - 1; // and then
decrement x
NSIT ,Jetalpur
Constructors
• Classes should define one or more methods to create or
construct instances of the class
• Their name is the same as the class name
– note deviation from convention that methods begin with lower
case
• Constructors are differentiated by the number and types of
their arguments
– An example of overloading
• If you don’t define a constructor, a default one will be
created.
• Constructors automatically invoke the zero argument
constructor of their superclass when they begin (note that
this yields a recursive process!)NSIT ,Jetalpur
Methods, arguments and
return values
• Java methods are like C/C++ functions.
General case:
returnType methodName ( arg1, arg2, … argN)
{
methodBody
}
The return keyword exits a method optionally with a value
int storage(String s) {return s.length() * 2;}
boolean flag() { return true; }
float naturalLogBase() { return 2.718f; }
void nothing() { return; }
void nothing2() {}

More Related Content

What's hot

Core java concepts
Core java concepts Core java concepts
Core java concepts javeed_mhd
 
Object and class in java
Object and class in javaObject and class in java
Object and class in javaUmamaheshwariv1
 
Java basic tutorial
Java basic tutorialJava basic tutorial
Java basic tutorialBui Kiet
 
Class & Object - Intro
Class & Object - IntroClass & Object - Intro
Class & Object - IntroPRN USM
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in JavaSpotle.ai
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in javaAtul Sehdev
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Majid Saeed
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and objectFajar Baskoro
 
Java Basics
Java BasicsJava Basics
Java BasicsF K
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in javaRaja Sekhar
 
Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectJava OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectOUM SAOKOSAL
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object ReferencesTareq Hasan
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introductionSohanur63
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPTkishu0005
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java conceptsChikugehlot
 

What's hot (20)

Java Basics
Java BasicsJava Basics
Java Basics
 
Core java concepts
Core java concepts Core java concepts
Core java concepts
 
Object and class in java
Object and class in javaObject and class in java
Object and class in java
 
Java basic tutorial
Java basic tutorialJava basic tutorial
Java basic tutorial
 
Class & Object - Intro
Class & Object - IntroClass & Object - Intro
Class & Object - Intro
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
 
Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Class object method constructors in java
Class object method constructors in javaClass object method constructors in java
Class object method constructors in java
 
Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectJava OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and Object
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object References
 
Java Methods
Java MethodsJava Methods
Java Methods
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java concepts
 
C++ classes
C++ classesC++ classes
C++ classes
 

Similar to Core java

Core java concepts
Core java  conceptsCore java  concepts
Core java conceptsRam132
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorialrajkamaltibacademy
 
Pi j2.2 classes
Pi j2.2 classesPi j2.2 classes
Pi j2.2 classesmcollison
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptxEpsiba1
 
JavaTutorials.ppt
JavaTutorials.pptJavaTutorials.ppt
JavaTutorials.pptKhizar40
 
Java assignment help
Java assignment helpJava assignment help
Java assignment helpJacob William
 
Ifi7184 lesson3
Ifi7184 lesson3Ifi7184 lesson3
Ifi7184 lesson3Sónia
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.Tarunsingh198
 
02 java basics
02 java basics02 java basics
02 java basicsbsnl007
 
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...argsstring
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0BG Java EE Course
 
Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaRadhika Talaviya
 
Unit 1 Part - 3 constructor Overloading Static.ppt
Unit 1 Part - 3  constructor Overloading Static.pptUnit 1 Part - 3  constructor Overloading Static.ppt
Unit 1 Part - 3 constructor Overloading Static.pptDeepVala5
 
Java tutorials
Java tutorialsJava tutorials
Java tutorialssaryu2011
 

Similar to Core java (20)

Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Java basic
Java basicJava basic
Java basic
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorial
 
Java
JavaJava
Java
 
Java
JavaJava
Java
 
Pi j2.2 classes
Pi j2.2 classesPi j2.2 classes
Pi j2.2 classes
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
 
JavaTutorials.ppt
JavaTutorials.pptJavaTutorials.ppt
JavaTutorials.ppt
 
Java assignment help
Java assignment helpJava assignment help
Java assignment help
 
Ifi7184 lesson3
Ifi7184 lesson3Ifi7184 lesson3
Ifi7184 lesson3
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
02 java basics
02 java basics02 java basics
02 java basics
 
core java
core javacore java
core java
 
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with Java
 
Unit 1 Part - 3 constructor Overloading Static.ppt
Unit 1 Part - 3  constructor Overloading Static.pptUnit 1 Part - 3  constructor Overloading Static.ppt
Unit 1 Part - 3 constructor Overloading Static.ppt
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Java OO Revisited
Java OO RevisitedJava OO Revisited
Java OO Revisited
 

More from Rajkattamuri

Github plugin setup in anypointstudio
Github plugin setup in anypointstudioGithub plugin setup in anypointstudio
Github plugin setup in anypointstudioRajkattamuri
 
For each component in mule
For each component in muleFor each component in mule
For each component in muleRajkattamuri
 
Filter expression in mule
Filter expression in muleFilter expression in mule
Filter expression in muleRajkattamuri
 
File component in mule
File component in muleFile component in mule
File component in muleRajkattamuri
 
Database component in mule
Database component in muleDatabase component in mule
Database component in muleRajkattamuri
 
Choice component in mule
Choice component in mule Choice component in mule
Choice component in mule Rajkattamuri
 
Java Basics in Mule
Java Basics in MuleJava Basics in Mule
Java Basics in MuleRajkattamuri
 
WebServices Basic Overview
WebServices Basic OverviewWebServices Basic Overview
WebServices Basic OverviewRajkattamuri
 
Java For Begineers
Java For BegineersJava For Begineers
Java For BegineersRajkattamuri
 
WebServices Basics
WebServices BasicsWebServices Basics
WebServices BasicsRajkattamuri
 
WebServices SOAP WSDL and UDDI
WebServices SOAP WSDL and UDDIWebServices SOAP WSDL and UDDI
WebServices SOAP WSDL and UDDIRajkattamuri
 
Mule esb dataweave
Mule esb dataweaveMule esb dataweave
Mule esb dataweaveRajkattamuri
 
Mule with rabbitmq
Mule with rabbitmqMule with rabbitmq
Mule with rabbitmqRajkattamuri
 

More from Rajkattamuri (20)

Github plugin setup in anypointstudio
Github plugin setup in anypointstudioGithub plugin setup in anypointstudio
Github plugin setup in anypointstudio
 
For each component in mule
For each component in muleFor each component in mule
For each component in mule
 
Filter expression in mule
Filter expression in muleFilter expression in mule
Filter expression in mule
 
File component in mule
File component in muleFile component in mule
File component in mule
 
Database component in mule
Database component in muleDatabase component in mule
Database component in mule
 
Choice component in mule
Choice component in mule Choice component in mule
Choice component in mule
 
WebServices
WebServicesWebServices
WebServices
 
Java Basics in Mule
Java Basics in MuleJava Basics in Mule
Java Basics in Mule
 
WebServices Basic Overview
WebServices Basic OverviewWebServices Basic Overview
WebServices Basic Overview
 
Java For Begineers
Java For BegineersJava For Begineers
Java For Begineers
 
WebServices Basics
WebServices BasicsWebServices Basics
WebServices Basics
 
WebServices SOAP WSDL and UDDI
WebServices SOAP WSDL and UDDIWebServices SOAP WSDL and UDDI
WebServices SOAP WSDL and UDDI
 
Web services soap
Web services soapWeb services soap
Web services soap
 
Web services wsdl
Web services wsdlWeb services wsdl
Web services wsdl
 
Web services uddi
Web services uddiWeb services uddi
Web services uddi
 
Maven
MavenMaven
Maven
 
Mule esb dataweave
Mule esb dataweaveMule esb dataweave
Mule esb dataweave
 
Mule with drools
Mule with drools Mule with drools
Mule with drools
 
Mule with quartz
Mule with quartz Mule with quartz
Mule with quartz
 
Mule with rabbitmq
Mule with rabbitmqMule with rabbitmq
Mule with rabbitmq
 

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2DianaGray10
 
The architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdfThe architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdfalexjohnson7307
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationZilliz
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Julian Hyde
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupCatarinaPereira64715
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka DoktorováCzechDreamin
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityScyllaDB
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor TurskyiFwdays
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backElena Simperl
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeCzechDreamin
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsPaul Groth
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...Product School
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesBhaskar Mitra
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Product School
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...Product School
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoTAnalytics
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
The architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdfThe architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdf
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 

Core java

  • 2. Comments are almost like C++ • The javadoc program generates HTML API documentation from the “javadoc” style comments in your code. /* This kind comment can span multiple lines */ // This kind is of to the end of the line /* This kind of comment is a special * ‘javadoc’ style comment */
  • 3. JAVA Classes • The class is the fundamental concept in JAVA (and other OOPLs) • A class describes some data object(s), and the operations (or methods) that can be applied to those objects • Every object and method in Java belongs to a class • Classes have data (fields) and code (methods) and classes (member classes or inner classes) • Static methods and fields belong to the class itself • Others belong to instances
  • 4. An example of a class class Person { Variable String name; int age; Method void birthday ( ) { age++; System.out.println (name + ' is now ' + age); } }
  • 5. Scoping As in C/C++, scope is determined by the placement of curly braces {}. A variable defined within a scope is available only to the end of that scope. { int x = 12; /* only x available */ { int q = 96; /* both x and q available */ } /* only x available */ /* q “out of scope” */ } { int x = 12; { int x = 96; /* illegal */ } } This is ok in C/C++ but not in Java.
  • 6. Scope of Objects • Java objects don’t have the same lifetimes as primitives. • When you create a Java object using new, it hangs around past the end of the scope. • Here, the scope of name s is delimited by the {}s but the String object hangs around until GC’d { String s = new String("a string"); } /* end of scope */
  • 7. The static keyword • Java methods and variables can be declared static • These exist independent of any object • This means that a Class’s – static methods can be called even if no objects of that class have been created and – static data is “shared” by all instances (i.e., one rvalue per class instead of one per instance class StaticTest {static int i = 47;} StaticTest st1 = new StaticTest(); StaticTest st2 = new StaticTest(); // st1.i == st2.I == 47 StaticTest.i++; // or st1.I++ or st2.I++ // st1.i == st2.I == 48
  • 8. Example public class Circle {public class Circle { // A class field// A class field public static final double PI= 3.14159; // A usefulpublic static final double PI= 3.14159; // A useful constantconstant // A class method: just compute a value based on the// A class method: just compute a value based on the argumentsarguments public static double radiansToDegrees(double rads) {public static double radiansToDegrees(double rads) { return rads * 180 / PI;return rads * 180 / PI; }} // An instance field// An instance field public double r; // The radius of thepublic double r; // The radius of the circlecircle // Two methods which operate on the instance fields of// Two methods which operate on the instance fields of an objectan object public double area() { // Compute the area ofpublic double area() { // Compute the area of the circlethe circle return PI * r * r;return PI * r * r; }} public double circumference() { // Compute thepublic double circumference() { // Compute the circumference of the circlecircumference of the circle return 2 * PI * r;return 2 * PI * r; }} }}
  • 9. Array Operations • Subscripts always start at 0 as in C • Subscript checking is done automatically • Certain operations are defined on arrays of objects, as for other classes – e.g. myArray.length == 5
  • 10. An array is an object • Person mary = new Person ( ); • int myArray[ ] = new int[5]; • int myArray[ ] = {1, 4, 9, 16, 25}; • String languages [ ] = {"Prolog", "Java"}; • Since arrays are objects they are allocated dynamically • Arrays, like all objects, are subject to garbage collection when no more references remain – so fewer memory leaks – Java doesn’t have pointers!
  • 12. Echo.java • C:UMBC331java>type echo.java • // This is the Echo example from the Sun tutorial • class echo { • public static void main(String args[]) { • for (int i=0; i < args.length; i++) { • System.out.println( args[i] ); • } • } • } • C:UMBC331java>javac echo.java • C:UMBC331java>java echo this is pretty silly • this • is • pretty • silly NSIT ,Jetalpur
  • 13. Factorial Example /* This program computes the factorial of a number */ public class Factorial { // Define a class public static void main(String[] args) { // The program starts here int input = Integer.parseInt(args[0]); // Get the user's input double result = factorial(input); // Compute the factorial System.out.println(result); // Print out the result } // The main() method ends here public static double factorial(int x) { // This method computes x! if (x < 0) // Check for bad input return 0.0; // if bad, return 0 double fact = 1.0; // Begin with an initial value while(x > 1) { // Loop until x equals fact = fact * x; // multiply by x each time x = x - 1; // and then decrement x NSIT ,Jetalpur
  • 14. Constructors • Classes should define one or more methods to create or construct instances of the class • Their name is the same as the class name – note deviation from convention that methods begin with lower case • Constructors are differentiated by the number and types of their arguments – An example of overloading • If you don’t define a constructor, a default one will be created. • Constructors automatically invoke the zero argument constructor of their superclass when they begin (note that this yields a recursive process!)NSIT ,Jetalpur
  • 15. Methods, arguments and return values • Java methods are like C/C++ functions. General case: returnType methodName ( arg1, arg2, … argN) { methodBody } The return keyword exits a method optionally with a value int storage(String s) {return s.length() * 2;} boolean flag() { return true; } float naturalLogBase() { return 2.718f; } void nothing() { return; } void nothing2() {}