Skip to main content

Posts

Showing posts with the label class

Java classes and objects

 Java Classes and Objects: Classes and objects both are treated in similar way in all programming languages. Java is not exception. Understanding classes and objects with real world example Consider a physical class room with lot of real world objects. What we Observe in class room..? Chairs  Table  Students  Teacher  Black board Markers and Erasers etc So, a programmer needs to instruct the computer, how to create a class room object and it's subsequent objects. like, chair, table, teacher and student etc. If programmer wants to create or develop a School application, he would need to create: class room object Office room object, Student object, Stationary object Play room object etc Let us now create School application with above mentioned objects and classes using java programming language. To create Objects, first of all, we have to create respective classes in java public class School_Application{      public Student students;     ...

CHEAT SHEET for java List interface, LinkedList and ArrayList

Consider Below points before choosing List concrete implementations for your use case:  ArrayList is a linear data structure and  re-sizable/dynamic array   Initial size can be given. and if not given the default size is 10   It is always good practice to give initial size and advised not to give very large number as size   Good programmers prefer ArrayList to LinkedList if retrieval operations is done more frequently than insertion and deletions of elements.   Better choose LinkedList if insertion and deletion operations are done frequently compared to retrieval operations.   Lists are not sorted. if required use Collections.sort() to sort   Collections.sort() uses optimized merge sort [tim sort] on ArrayList   However legacy merge sort also can be used using a switch. But it is going to be deprecated  in near future  The major difference between ArrayList and LinkedList is RandomAccess behavior...