Skip to main content

Posts

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;     ...
Recent posts

Coding and best practices

 Write code or write code in right way... Writing a coding solution to a problem can be done in many ways. If the solution can be obtained with less number of code lines, then it is easy to understand and maintain. But what if code is large with having millions of lines. Moreover maintenance and readability becomes difficult as the code base grows... Right?  In this blog I want to share my views and experiences on writing code efficiently and effectively with less maintenance efforts. Aspects to consider while coding: Naming convention Cyclomatic Complexity SOLID principles DRY Principle Managing dead code Comments Naming conventions: Every programming language mandates few norms in order to name variables, classes and functions etc. For ex: Java uses class names first letter to be a alphabet and rest to be lower case letters.  But if we dig little bit more, naming conventions are not limited to only upper case or lower case letters and using alphanumeric letters etc. Nam...

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...

Atomicity with Java Programming Language

 Atomicity with Java What is Atomicity Atomicity, in computer science, is considered to be a property [ALL-OR-NOTHING], that the state of a resource in an operation is not controlled by a different flow of execution at the same time [Even in time slicing operations] We know, Java is not pure object oriented programming language, due to primitive data types' design behavior. Most of the Java experts, while designing and developing applications thrives hard, to create, most secured applications considering " Atomicity in multi threaded application". Does Java language helps in developing Secured application..? The answer is no, Java programming language does not give secured applications at all, especially in multi threaded environment. As we know, Java supports 2 types of variables/data types.  Primitive data types User defined data types Primitive data types:       Java supports 8 different primitive data types. They are:   boolean    1 ...

File IO operations with java programming language

File Management in OS File management includes files and folders creation, copy and paste operations, reading the file and writing into files and deleting the files and folders  And also reading meta data about files and folders. It may include file free space, occupied space and read/write permissions etc. These above operations are considered as file management and managed by respective operating system. GUI that represents Windows File Manager File Management with Java  Though Java is platform independent, programming language depends on native file IO resources of operating system. This is possible with the Java API support. These API are categorized into 2 types. Readers and Writers: Readers and writers does the IO operations, character by character InputStream and OutputStream: Where as InputStream and OutputStream does IO operations byte by byte Below are simple Java programs that demonstrates different File IO operations. Program for creating directory package com.all...

Demonstration of Java NullPointerException

NullPointerException causes and reasons Since Java is object oriented programming language, every thing is considered to be an object. and there is always a scope of an object to be null or "No value".  Since Java supports primitive data types, Java is not considered to be pure Java object oriented programming language.   Few Notable points about NullPointerException NullPointerExceptions is unchecked exception Please read post  Exception handling and java keywords before reading this article Usually if program tries to fetch the value from reference and finds nothing as value, then program throws NullPointerException 'Zero' is not null And empty String is not considered to be null It is not the subclass of RuntimeException class Demo code that throws NullPointerException  package com.allabtjava.blog; public class DemoNullPointerException { class BeanDemo { String name; Integer ID; public String getName() { return name; } public void s...

Evolution of Java Programming Language

Evolution of Java: First of all, The Java programming language and it's tools that we currenly using is not what actually expected. This language started as a project to give solutions for embedded devices, mobile phones and other portable peripherals.  Initially, the Java was called Oak.  Why it is Oak first..? and Why it transformed to Java..? The team of five technocrats including Dr. James Gosling and also known as Dr. Java, together working on a project, which expected to give solutions on embedded devices, portable smart devices and TV Set top Boxes etc. at Sun Micro Systems.  In the process of achieving this solution, at their breaktime, team used to relax with a coffee by having a glimpse on a scenery of Oak tree next to their facility.  Once the project has come to conclusion and in the process of giving a title to it, they noticed the Oak trees [Always observing them in their break time], they named this programming language as Oak. Oak Logo Why it transfor...