: Manish Soni
: Core Java
: Poorav Publications
: 9789369914432
: 1
: CHF 7.50
:
: Programmiersprachen
: English
: 194
: DRM
: PC/MAC/eReader/Tablet
: ePUB

Core Java is the backbone of modern software development, and mastering its core concepts is essential for any aspiring programmer, whether you're just starting your journey or seeking to deepen your knowledge. This book, 'Core Java,' is designed to be your comprehensive guide to the fundamental principles of Java programming.
In the ever-evolving landscape of technology, Java remains a constant. Its versatility and platform independence have made it the language of choice for a wide range of applications, from mobile apps to web services and enterprise systems. Whether you're a student, a professional developer, or an enthusiast eager to learn, this book is crafted to meet your needs.
Our journey through the world of Java begins with the basics. We'll guide you through setting up your development environment, writing your first lines of code, and understanding the syntax that underpins the language. From there, we'll delve into the rich world of data types, control structures, and object-oriented programming, providing a solid foundation upon which to build your Java expertise. As we progress, you'll explore advanced topics such as multithreading, I/O, and exception handling, gaining the skills necessary to develop robust and efficient Java applications. We'll demystify object-oriented design principles and guide you in applying them to your projects.
Java isn't just about syntax; it's about building real-world applications. You'll learn how to work with databases, networked systems, and graphical user interfaces, giving you the tools to create software that can truly make an impact.
Throughout this book, you'll find practical examples and hands-on exercises to reinforce your understanding and hone your programming skills. Java is a language of practice, and our aim is to equip you with the knowledge and experience needed to tackle real-world challenges confidently.

CHAPTER 2 - Language Fundamentals


 

2.1 Data Types and Variables

2.1.1 Primitive Data Types

In Java, primitive data types are the basic building blocks for defining and storing simple values. They represent fundamental data types and are used to store numeric values, characters, and boolean values. Java has eight primitive data types, categorized into four groups: integers, floating-point numbers, characters, and Booleans.

Here are the eight primitive data types in Java:

1. Integers:

byte = 8-bit signed integer. Range: -128 to 127.

short = 16-bit signed integer. Range: -32,768 to 32,767.

int = 32-bit signed integer. Range: -2^31 to (2^31 - 1).

long = 64-bit signed integer. Range: -2^63 to (2^63 - 1).

Syntax

byte b = 127;

short s = 32767;

int integer = 2147483647;

long l = 9223372036854775807L; // Note the 'L' suffix for long literals.

2. Floating-Point Numbers:

float = 32-bit IEEE 754 floating-point number. Approximate range: ±3.4 x 10^38 with limited precision.

Double = 64-bit IEEE 754 floating-point number. Approximate range: ±1.7 x 10^308 with higher precision.

Syntax

float f = 3.14f; // Note the 'f' suffix for float literals

double d = 3.14159265359;

3. Characters:

char = 6-bit Unicode character. Represents a single character in the Unicode standard.

Syntax

char c = 'A';

4. Booleans:

Boolean = Represents a true or false value.

Syntax

boolean isprogrammingFun = true;

boolean isProgrammingHard = false;

2.1.2Non-Primitive Data Types

Non-Primitive Data Types user-defined data types created by users. These data types are used to store multiple values. When non-primitive data is defined, it refers to the memory location in the heap memory where the data is stored, i.e. the memory location where the object is located. For this reason, non-primitive data type variables are also called reference data types or object-only reference variables.There are five types of non-primitive data types in Java:

Class and Object – These are user_defined data types that you create by defining classes. When you create an instance(object)of a class, a reference variable is used to store the memory address of that object.

Syntax-

Class MyClass {

// Class definition

}

 

MyClass obj = new MyClass();

String- A string represents a sequence of characters for example"CoreJava","Hello world", etc. String is the class of Java.

Syntax-String str = "Core Java Book";  

Array - Arrays in Java are reference data types. They allow you to store multiple values of the same data type in a single data structure. An array variable stores the reference to the array object in memory.

Syntax –int[] num = new int[50]; // 'num' is a reference to an array of integers

Interface- Interfaces are reference data types that define a contract for classes to implement. You can use interface reference variables to store objects of any class that implements the interface.

Syntax-

interface MynewInterface {

<