0% found this document useful (0 votes)
6 views1 page

Java Basics: Classes, Data Types, and Syntax

The document provides an overview of a simple Java program that prints 'hello, world!' and explains the structure of the main method. It outlines Java's primitive data types, including their sizes and examples of how to declare and assign values to variables. Additionally, it covers the syntax for characters and strings in Java.

Uploaded by

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

Java Basics: Classes, Data Types, and Syntax

The document provides an overview of a simple Java program that prints 'hello, world!' and explains the structure of the main method. It outlines Java's primitive data types, including their sizes and examples of how to declare and assign values to variables. Additionally, it covers the syntax for characters and strings in Java.

Uploaded by

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

Java:

[first line:]

public class Main {


public static void main(String[] args) {
[Link]("hello, world!");
}
}

public class main { = class called main which is public so any other classes can
access it

public static void main(String[] args) { = entry point of the java program:
public = anyone can access it
static = you can run this method without creating
an instance of Main.
void = this method doesn't return any value.
main is the name of the method.
[variables and types:]

primitive data types: represents raw values

list of primitives in java: byte (number, 1 byte)


short (number, 2 bytes)
int (number, 4 bytes)
long (number, 8 bytes)
float (float number, 4 bytes)
double (float number, 8 bytes)
char (a character, 2 bytes)
boolean (true or false, 1 byte)

[Numbers:]

declare and assign number: int myNumber;


myNumber = 5;
or combine them: int myNumber = 5;

define double floating point number: double d = 4.5;


d = 3.0;
using float: float f = (float) 4.5;

shorter way using float = float f = 4.5f; // (f is a shorter way of casting float)

[characters and strings:]

chars = characters

syntax for chars: char c = 'g';

You might also like