SlideShare a Scribd company logo
support@myassignmenthelpers.com
http://www.myassignmenthelpers.com/
The javadoc program generates HTML API
documentation from the “javadoc” style
comments in your code.
2
/* This kind of comment can span multiple lines */
// This kind is to the end of the line
/**
* This kind of comment is a special
* ‘javadoc’ style comment
*/
3
class Person {
String name;
int age;
void birthday ( ) {
age++;
System.out.println (name +
' is now ' + age);
}
}
Variable
Method
 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.
4
{ 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 inC/C++ but not in Java.
 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!
5
 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 */
6
 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() {}
7
 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
8
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
 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
9
/**
* 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 1
fact = fact * x; // multiply by x each time
x = x - 1; // and then decrement x
} // Jump back to the star of
loop
return fact; // Return the result
} // factorial() ends here
} // The class ends here
10
From Java in a Nutshell
 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
11
 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!)
12
 Class hierarchies reflect subclass-superclass relations among
classes.
 One arranges classes in hierarchies:
 A class inherits instance variables and instance methods from all of its
superclasses. Tree -> BinaryTree -> BST
 You can specify only ONE superclass for any class.
 When a subclass-superclass chain contains multiple instance
methods with the same signature (name, arity, and argument
types), the one closest to the target instance in the subclass-
superclass chain is the one executed.
 All others are shadowed/overridden.
 Something like multiple inheritance can be done via interfaces
(more on this later)
 What’s the superclass of a class defined without an extends
clause?
13
 Data-hiding or encapsulation is an important
part of the OO paradigm.
 Classes should carefully control access to
their data and methods in order to
 Hide the irrelevant implementation-level details so
they can be easily changed
 Protect the class against accidental or malicious
damage.
 Keep the externally visible class simple and easy to
document
 Java has a simple access control mechanism
to help with encapsulation
 Modifiers: public, protected, private, and package
(default) 14
 Access to packages
 Java offers no control mechanisms for packages.
 If you can find and read the package you can access it
 Access to classes
 All top level classes in package P are accessible
anywhere in P
 All public top-level classes in P are accessible
anywhere
 Access to class members (in class C in package P)
 Public: accessible anywhere C is accessible
 Protected: accessible in P and to any of C’s subclasses
 Private: only accessible within class C
 Package: only accessible in P (the default)
15
 Abstract vs. concrete classes
 Abstract classes can not be instantiated
public abstract class shape { }
 An abstract method is a method w/o a body
public abstract double area();
 (Only)Abstract classes can have abstract
methods
 In fact, any class with an abstract method is
automatically an abstract class
16
 No global variables
 class variables and methods may be applied to
any instance of an object
 methods may have local (private?) variables
 No pointers
 but complex data objects are “referenced”
 Other parts of Java are borrowed from PL/I,
Modula, and other languages
17

More Related Content

What's hot

Classes&amp;objects
Classes&amp;objectsClasses&amp;objects
Classes&amp;objects
M Vishnuvardhan Reddy
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
Elizabeth alexander
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism Java
M. Raihan
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
Elizabeth alexander
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritanceArjun Shanka
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorial
rajkamaltibacademy
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#
Adeel Rasheed
 
Introduction to OOP(in java) BY Govind Singh
Introduction to OOP(in java)  BY Govind SinghIntroduction to OOP(in java)  BY Govind Singh
Introduction to OOP(in java) BY Govind Singh
prabhat engineering college
 
Classes and objects in java
Classes and objects in javaClasses and objects in java
Classes and objects in java
Muthukumaran Subramanian
 
C# Types of classes
C# Types of classesC# Types of classes
C# Types of classes
Prem Kumar Badri
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
Ahsan Raja
 
CLASS & OBJECT IN JAVA
CLASS & OBJECT  IN JAVACLASS & OBJECT  IN JAVA
CLASS & OBJECT IN JAVA
Riaj Uddin Mahi
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
Tareq Hasan
 
Generics in java
Generics in javaGenerics in java
Generics in java
suraj pandey
 
Java Generics
Java GenericsJava Generics
Java Generics
DeeptiJava
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
Dr.Neeraj Kumar Pandey
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
Sohanur63
 
Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
PhD Research Scholar
 

What's hot (20)

Classes&amp;objects
Classes&amp;objectsClasses&amp;objects
Classes&amp;objects
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Inheritance and Polymorphism Java
Inheritance and Polymorphism JavaInheritance and Polymorphism Java
Inheritance and Polymorphism Java
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
 
Corejava Training in Bangalore Tutorial
Corejava Training in Bangalore TutorialCorejava Training in Bangalore Tutorial
Corejava Training in Bangalore Tutorial
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#
 
Introduction to OOP(in java) BY Govind Singh
Introduction to OOP(in java)  BY Govind SinghIntroduction to OOP(in java)  BY Govind Singh
Introduction to OOP(in java) BY Govind Singh
 
Classes and objects in java
Classes and objects in javaClasses and objects in java
Classes and objects in java
 
C# Types of classes
C# Types of classesC# Types of classes
C# Types of classes
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
 
CLASS & OBJECT IN JAVA
CLASS & OBJECT  IN JAVACLASS & OBJECT  IN JAVA
CLASS & OBJECT IN JAVA
 
Unit 4 Java
Unit 4 JavaUnit 4 Java
Unit 4 Java
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Generics in java
Generics in javaGenerics in java
Generics in java
 
Java Generics
Java GenericsJava Generics
Java Generics
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
 
Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
 

Viewers also liked

Programming Mobile Applications for Android Handheld Systems: Part 1
Programming Mobile Applications for Android Handheld Systems: Part 1Programming Mobile Applications for Android Handheld Systems: Part 1
Programming Mobile Applications for Android Handheld Systems: Part 1Luca Invernizzi
 
An Introduction to Interactive Programming in Python (Part 2)
An Introduction to Interactive Programming in Python (Part 2)An Introduction to Interactive Programming in Python (Part 2)
An Introduction to Interactive Programming in Python (Part 2)Luca Invernizzi
 
Lo3 summary report
Lo3 summary reportLo3 summary report
Lo3 summary report
joshuah649
 
Curriculum builder directions
Curriculum builder directionsCurriculum builder directions
Curriculum builder directions
Ru Story Huffman
 
3. siklus sel
3. siklus sel3. siklus sel
3. siklus sel
Atifah Hanum
 
#ILIB15 : De BA1 à MA2, que de changements, d'évolutions, de différences !
#ILIB15 : De BA1 à MA2, que de changements, d'évolutions, de différences !#ILIB15 : De BA1 à MA2, que de changements, d'évolutions, de différences !
#ILIB15 : De BA1 à MA2, que de changements, d'évolutions, de différences !
Sophie Fally
 
Usable Security
Usable SecurityUsable Security
Usable SecurityRohit Rao
 
2.0
2.02.0
Autonomii locale şi instituţii centrale în spaţiul românesc
Autonomii locale şi instituţii centrale în spaţiul românescAutonomii locale şi instituţii centrale în spaţiul românesc
Autonomii locale şi instituţii centrale în spaţiul românesc
Stănescu Cătălin
 

Viewers also liked (14)

Evaluación
EvaluaciónEvaluación
Evaluación
 
Programming Mobile Applications for Android Handheld Systems: Part 1
Programming Mobile Applications for Android Handheld Systems: Part 1Programming Mobile Applications for Android Handheld Systems: Part 1
Programming Mobile Applications for Android Handheld Systems: Part 1
 
An Introduction to Interactive Programming in Python (Part 2)
An Introduction to Interactive Programming in Python (Part 2)An Introduction to Interactive Programming in Python (Part 2)
An Introduction to Interactive Programming in Python (Part 2)
 
Coursera usablesec 2015
Coursera usablesec 2015Coursera usablesec 2015
Coursera usablesec 2015
 
Software Security
Software SecuritySoftware Security
Software Security
 
Lo3 summary report
Lo3 summary reportLo3 summary report
Lo3 summary report
 
Curriculum builder directions
Curriculum builder directionsCurriculum builder directions
Curriculum builder directions
 
HSG_101
HSG_101HSG_101
HSG_101
 
3. siklus sel
3. siklus sel3. siklus sel
3. siklus sel
 
#ILIB15 : De BA1 à MA2, que de changements, d'évolutions, de différences !
#ILIB15 : De BA1 à MA2, que de changements, d'évolutions, de différences !#ILIB15 : De BA1 à MA2, que de changements, d'évolutions, de différences !
#ILIB15 : De BA1 à MA2, que de changements, d'évolutions, de différences !
 
Kroll ontrack
Kroll ontrackKroll ontrack
Kroll ontrack
 
Usable Security
Usable SecurityUsable Security
Usable Security
 
2.0
2.02.0
2.0
 
Autonomii locale şi instituţii centrale în spaţiul românesc
Autonomii locale şi instituţii centrale în spaţiul românescAutonomii locale şi instituţii centrale în spaţiul românesc
Autonomii locale şi instituţii centrale în spaţiul românesc
 

Similar to Java assignment help

Java
JavaJava
Java
JavaJava
Core java concepts
Core java concepts Core java concepts
Core java concepts
javeed_mhd
 
Core Java
Core JavaCore Java
Core Java
Khasim Saheb
 
Java Concepts
Java ConceptsJava Concepts
Java Concepts
AbdulImrankhan7
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
G C Reddy Technologies
 
Java Basics
Java BasicsJava Basics
Java Basics
Rajkattamuri
 
Java basic tutorial
Java basic tutorialJava basic tutorial
Java basic tutorial
Bui Kiet
 
Best Core Java Training In Bangalore
Best Core Java Training In BangaloreBest Core Java Training In Bangalore
Best Core Java Training In Bangalore
rajkamaltibacademy
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
Ram132
 
Java PRESENTATION(PACKAGES,CLASSES,VARIABLES,FLOW CONTROL,EXCEPTION)
Java PRESENTATION(PACKAGES,CLASSES,VARIABLES,FLOW CONTROL,EXCEPTION)Java PRESENTATION(PACKAGES,CLASSES,VARIABLES,FLOW CONTROL,EXCEPTION)
Java PRESENTATION(PACKAGES,CLASSES,VARIABLES,FLOW CONTROL,EXCEPTION)
quantumiq448
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
Ajay Sharma
 
Java Basics
Java BasicsJava Basics
Java Basics
F K
 
Sonu wiziq
Sonu wiziqSonu wiziq
Sonu wiziq
Sonu WIZIQ
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
Gousalya Ramachandran
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10Terry Yoast
 
JAVA CONCEPTS AND PRACTICES
JAVA CONCEPTS AND PRACTICESJAVA CONCEPTS AND PRACTICES
JAVA CONCEPTS AND PRACTICES
Nikunj Parekh
 

Similar to Java assignment help (20)

Java02
Java02Java02
Java02
 
Java
JavaJava
Java
 
Java
JavaJava
Java
 
Core java concepts
Core java concepts Core java concepts
Core java concepts
 
Core Java
Core JavaCore Java
Core Java
 
Java Concepts
Java ConceptsJava Concepts
Java Concepts
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java basic
Java basicJava basic
Java basic
 
Java basic tutorial
Java basic tutorialJava basic tutorial
Java basic tutorial
 
Best Core Java Training In Bangalore
Best Core Java Training In BangaloreBest Core Java Training In Bangalore
Best Core Java Training In Bangalore
 
Java 06
Java 06Java 06
Java 06
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Java PRESENTATION(PACKAGES,CLASSES,VARIABLES,FLOW CONTROL,EXCEPTION)
Java PRESENTATION(PACKAGES,CLASSES,VARIABLES,FLOW CONTROL,EXCEPTION)Java PRESENTATION(PACKAGES,CLASSES,VARIABLES,FLOW CONTROL,EXCEPTION)
Java PRESENTATION(PACKAGES,CLASSES,VARIABLES,FLOW CONTROL,EXCEPTION)
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Sonu wiziq
Sonu wiziqSonu wiziq
Sonu wiziq
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
 
JAVA CONCEPTS AND PRACTICES
JAVA CONCEPTS AND PRACTICESJAVA CONCEPTS AND PRACTICES
JAVA CONCEPTS AND PRACTICES
 

Recently uploaded

CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 

Recently uploaded (20)

CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 

Java assignment help

  • 2. The javadoc program generates HTML API documentation from the “javadoc” style comments in your code. 2 /* This kind of comment can span multiple lines */ // This kind is to the end of the line /** * This kind of comment is a special * ‘javadoc’ style comment */
  • 3. 3 class Person { String name; int age; void birthday ( ) { age++; System.out.println (name + ' is now ' + age); } } Variable Method
  • 4.  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. 4 { 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 inC/C++ but not in Java.
  • 5.  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! 5
  • 6.  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 */ 6
  • 7.  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() {} 7
  • 8.  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 8 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
  • 9.  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 9
  • 10. /** * 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 1 fact = fact * x; // multiply by x each time x = x - 1; // and then decrement x } // Jump back to the star of loop return fact; // Return the result } // factorial() ends here } // The class ends here 10 From Java in a Nutshell
  • 11.  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 11
  • 12.  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!) 12
  • 13.  Class hierarchies reflect subclass-superclass relations among classes.  One arranges classes in hierarchies:  A class inherits instance variables and instance methods from all of its superclasses. Tree -> BinaryTree -> BST  You can specify only ONE superclass for any class.  When a subclass-superclass chain contains multiple instance methods with the same signature (name, arity, and argument types), the one closest to the target instance in the subclass- superclass chain is the one executed.  All others are shadowed/overridden.  Something like multiple inheritance can be done via interfaces (more on this later)  What’s the superclass of a class defined without an extends clause? 13
  • 14.  Data-hiding or encapsulation is an important part of the OO paradigm.  Classes should carefully control access to their data and methods in order to  Hide the irrelevant implementation-level details so they can be easily changed  Protect the class against accidental or malicious damage.  Keep the externally visible class simple and easy to document  Java has a simple access control mechanism to help with encapsulation  Modifiers: public, protected, private, and package (default) 14
  • 15.  Access to packages  Java offers no control mechanisms for packages.  If you can find and read the package you can access it  Access to classes  All top level classes in package P are accessible anywhere in P  All public top-level classes in P are accessible anywhere  Access to class members (in class C in package P)  Public: accessible anywhere C is accessible  Protected: accessible in P and to any of C’s subclasses  Private: only accessible within class C  Package: only accessible in P (the default) 15
  • 16.  Abstract vs. concrete classes  Abstract classes can not be instantiated public abstract class shape { }  An abstract method is a method w/o a body public abstract double area();  (Only)Abstract classes can have abstract methods  In fact, any class with an abstract method is automatically an abstract class 16
  • 17.  No global variables  class variables and methods may be applied to any instance of an object  methods may have local (private?) variables  No pointers  but complex data objects are “referenced”  Other parts of Java are borrowed from PL/I, Modula, and other languages 17