Posts

Java Basic data types

Java - Basic Datatypes Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory. Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals, or characters in these variables. There are two data types available in Java − Primitive Data Types Reference/Object Data Types Primitive Data Types There are eight primitive datatypes supported by Java. Primitive datatypes are predefined by the language and named by a keyword. Let us now look into the eight primitive data types in detail. byte Byte data type is an 8-bit signed two's complement integer Minimum value is -128 (-2^7) Maximum value is 127 (inclusive)(2^7 -1) Default value is 0 Byte data type is used to save space in large arrays, mainly in p...

Java-Objects and class

Java is an Object-Oriented Language. As a language that has the Object-Oriented feature, Java supports the following fundamental concepts − Polymorphism Inheritance Encapsulation Abstraction Classes Objects Instance Method Message Parsing In this chapter, we will look into the concepts - Classes and Objects. Object  − Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behaviors – wagging the tail, barking, eating. An object is an instance of a class. Class  − A class can be defined as a template/blueprint that describes the behavior/state that the object of its type support. Objects in Java Let us now look deep into what are objects. If we consider the real-world, we can find many objects around us, cars, dogs, humans, etc. All these objects have a state and a behavior. If we consider a dog, then its state is - name, breed, color, and the behavior is - barking, wagging the tail, running. If you compa...

Java-Basic Syntax

When we consider a Java program, it can be defined as a collection of objects that communicate via invoking each other's methods. Let us now briefly look into what do class, object, methods, and instance variables mean. Object  − Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behavior such as wagging their tail, barking, eating. An object is an instance of a class. Class  − A class can be defined as a template/blueprint that describes the behavior/state that the object of its type supports. Methods  − A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed. Instance Variables  − Each object has its unique set of instance variables. An object's state is created by the values assigned to these instance variables. First Java Program Let us look at a simple code that will print the words  He...

Environment setup

Local Environment Setup If you are still willing to set up your environment for Java programming language, then this section guides you on how to download and set up Java on your machine. Following are the steps to set up the environment. Java SE is freely available from the link  Download Java . You can download a version based on your operating system. Follow the instructions to download Java and run the  .exe  to install Java on your machine. Once you installed Java on your machine, you will need to set environment variables to point to correct installation directories − Setting Up the Path for Windows Assuming you have installed Java in  c:\Program Files\java\jdk  directory − Right-click on 'My Computer' and select 'Properties'. Click the 'Environment variables' button under the 'Advanced' tab. Now, alter the 'Path' variable so that it also contains the path to the Java executable. Example, if the path is currently set to...

Java-Introduction

Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java platform (Java 1.0 [J2SE]). The latest release of the Java Standard Edition is Java SE 8. With the advancement of Java and its widespread popularity, multiple configurations were built to suit various types of platforms. For example: J2EE for Enterprise Applications, J2ME for Mobile Applications. The new J2 versions were renamed as Java SE, Java EE, and Java ME respectively. Java is guaranteed to be  Write Once, Run Anywhere. Java is − Object Oriented  − In Java, everything is an Object. Java can be easily extended since it is based on the Object model. Platform Independent  − Unlike many other programming languages including C and C++, when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over t...