#java tutorials for beginners by deepak
Explore tagged Tumblr posts
smartprogramming · 7 years ago
Link
Java Basic Tutorials for Beginners & Experienced in Hindi by Deepak. Interview Questions are also covered in these tutorials.
0 notes
smartprogramming · 7 years ago
Link
Program to create Calculator using switch case in Java by Deepak
0 notes
smartprogramming · 7 years ago
Link
Getting User Input in Java (using Scanner class) by Deepak
0 notes
smartprogramming · 7 years ago
Link
Virtual Machine - Virtual Machine is a software simulation of a machine which can perform operations similar to physical machine. - Virtual Machine is not physically present. - A virtual machine, usually known as a guest is created within another computing environment referred as a "host." Multiple virtual machines can exist within a single host at one time. - For eg. Calculator software in operating system, which is not physically present, but performs all the functions similar to physical calculator. - Types of Virtual Machine : 1. Hardware Based or System Based Virtual Machine 2. Application Based or Process Based Virtual Machine - JVM (Java Virtual Machine) is Application Based Virtual Machine. ------------------------------------------------------------------------------------------ Java Virtual Machine (JVM) : - It is a Runtime Engine responsible to run java based applications. - It has two main tasks : 1. load .class file 2. execute .class file - Main components of JVM : 1. Class Loader 2. Memory Areas 3. Execution Engine ---------------------------------------------------------------------------- Class Loader : - It is responsible for the following three tasks :         1. Loading 2. Linking 3. Initialisation - Loading - Linking : In linking three activities are performed :  1. Verification  2. Preparation 3. Resolution - Initialisation ------------------------------------------------------------------------------------ Memory Areas : Total 5 types of memory areas : 1. Method Area           2. Heap Area 3. Stack Area 4. PC Register           5. Native Method Area ------------------------------------------------------ Execution Engine : It  is responsible to execute java class file. It contains mainly two components : 1. Interpreter 2. JIT Compiler
0 notes
smartprogramming · 7 years ago
Link
Virtual Machine - Virtual Machine is a software simulation of a machine which can perform operations similar to physical machine. - Virtual Machine is not physically present. - A virtual machine, usually known as a guest is created within another computing environment referred as a "host." Multiple virtual machines can exist within a single host at one time. - For eg. Calculator software in operating system, which is not physically present, but performs all the functions similar to physical calculator. - Types of Virtual Machine : 1. Hardware Based or System Based Virtual Machine 2. Application Based or Process Based Virtual Machine - JVM (Java Virtual Machine) is Application Based Virtual Machine. ------------------------------------------------------------------------------------------ Java Virtual Machine (JVM) : - It is a Runtime Engine responsible to run java based applications. - It has two main tasks : 1. load .class file 2. execute .class file - Main components of JVM : 1. Class Loader 2. Memory Areas 3. Execution Engine ---------------------------------------------------------------------------- Class Loader : - It is responsible for the following three tasks :         1. Loading 2. Linking 3. Initialisation - Loading - Linking : In linking three activities are performed :  1. Verification  2. Preparation 3. Resolution - Initialisation ------------------------------------------------------------------------------------ Memory Areas : Total 5 types of memory areas : 1. Method Area           2. Heap Area 3. Stack Area 4. PC Register           5. Native Method Area ------------------------------------------------------ Execution Engine : It  is responsible to execute java class file. It contains mainly two components : 1. Interpreter 2. JIT Compiler
0 notes
smartprogramming · 7 years ago
Link
Java Softwares and Installation : -------------------------------------------------------------------------------------- Software used for Java : JDK (Java Development Kit) Download link : http://www.oracle.com/technetwork/jav... Simply install JDK, it will create a virtual environment on which we can execute java programs or softwares or website. ----------------------------------------------------------------------------------------------------------- IDE : Netbeans & Eclipse Netbeans download link : https://netbeans.org/downloads/ Eclipse download link : https://www.eclipse.org/downloads/pac...
0 notes
smartprogramming · 7 years ago
Link
FEATURES OF JAVA : 1.  Platform Independent  :-  The concept of  Write-once-run-anywhere  (known as the Platform independent) is one of the important key feature of java language that makes java as the most powerful language. The programs written on one platform can run on any platform provided the platform must have its own JVM. 2.  Portable  :-  The feature Write-once-run-anywhere makes the java language portable provided that the system must have interpreter for the JVM. Java also have the standard data size irrespective of operating system or the processor. These features makes the java as a portable language. 3.  Secure  :-  This is important feature of java. Java is very much secure as compared to any other language. Some of the points why java is secured is JVM, Security Manager, No Pointers, Access Modifiers, Exception Handling, Own Memory Management. 4.  Object Oriented  :-  Basic concepts of OOP's are OBJECT, CLASS, INHERITANCE, PLOYMORPHISM, ABSTRACTION, INCAPSULATION, DYNAMIC BINDING. Java follows all these basic concepts of OOP's. As the languages like Objective C, C++ fulfills the above four characteristics yet they are not fully object oriented languages because they are structured as well as object oriented languages. But in case of java, it is a fully Object Oriented language because object is at the outer most level of data structure in java. No stand alone methods, constants, and variables are there in java. Everything in java is object even the primitive data types can also be converted into object by using the wrapper class. 5.  Robust  :-  Dictionary meaning of Robust is Powerfull or Strong. The feature of java like Memory Allocation & Automatic Garbage Collection makes java Robust. The Java Source Code will only be compiled when it is Error Free. Also powerful Exception Handling and Type Checking mechanism makes java strong and guides you how to deal with perticular type of error. 6.  Multi-Threading  :-  Java is a Multithreaded programming language. Multithreading means a single program having different threads executing independently at the same time. Multiple threads execute instructions according to the program code in a process or a program. Multithreading works the similar way as multiple processes run on one computer. In multithreaded programs not even a single thread disturbs the execution of other thread. Threads are obtained from the pool of available ready to run threads and they run on the system CPUs. 7.  Simple, As Some features of C & C++ Eliminated  :-  Some features of C & C++ like  Memory Pointer, Preprocessor, No Array Index Limit Checking, Operator Overloading, No Automatic Garbage Collection  is removed from Java. This makes java more simple & less confusing. ---------------------------- USE OF JAVA : 1. Android Apps : Java has a rich use in Android Applications. Open your Android phone and any app, they are actually written in Java programming language, with Google's Android API, which is similar to JDK (DVM in android). Couple of years back Android has provided much needed boost and today many Java programmer are Android App developer. 2. Financial Services Industries : Java is very big in Financial Services which demands more security. API's of Data Processing & Payment Gateways are created in java. It is mostly used to write server side application, mostly without any front end, which receives data form one server (upstream), process it and sends it other process (downstream). 3. Java Web Applications : Java is also big on E-commerce and web application space. Java frameworks i.e. Spring MVC, Struts 2.0 and other frameworks are used for this web applications. Many of government, healthcare, insurance, education, defense and several other department have their web application built in Java. 4. Software Tools : Many useful software and development tools are written and developed in Java e.g. Netbans, Eclipse and InetelliJ IDE. They are also most used desktop applications for development of java and other languages. 5. Big Data Technologies : Many social networking websites like facebook twitter etc and e-commerse websites generates a lot of data day to day. So to manage this huge amount of data, Hadoop and other big data technologies are developed using java only. So Java plays an important role for big data technologies. 6. Scientific Applications : As Java is more safe, portable, maintainable and comes with better high-level concurrency tools than C++ or any other language therefore Java is often a default choice for scientific applications, including natural language processing. 7. J2ME Apps : There was time when Nokia and Samsung handsets had a large market which uses J2ME. At that time almost all games, applications, which is available in Android are written using MIDP and CLDC, part of J2ME platform. 8. Embedded Systems : Java is also used in embedded systems. Computers, Printers, Routers, ATM’s, Home Security Systems etc. all uses java a lot.
0 notes
smartprogramming · 7 years ago
Link
WHAT IS JAVA : Java is : 1. Programming Language : Java is a High Level Programming Language. It derives much of its syntax from C and C++, but it has fewer low-level facilities than either of them. 2. Platform : Java is a Platform because it has its own runtime environment that is JVM (Java Virtual Machine). JVM provides a platform which accepts the byte code and executes on the machine. ---------------------------------------------------------------------------------------------------------------- HISTORY OF JAVA is as follows:- 1991 :-   In 1991, Java was conceived by James Gosling, Patrick Naughton, Chris Warth, Ed Frank & Mike Sheridan at  Sun Microsystem. Its first name was "OAK".   1995 :-   Between 1991 to 1995 many more people contributed to the design & evolution of java. Bill Joy, Arthur van Hoff, Jonathan Payne, Frank Yellin & Tim Lindholm were main contributors. JDK Alpha and Beta  version was released. 1996 :-   In January 23, 1996 JDK 1.0  version was released. It was first stable release of java 1997 :-   In February 19,, 1997 JDK 1.1  version was released. 1998 :-   In December 8, 1998 JDK 1.2  version was released. 2000 :-   In May 8, 2000 JDK 1.3  version was released. 2002 :-   In February 6, 2002 JDK 1.4  version was released. 2004 :-   In September 30, 2004 JDK 5.0  version was released. 2006 :-   December 11, 2006 Java SE 6  version was released. 2010 :-   The acquisition of Sun Microsystems by Oracle Corporation was completed on January 27, 2010 2011 :-   In July 28, 2011 Java SE 7  version was released. 2014 :-   In March 18, 2014 Java SE 8  version was released. 2017 :-   In September 21, 2017 Java SE 9  version was released.
0 notes
smartprogramming · 7 years ago
Link
Description : In programming languages, identifiers are used for identification purpose. In Java an identifier is any name, it can be variable name, method name, class name, interface name or package name. ---------------------------------------------------------------------------------------------------------------------------- Rules for identifiers : 1. Spaces cannot be used. eg. int emp id=101; //wrong 2. Only underscore and $ sign can be used, not any other symbol in identifier name. eg. int emp_id=101; //correct     int $emp_id=101; //correct     int emp+id=101; //wrong 3. Reserved words cannot be used. eg. int public=10; //wrong     int false=10; //wrong 4. Integer value cannot be used at first position but can be used after first character. eg. int 1id=101; //wrong     int id1=101; //correct     int i1d=101; //correct     int _1id=101; //correct ---------------------------------------------------------------------------------------------------------------------------- Naming Conventions : (let us assume three words : my, java, demo; then) VARIABLE NAMES : my ....OR.... my_java ....OR.... my_java_demo METHODS NAME : my() ....OR.... myJava() ....OR.... myJavaDemo() CLASS or INTERFACE NAME : My ....OR.... MyJava ....OR.... MyJavaDemo
0 notes
smartprogramming · 7 years ago
Link
What is variable ?
1. Variable is a name of memory location where data is stored. 2. The value of variable can vary, means value can be changed. There are three types of variables : 1. Local Variables : 1.1 DECLARED : inside methods, constructors or blocks. 1.2 SCOPE : within the methods, constructors or blocks but not outside of them. 1.3 MEMORY ALLOCATION : when method, constructor or block is invoked variable is allocated; when exits, variable gets destroyed. 1.4 STORED MEMORY : stack memory 1.5 DEFAULT VALUES : doesnt have any default value, so it should be assigned before use. 1.6 ACCESS MODIFIERS : public, private or protected access specifier cannot be used. 2. Instance Variable : 2.1 DECLARED : in a class but outside methods, constructors or blocks. 2.2 SCOPE : inside the class, within all methods, constructors or blocks. 2.3 MEMORY ALLOCATION : when object is created, variable allocated memory; when object destroyed, memory releases. 2.4 STORED MEMORY : heap memory 2.5 DEFAULT VALUES : have default values eg. int has 0 value, boolean false, String null etc. 2.6 ACCESS MODIFIERS : any access modifiers can be used. 2.7 HOW TO ACCESS : a) can be accessed directly by calling the variable name inside the class.       b) in static methods they should be called using the fully qualified name, ie objectRefName.variable_name. 3. static variable : 3.1 DECLARED : with static keyword in a class but outside methods, constructors or blocks. 3.2 SCOPE : similar to instance variable ie inside the class, within all methods, constructors or blocks including static part 3.3 MEMORY ALLOCATION : when we run program and .class file is loaded, variable allocated; when class file unload, variable gets destroyed. 3.4 STORED MEMORY : non-heap memory or static memory 3.5 DEFAULT VALUES : have default values eg. int has 0 value, boolean false, String null etc. 3.6 ACCESS MODIFIERS : any access modifiers can be used. 3.7 HOW TO ACCESS : a) directly       b) by using class name       b) by using object reference name
0 notes
smartprogramming · 7 years ago
Link
What is variable ? 1. Variable is a name of memory location where data is stored. 2. The value of variable can vary, means value can be changed.
There are three types of variables : 1. Local Variables : 1.1 DECLARED : inside methods, constructors or blocks. 1.2 SCOPE : within the methods, constructors or blocks but not outside of them. 1.3 MEMORY ALLOCATION : when method, constructor or block is invoked variable is allocated; when exits, variable gets destroyed. 1.4 STORED MEMORY : stack memory 1.5 DEFAULT VALUES : doesnt have any default value, so it should be assigned before use. 1.6 ACCESS MODIFIERS : public, private or protected access specifier cannot be used.
2. Instance Variable : 2.1 DECLARED : in a class but outside methods, constructors or blocks. 2.2 SCOPE : inside the class, within all methods, constructors or blocks. 2.3 MEMORY ALLOCATION : when object is created, variable allocated memory; when object destroyed, memory releases. 2.4 STORED MEMORY : heap memory 2.5 DEFAULT VALUES : have default values eg. int has 0 value, boolean false, String null etc. 2.6 ACCESS MODIFIERS : any access modifiers can be used. 2.7 HOW TO ACCESS : a) can be accessed directly by calling the variable name inside the class.       b) in static methods they should be called using the fully qualified name, ie objectRefName.variable_name.
3. static variable : 3.1 DECLARED : with static keyword in a class but outside methods, constructors or blocks. 3.2 SCOPE : similar to instance variable ie inside the class, within all methods, constructors or blocks including static part 3.3 MEMORY ALLOCATION : when we run program and .class file is loaded, variable allocated; when class file unload, variable gets destroyed. 3.4 STORED MEMORY : non-heap memory or static memory 3.5 DEFAULT VALUES : have default values eg. int has 0 value, boolean false, String null etc. 3.6 ACCESS MODIFIERS : any access modifiers can be used. 3.7 HOW TO ACCESS : a) directly       b) by using class name       b) by using object reference name
0 notes
smartprogramming · 7 years ago
Link
Categories Of Prgramming Languages :
1. COMPUTER LANGUAGE : 1.1 Programming Language : c, c++, java, c# 1.2 Query Language : SQL (for relational databases), NoSQL (for non-relational databases), OQL (Object Query Language) 1.3 Mark-Up Languages : HTML, DHTML, XML, XHTML 1.4 Scripting Language :  1.4.1 Client Side Scripting Language : JavaScript, VBScript  1.4.2 Server Side Scripting Language : PHP, Servlets, JSP
2. TECHNOLOGIES : CSS, JQuery, AJAX
3. FRAMEWORKS : 3.1 Java Frameworks : Struts, Spring, Hibernate, JSF 3.2 PHP Frameworks : CakePHP, CodeIgnitor, Drupal, Joomla, Zend Framework 3.3 JavaScript Frameworks : Angular JS, Node JS, React JS
4. OPERATING SYSTEMS : 4.1 Mobile OS : Android, IOS, Blackberry, Symbian 4.2 DESKTOP OS : Linux, Windows, MacOS
0 notes
smartprogramming · 7 years ago
Link
History Of Programming Languages :-
1. First Generation Programming Languages : Introduced in the 1940's.
Sometimes referred as Binary Language, Machine Language, Very Low Level Language, Machine Code or Object Code.
It is a language made up of entirely 1s and 0s.
Programmers have to design their code by hand then transfer it to a computer by using a punch card, punch tape or flicking switches.
It is the only language a computer is capable of understanding without using a translation program.
Close to machines.
Modern day programmers still occasionally use machine level code, especially when programming lower level functions of the system, such as drivers, interfaces with firmware and hardware devices.
2. Second Generation Programming Languages : Introduced in the 1950's.
Sometimes referred as Assembly Language or Low Level Language.
Programmes are in the form of Alphanumeric Symbols (or Mnemonic Codes) instead of 0’s and l’s.
These alphanumeric symbols can have maximum up to 5 letter combinations e.g. ADD for addition, SUB for subtraction, START LABEL  etc. because of this feature it is also known as “Symbolic Programming Language”.
Close to machine.
Programmes are translated into machine language using Assemblers.
Not portable. Used in kernels and hardware driver, but more often find use in extremely intensive processing such as games, video editing, graphic manipulation/rendering.
Examples are :  RISC(Reduced Instruction Set Computer)
CISC(Complex Instruction Set Computer)
x86 as that is what our embedded systems and desktop computers use.
3. Third Generation Of Programming Languages : Introduced in the 1950's.
Purpose of developing High-Level Languages was to enable people to write programs easily, in their own native language environment (English).
These are Symbolic languages that use English words and/or mathematical symbols rather than mnemonic codes.
Close to humans.
Compiler (which converts the language into machine code automatically) was developed
First compiled high level programming language : in 1952 for the Mark 1 computer at the University of Manchester.
In 1954, FORTRAN was invented at IBM by John Backus. It was the first widely used high level general purpose programming language to have a functional implementation.
1) Algebraic Formula-Type Processing :- These languages are oriented towards the computational procedures for solving mathematical and statistical problems.    Examples include:
  • BASIC (Beginners All Purpose Symbolic Instruction Code)
  • FORTRAN (Formula Translation)
  • PL/I (Programming Language, Version 1)
  • ALGOL (Algorithmic Language)
  • APL (A Programming Language)
