JAVA API , these built in classes are already compiled. That means you dont have to type them.Just use them.
Sample API to start – ArrayList
Arraylist is a advanced array. that can hold items just an array with additional features, which i will showcase below.
Declare this way
ArrayList<egg> Mylist = new ArrayList<egg>(); // An Arraylist of Objects. Note the angular brackets
egg s = new egg();
egg b = new egg();
Features of Array List
int size = Mylist.size(); // return the number of objects in the array list
boolean isin = Mylist.contains(s); // checks if the object s is in the array list
int index = Mylist.indexof(s); // returns the index. Note the index starts from 0, so the index of s will be 0
boolean empty = Mylist.isEmpty(); // return false in this case
Mylist.remove(s); // removes s from the list
remove object from list. Can allocate size dynamically( meaning you can expand the size to any limit). Arraylist<type> type says of the type is
What is the benefit of using array list?
Using Array list the code becomes easy and more scale able. With Array List if you enter the same input again it will not count as a hit, one may not follow this completely without the full background from the book. so i suggest to go through that to get better idea.
The Final Code of the game really sucks. Over explanation of same thing again and again is irritating and boring than compelling. So, I wont go through that. Dealing with array.
Euler Problem 1 – Sum of all multiples of 3 or 5 less than 100 using Array List.
If you really really want to learn programming, then programming has to be made for fun or you could make it interesting by yourself. I have included few sites below that gives mathematical or a real life situation that you need to solve using a programming language. Since we are learning JAVA why not use the same.
I am trying few problems for fun. You may try based on your likes/dislikes.
Interview Cake Problem One
Note – There is no gap between >= in Java.
Not equals Boolean Expression != or !
Java.Lang package holds many classes like String, Math or System
Why do we need packages?
To group the classes. Classes can be grouped based on functionalities
It gives naming scope to prevent name clashes . example various people can use the same name for a method,provided they do it in their own package.
Interview tip !! A full class name would be with extension from package and class name.
Two ways to import a class
1 use import as first statement. Like import.java.util.ArrayList
2 use inline where ever you want to use, java.util<ArrayList>Dog list = new.
Java.Lang package does not need to be imported, it is done automatically ( They are fundamental). So the classes within that package can be used directly.
Ponder. Import doesn’t add overhead to your code. Lets say you have 10 import statement , it is not like there would be additional class loading etc.
Import is a way to tell JVM full name of class.
Few Interesting Questions from Sample Question List of Oracle Certified Java Certification
next page 181
More in next part.
Head First Java 2nd Edition