0% found this document useful (0 votes)
5 views3 pages

Java Basics: Syntax, Data Types & More

The document outlines the aim and objectives of writing simple Java programs to demonstrate basic concepts such as syntax, data types, type casting, bitwise operations, Boolean operators, and wrapper classes. It includes a theoretical overview and a sample Java code that illustrates these concepts, along with expected outputs. The conclusion emphasizes the importance of these foundational concepts for developing robust and efficient Java applications.

Uploaded by

owen9b44
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Java Basics: Syntax, Data Types & More

The document outlines the aim and objectives of writing simple Java programs to demonstrate basic concepts such as syntax, data types, type casting, bitwise operations, Boolean operators, and wrapper classes. It includes a theoretical overview and a sample Java code that illustrates these concepts, along with expected outputs. The conclusion emphasizes the importance of these foundational concepts for developing robust and efficient Java applications.

Uploaded by

owen9b44
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

VIDYAVARDHINI’S COLLEGE OF ENGINEERING & TECHNOLOGY

DEPARTMENT OF INFORMATION TECHNOLOGY


K.T. Marg, Vasai Road (W), Dist-Palghar - 401202, Maharashtra

Aim: To write and execute simple Java programs demonstrating the concepts of basic
syntax (Hello World), data types, type casting, bitwise operations, Boolean operators,
and wrapper classes.

Objective: Simple Java programs visually demonstrate syntax, data types, type casting,
bitwise operations, Boolean operators, and wrapper classes, forming the basis of logical
and effective programming practices in Java. These concepts are vital for efficient
computation and code clarity.

Theory
1. General Theory: Java is an object-oriented language with a strict syntax
resembling C/C++. It uses classes and methods to structure programs, making
maintenance and reuse easy.

2. Hello World: The main method (public static void main(String[] args)) is the
entry point. [Link]() prints output to the console. All executable code
resides within a class.

3. Data Types: Java's primitive data types


include int, float, double, char, boolean, byte, and short. Each type stores specific
values, ensuring memory efficiency—e.g., boolean holds true or false, int stores
large integers, and float/double store decimal numbers.

4. Type Casting: Converting between types, for example, int to double (automatic
widening) or double to int (manual narrowing with parentheses), helps avoid loss
of data or rounding errors in calculations.

5. Bitwise Operations: Operations like & (AND), | (OR), ^ (XOR), ~ (complement),


and bit shifts (<<, >>, >>>) manipulate data at the binary level, useful in low-level
programming.

6. Boolean Operators: Logical (&&, ||, !) and relational operators


(==, !=, <, >, <=, >=) dictate program flow, evaluating conditions and controlling
decisions.

7. Wrapper Classes: These convert primitives to objects


(Integer, Double, Character, etc.), allowing use in Java collections and providing
utility methods for conversion and parsing.
VIDYAVARDHINI’S COLLEGE OF ENGINEERING & TECHNOLOGY
DEPARTMENT OF INFORMATION TECHNOLOGY
K.T. Marg, Vasai Road (W), Dist-Palghar - 401202, Maharashtra

Code:
import [Link];

public class JavaConceptsDemo {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

// Hello World
[Link]("Hello, World!");

// Data Types
[Link]("Enter an integer: ");
int num = [Link]();
[Link]("Enter a float: ");
float fl = [Link]();
[Link]("Enter a char: ");
char ch = [Link]().charAt(0);

// Type Casting
double d = num; // Widening
int narrow = (int) fl; // Narrowing

// Bitwise Operations
int a = num & 15; // Bitwise AND with 15
int b = num | 15; // Bitwise OR with 15

// Boolean Operators
boolean cmp = num > 100;
boolean check = (cmp && (fl < 100.0));

// Wrapper Classes
Integer numObj = [Link](num);
Character chObj = [Link](ch);

[Link]("Int: " + num + ", Float: " + fl + ", Char: " + ch);
[Link]("Double (widened): " + d + ", Int (narrowed): " + narrow);
[Link]("Bitwise AND: " + a + ", Bitwise OR: " + b);
[Link]("Comparison (num > 100): " + cmp);
[Link]("Boolean check (num>100 && fl<100.0): " + check);
[Link]("Wrapper Integer: " + numObj + ", Wrapper Character: " +
chObj);
}
}
VIDYAVARDHINI’S COLLEGE OF ENGINEERING & TECHNOLOGY
DEPARTMENT OF INFORMATION TECHNOLOGY
K.T. Marg, Vasai Road (W), Dist-Palghar - 401202, Maharashtra

Output:
C:\Users\thakk\OneDrive\Documents\java notepad>java [Link]
Hello, World!
Enter an integer: 5
Enter a float: 8.2
Enter a char: hello
Int: 5, Float: 8.2, Char: h
Double (widened): 5.0, Int (narrowed): 8
Bitwise AND: 5, Bitwise OR: 15
Comparison (num > 100): false
Boolean check (num>100 && fl<100.0): false
Wrapper Integer: 5, Wrapper Character: h

Conclusion
Understanding syntax, data types, type casting, bitwise, Boolean operators,
and wrapper classes is crucial for building robust Java applications. These foundational
concepts enable clean, efficient, and error-free code by encouraging type safety, logical
flow, and interoperability within Java’s rich ecosystem.

You might also like