2) Business Data Processing :- These languages are best able to maintain data processing procedures and problems involved in handling files.
  Some examples include:
  • COBOL (Common Business Oriented Language)
  • RPG (Report Program Generator)
3) String and List Processing :- These are used for string manipulation, including search patterns and inserting and deleting characters.
  Examples are:
  • LISP (List Processing)
  • Prolog (Program in Logic)
4) Programming Languages (Approx 50 types in wikipedia) :- In OOP, the computer program is divided into objects.
  Examples are:
  • C++
  • Java
  • Objective C or C#
5) Visual Programming Language :- These programming languages are designed for building Windows-based applications.
  Examples are:
  • Visual Basic
  • Visual Java
  • Visual C
4. Fourth Generation Programming Languages : 1970s through the 1990s.
Also known as Very High Level Language or Non-Procedural Language.
It is Application Specific.
Close to natural language.
Closer to the domain, Further from the machine.
Fourth generation languages need approximately one tenth the number of statements that a high level languages needs to achieve the same results.
Non-computer professionals can develop software.
Examples are :  1. Query languages (SQL)
2. Report Programer Generators (RPG by IBM) : created for punched card machines.
 3. Applications generators
4. MATLAB
5. Some minicomputer applications eg PowerBuilder, FOCUS, Infotrieve-4GL, Progress 4GL etc
5. Fifth Generation Programming Languages : It is based on solving using constraints given to the program rahter than using an algorithm written by a programmer.
Introduced around 1990's.
Very closely resembles human speech.
Examples are : Prolog, Mercury, OPS5, AI etc.
These languages are also designed to make the computer "smarter".
Mainly used in artificial intelligence research.
Natural languages already available for microcomputers include Clout, Q&A, and Savvy Retriever (for use with databases) and HAL (Human Access Language).
0 notes
smartprogramming · 8 years ago
Link
History Of Computers:- before 18th century - Abacus, Slide Rule, Pascals Calculator, Leibnitz's Calculator; in 18th century - Difference Engine, Analytical Engine; in 19th century - Five Generations Of Computers Generations Of Computers :- 1. First Generation Of Computers (1942 - 1954) : The computers of first generation used vacuum tubes as the basic components for memory and circuitry for CPU (Central Processing Unit). These tubes, like electric bulbs, produced a lot of heat and the installations used to fuse frequently. Therefore, they were very expensive and only large organizations were able to afford it. The computers in this generation used machine code as the programming language. Some computers of this generation were −    ENIAC    EDVAC    UNIVAC    IBM-701    IBM-650 2. Second Generation Of Computers (1952 - 1964) : In this generation, transistors were used that were cheaper, consumed less power, more compact in size, more reliable and faster than the first generation machines made of vacuum tubes. In this generation, assembly language and high-level programming languages like FORTRAN, COBOL were used. The computers used batch processing and multiprogramming operating system. Some computers of this generation were −    IBM 1620    IBM 7094    CDC 1604    CDC 3600    UNIVAC 1108 3. Third Generation Of Computers (1964 - 1962) :- The computers of third generation used SSI and MSI Integrated Circuits (ICs) in place of transistors. A single IC has many transistors, resistors, and capacitors along with the associated circuitry. High-level languages (FORTRAN-II TO IV, COBOL, PASCAL PL/1, BASIC, ALGOL-68 etc.) were used during this generation. Some computers of this generation were −    IBM-360 series    Honeywell-6000 series    PDP (Personal Data Processor)    IBM-370/168    TDC-316 4. Fourth Generation Of Computers (1972-1989) : Computers of fourth generation used Very Large Scale Integrated (VLSI) circuits. All the high-level languages like C, C++, DBASE etc., were used in this generation. Some computers of this generation were −    DEC 10    STAR 1000    PDP 11    CRAY-1(Super Computer)    CRAY-X-MP(Super Computer) 5. Fifth Generation Of Computers (1989 - Present) : In the fifth generation, VLSI technology became ULSI (Ultra Large Scale Integration) technology, resulting in the production of microprocessor chips having ten million electronic components. This generation is based on parallel processing hardware and AI (Artificial Intelligence) software. AI is an emerging branch in computer science, which interprets the means and method of making computers think like human beings. All the high-level languages like C and C++, Java, .Net etc., are used in this generation. Some computer types of this generation are -    Desktop    Laptop    NoteBook    UltraBook    ChromeBook
0 notes
smartprogramming · 7 years ago
Link
Operators : Operators are the special symbols which perform any operation on one or more operands We can divide all the Java operators into the following groups :- 1. Arithmetic Operators  Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra.   2. Relational Operators  A relational operator compares two values and determines the relationship between them. For example, != returns true if its two operands are unequal. Relational operators are used to test whether two values are equal, whether one value is greater than another, and so forth.   3. Bitwise Operators Java defines several bitwise operators, which can be applied to the integer types, long, int, short, char, and byte. Binary AND Operator copies a bit to the result if it exists in both operands. Binary OR Operator copies a bit if it exists in either operand.   4. Logical Operators  A logical operator (sometimes called a “Boolean operator”) in Java programming is an operator that returns a Boolean result that's based on the Boolean result of one or two other expressions.   5. Assignment Operators  One of the most common operators that you'll encounter is the simple assignment operator " = ". You saw this operator in the Bicycle class; it assigns the value on its right to the operand on its left: ... This operator can also be used on objects to assign object references, as discussed in Creating Objects. 6. Misc Operators  There are few other operators supported by Java Language.  eg is Conditional Operator ( ? : ) Conditional operator is also known as the ternary operator. This operator consists of three operands and is used to evaluate Boolean expressions. The goal of the operator is to decide, which value should be assigned to the variable. The operator is written as − ----------------------------------------------------------------------------------------------------------------------------------- Literals : The values provided to the variable is known as literal. Types of literals : String literals, character literals, float literal, boolean literal, integer literal, null literal ----------------------------------------------------------------------------------------------------------------------------------- Keywords : Keywords are the predefined words having any specific meaning. In java there are total 50 keywords (48 in use and 2 not used)
0 notes
smartprogramming · 7 years ago
Link
What is Data-Type ? The type of data that we are inserting into computer is data type for ex. 10 is integer type of data, 'a' is character type of data.
Type of Data Types : Two types of Data Types : 1. Primitive Data Type : 8 type of primitive data type examples are : boolean, char, byte, short, int, long, float, double 2. Non-Primitive Data Type : examples are : String, Arrays, Class, Structure, Stacks etc
Data Type  Default Value  Default size boolean   false   1 bit (but not preciously defined) char   '\u0000'  2 byte byte   0   1 byte short   0   2 byte int   0   4 byte long   0L   8 byte float   0.0f   4 byte double   0.0d   8 byte
The eight primitive data types supported by the Java programming language are:
byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation.
short: The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with byte, the same guidelines apply: you can use a short to save memory in large arrays, in situations where the memory savings actually matters.
int: By default, the int data type is a 32-bit signed two's complement integer, which has a minimum value of -231 and a maximum value of 231-1. In Java SE 8 and later, you can use the int data type to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of 232-1. Use the Integer class to use int data type as an unsigned integer. See the section The Number Classes for more information. Static methods like compareUnsigned, divideUnsigned etc have been added to the Integer class to support the arithmetic operations for unsigned integers.
long: The long data type is a 64-bit two's complement integer. The signed long has a minimum value of -263 and a maximum value of 263-1. In Java SE 8 and later, you can use the long data type to represent an unsigned 64-bit long, which has a minimum value of 0 and a maximum value of 264-1. Use this data type when you need a range of values wider than those provided by int. The Long class also contains methods like compareUnsigned, divideUnsigned etc to support arithmetic operations for unsigned long.
float: The float data type is a single-precision 32-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. As with the recommendations for byte and short, use a float (instead of double) if you need to save memory in large arrays of floating point numbers. This data type should never be used for precise values, such as currency. For that, you will need to use the java.math.BigDecimal class instead. Numbers and Strings covers BigDecimal and other useful classes provided by the Java platform.
double: The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion, but is specified in the Floating-Point Types, Formats, and Values section of the Java Language Specification. For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency.
boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined.
char: The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).
What is the default size of boolean? Boolean doesnt have any default size, JVM allocates the size at runtime.
Why char uses 2 byte in java and what is \u0000 ? It is because java uses Unicode system than ASCII code system. The \u0000 is the lowest range of Unicode system. To get detail explanation about Unicode visit next page.
0 notes