0% found this document useful (0 votes)
2 views

Assignment

The document provides an overview of key Java programming concepts, including static methods, loops, memory allocation, string immutability, and object-oriented principles such as encapsulation, polymorphism, inheritance, and abstraction. It also discusses the limitations of arrays compared to ArrayLists and includes code examples demonstrating these concepts. Additionally, it briefly mentions SQL syntax for selecting data from a table.

Uploaded by

traokelsa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment

The document provides an overview of key Java programming concepts, including static methods, loops, memory allocation, string immutability, and object-oriented principles such as encapsulation, polymorphism, inheritance, and abstraction. It also discusses the limitations of arrays compared to ArrayLists and includes code examples demonstrating these concepts. Additionally, it briefly mentions SQL syntax for selecting data from a table.

Uploaded by

traokelsa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment – Open Course

1. Static means that you can call the function without having instance of a class(or
creating object of class).

2. public void infiniteLoopUsingFor()


{ for (;;) { // do something } }

3. The while loop will repeat executing a set of statements infinite number of times
until a certain condition is met.
The do-while loop is similar to the while loop except it checks the condition only
after it runs through its instructions and the do-while loop always runs at least once.

4)The keyword new is used to allocate the memory, so when we ask the compiler to
allocate some memory for some object, it gives it depending upon the size of the object
since the object size is unknown to the compiler unless the program is running.

5) The new keyword is used to create the instance of an object.

6) Use arrayname.length to determine the number of rows. Use arr[rowNumber].length


to get column length.

7) syntax:
public class Main{
static void myMethod() {
//code to be executed
}
example:

public class Demo


{
public static void main(String[] args)
{
// using the max() method of Math class
System.out.print("The maximum number is: " + Math.max(9,7));
}
}

8) syntax:

ClassName object = new ClassName();


Example:
public class CreateObjectExample1
{
void show()
{
System.out.println("Welcome to javaTpoint");
}
public static void main(String[] args)
{
//creating an object using new keyword
CreateObjectExample1 obj = new CreateObjectExample1();
//invoking method using the object
obj.show();
}
}

9) The String is immutable, so its value cannot be changed. As Java uses the concept of
String literal. Suppose there are 5 reference variables, all refer to one object. If one
reference variable changes the value of the object, it will be affected by all the reference
variables. That is why String objects are immutable in Java.

10) The stack frame holds the temporary, argument, and return address registers (if they
need to be saved because of a subsequent function call), and any of the saved registers that
the function will modify. It also holds local arrays and any excess local variables.

11) All Strings are stored in the String Pool (or String Intern Pool) that is allocated in the Java
heap. String pool is an implementation of the String Interring Concept. String Interning is a
method that stores only a copy of each distinct string literal. The distinct values are stored in
the String pool.

12) Static memory is allocated for declared variables by the compiler. The address can be
found using address of operator and can be assigned to a pointer. The memory is allocated
during compile time.

13) By string literal: Java String literal is created by using double quotes.
For Example: String s=“Welcome”;
By new keyword: Java String is created by using a keyword “new”.
For example: String s=new String(“Welcome”);

14) Encapsulation In object-oriented programming, encapsulation is the concept of wrapping


together of data and information in a single unit.
Polymorphism The name defines polymorphism is multiple forms. which means
polymorphism is the ability of object-oriented programming to do some work using multiple
forms.
Inheritance it is the capability of a class to inherit or derive properties or characteristics other
class. it is very important and object-oriented program as it allows reusability i.e. using a
method defined in another class by using inheritance.
Abstraction Data abstraction or Data Hiding is the concept of hiding data and showing only
relevant data to the final user.

15) Arrays are of fixed length. We cannot change the size of the arrays once they are
created. We cannot accommodate an extra element in an array after they are created.
Memory is allocated to an array during its creation only, much before the actual elements
are added to it.
Because of these drawbacks, use of arrays is less preferred. Instead of arrays, we can use
ArrayList class which addresses all these drawbacks.
Size of the ArrayList is not fixed. ArrayList can grow and shrink dynamically. Elements can be
inserted at or deleted from a particular position. ArrayList class has many methods to
manipulate the stored objects etc.,
16)

class One {
public void display() {
System.out.println("One"); } }
//inheritance
class Two extends One {
@Override
public void display() {
System.out.println("Two");
}
public int add(int x, int y) {
return x+y;
}
//Overload
public double add(double x,double y) {
return x+y; }
}
//encapsulation example
class EncapTest {
private String name;
public String getName()
return name;
}
public void setName(String newName) {
name = newName;
}
}
//abstraction
abstract class TwoWheeler {
public abstract void run();
}

class Honda extends TwoWheeler{


public void run(){
System.out.println("\nbike is Running..");
}
}

class MainClass {
public static void main(String[] args) {
One a=new One();
a.display();
Two b=new Two();
b.display();
System.out.println(b.add(4,2)); System.out.println(b.add(5.,2.));
//polymorphism
EncapTest encap = new EncapTest(); encap.setName("Tejaswini's");
System.out.print("Name : " + encap.getName() ); TwoWheeler test = new Honda();
test.run();
}
}

17) SELECT * FROM tablename;

You might also like