0% found this document useful (0 votes)
1 views1 page

Java Ch1 Answers

Uploaded by

shaikfaizan719
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views1 page

Java Ch1 Answers

Uploaded by

shaikfaizan719
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Programming – Assignment Answers

1(a) Compare different types of constructors with an example


A constructor in Java is a special method used to initialize objects. It has the same name as the
class and does not have a return type.

Constructor Type Description


Default Constructor Constructor with no parameters. Provided automatically if no constructor is defined.
Parameterized Constructor Constructor that accepts parameters to initialize variables.
Copy Constructor Constructor used to copy values from another object.

Example:
class Student { int id; String name; Student(){ id=0; name='Unknown'; } Student(int i, String n){ id=i;
name=n; } Student(Student s){ id=[Link]; name=[Link]; } }

1(b) Define Static Method with Example


A static method belongs to the class rather than an object. It can be called without creating an
instance of the class.
Example: class Demo { static void show(){ [Link]('Static Method'); } public static void
main(String args[]){ [Link](); }}

2. String Class and Methods


The String class in Java is used to store and manipulate text. Strings are immutable, meaning their
values cannot be changed after creation.
Common methods: length(), toUpperCase(), toLowerCase(), charAt(), substring(), concat(),
equals().

3. Java Buzzwords and Portability


Java Buzzwords include: Simple, Object-Oriented, Portable, Platform Independent, Secure,
Robust, Multithreaded, Distributed, Dynamic, and High Performance.
Java is portable because the Java compiler converts source code into bytecode, which runs on the
Java Virtual Machine (JVM). This allows Java programs to run on different operating systems
without modification.

You might also like