Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › How well does Java translate to C?
New Posts  All Forums:Forum Nav:

How well does Java translate to C?

post #1 of 14
Thread Starter 
I'm currently learning Java this semester then going to C next semester.

I understand just about every basic idea of Java (printing, DateFormats, DecimalFormats, if, else, switch, while, do-while, for, Arrays, Stacks, classes, methods, etc etc etc)

How easy will C be? Or is it a completely different world?
    
CPUMotherboardGraphicsRAM
AMD Phenom II X6 1090T Black Edition ASUS M4A89GTD PRO/USB3 XFX HD-577A-ZNFC Radeon HD 5770 G.SKILL 8gb (2x4gb) 1333mhz 
Hard DriveOSMonitorKeyboard
WD Caviar Black WD1002FAEX 1TB 7200 R Windows 7 Home Premium (none yet) Nothing special 
PowerCaseMouse
CORSAIR CMPSU-850TX 850W COOLER MASTER HAF 922 Logitech G700 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
AMD Phenom II X6 1090T Black Edition ASUS M4A89GTD PRO/USB3 XFX HD-577A-ZNFC Radeon HD 5770 G.SKILL 8gb (2x4gb) 1333mhz 
Hard DriveOSMonitorKeyboard
WD Caviar Black WD1002FAEX 1TB 7200 R Windows 7 Home Premium (none yet) Nothing special 
PowerCaseMouse
CORSAIR CMPSU-850TX 850W COOLER MASTER HAF 922 Logitech G700 
  hide details  
Reply
post #2 of 14
well if you were talking about C++ i here knowing java gives you a head start. C requires a lot of stuff to be done manually stuff like memory management... If I remember correctly.
Chris-PC
(16 items)
 
Core 2 Haf
(15 items)
 
Acer 5920G
(13 items)
 
CPUMotherboardGraphicsGraphics
Phenom II 1100T AsRock Extreme4 990FX HD4850 HD4850 
RAMHard DriveHard DriveHard Drive
Kingston HyperX DDR3 KHX1600C9D3K2/8G Barracuda 7200.10 WD Green Crucial M4 
CoolingOSMonitorMonitor
EVGA Superclock CPU Cooler Win 7 Ultimate 64bit Hanns,G Hi221 Dell E198WFP 
KeyboardPowerCaseAudio
Saitek Eclipse Corsair TX850W NZXT M59 Asus Xonar D1 
CPUMotherboardGraphicsRAM
C2Q Q9550 ASUS P5E3 Deluxe Wifi-AP GTX 570 Samsung Green 
Hard DriveCoolingOSOS
55gb, 320Gb, 500GB, 1TB Hyper 212 EVO Win 7 Ultimate 64bit Lubuntu 12.10 x64 
OSPowerCase
OS X 10.6.8 TX750 Haf 912 
CPUGraphicsRAMHard Drive
T9300 GT 240M DDR2  WD10JPVT 
OS
Win 7 Ultimate 64bit 
  hide details  
Reply
Chris-PC
(16 items)
 
Core 2 Haf
(15 items)
 
Acer 5920G
(13 items)
 
CPUMotherboardGraphicsGraphics
Phenom II 1100T AsRock Extreme4 990FX HD4850 HD4850 
RAMHard DriveHard DriveHard Drive
Kingston HyperX DDR3 KHX1600C9D3K2/8G Barracuda 7200.10 WD Green Crucial M4 
CoolingOSMonitorMonitor
EVGA Superclock CPU Cooler Win 7 Ultimate 64bit Hanns,G Hi221 Dell E198WFP 
KeyboardPowerCaseAudio
Saitek Eclipse Corsair TX850W NZXT M59 Asus Xonar D1 
CPUMotherboardGraphicsRAM
C2Q Q9550 ASUS P5E3 Deluxe Wifi-AP GTX 570 Samsung Green 
Hard DriveCoolingOSOS
55gb, 320Gb, 500GB, 1TB Hyper 212 EVO Win 7 Ultimate 64bit Lubuntu 12.10 x64 
OSPowerCase
OS X 10.6.8 TX750 Haf 912 
CPUGraphicsRAMHard Drive
T9300 GT 240M DDR2  WD10JPVT 
OS
Win 7 Ultimate 64bit 
  hide details  
Reply
post #3 of 14
You learning C or C++? C doesn't have strings nor classes. Where as C++ does.

Either one would be easier to learn once you know the basics of Java though as Java's syntax is very much C-like
post #4 of 14
There is no OOP in C. So no classes, private variables, objects.
Small command prompt programs are easier in C but once you want to use a GUI or send messsages over a network you have to write a lot more code to get this done.
the syntax is mostly the same, for/if/switchcase is all the same.

and like cdoublejj said, C doesn't run on a virtual machine so it doesn't has garbage collection.
if you do something like
char *array = malloc(32);
*array = malloc(32);

then you have 32 bytes allocated in your memory that you can't access and will stay there until you close the program. This is called a memory leak.
To solve this you have to release the memory before allocating more memory.

char *array = malloc(32);
free(array);
*array = malloc(32);

This very often leads to bugs because you freed something too early and then you tried reading data that was no longer allocated.

Those * are used to declarate pointers. Pointers are probably the hardest thing to get used to. In java everything is automaticly a pointer except the primitive types (int/char/double/etc). In C you have to write yourself if something is gonna be a pointer. After 3 years of learning C at school i still don't know when i have to use * or & or nothing. Luckily the compiler usually catches those errors.
Edited by Sisaroth - 11/1/12 at 3:03am
MySys
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6400 @ 3,05 ASRock 4Core1600P35-WiFi+ Powercolor HD 4650 Corsair 4 GB DDR2-800 
Hard DriveOSPower
Seagate 250 GB Windows XP Antec 380W 
  hide details  
Reply
MySys
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6400 @ 3,05 ASRock 4Core1600P35-WiFi+ Powercolor HD 4650 Corsair 4 GB DDR2-800 
Hard DriveOSPower
Seagate 250 GB Windows XP Antec 380W 
  hide details  
Reply
post #5 of 14
The thing is if you can learn one language its pretty easy to switch to another language you just have to read the syntax.

So it won't be hard. I myself learned Java then C++ then C(weird right?).
post #6 of 14
Quote:
Originally Posted by Sisaroth View Post

and like cdoublejj said, C doesn't run on a virtual machine so it doesn't has garbage collection.

The fact that Java runs in a virtual machine isn't correlated with the presence of GC at all.

See, the D language has GC and it actually doesn't run in a VM.

Also, there is actually a GC algorithm for C: Hans-Böhm, which works as a plugin and gets compiled with your code.
Quote:
Originally Posted by Makyl View Post

I myself learned Java then C++ then C(weird right?).

Not necessarily weird to start with Java since its a good starter language and the syntax is more easy-to-use.

But sure from a programming standpoint its a bit in reverse order. tongue.gif
Ti-89 Titanium
(13 items)
 
 
Would be nice!
(4 items)
 
CPUMotherboardRAMHard Drive
Motorola 68k @16 MHz Ti-89 HW4 256 KB 2.6 MB Flash ROM 
OSMonitorPowerCase
Ti-89 OS 3.10 LCD Dot-Matrix 160x100 4x 1.5V AAA Ti-89 HW4 Black 
CPUMotherboardGraphicsRAM
Intel Core™ i7 930 Gigabyte GA-X58A-UD3R 2.0 Gigabyte GTX 470 SOC G.Skill RX 2x4GB 1600C8 
Hard DriveHard DriveOptical DriveCooling
PNY Prevail Elite 120GB Hitachi 7K1000.C 1TB LG GH24LS50 Noctua NH-C12P SE14 
OSOSMonitorKeyboard
Windows 8 Pro x64 Linux Mint 14 x64 Samsung BX2250 Logitech Illuminated 
PowerCaseMouseAudio
Be Quiet! S.P. E⁷ 600W Fractal Design Core 3000 Logitech Pilot Optical AKG K240 Studio 
CPUCoolingPowerCase
Haswell Thermalright Macho Rev.A B/W Silverstone ST60F-PS Silverstone SG10 
  hide details  
Reply
Ti-89 Titanium
(13 items)
 
 
Would be nice!
(4 items)
 
CPUMotherboardRAMHard Drive
Motorola 68k @16 MHz Ti-89 HW4 256 KB 2.6 MB Flash ROM 
OSMonitorPowerCase
Ti-89 OS 3.10 LCD Dot-Matrix 160x100 4x 1.5V AAA Ti-89 HW4 Black 
CPUMotherboardGraphicsRAM
Intel Core™ i7 930 Gigabyte GA-X58A-UD3R 2.0 Gigabyte GTX 470 SOC G.Skill RX 2x4GB 1600C8 
Hard DriveHard DriveOptical DriveCooling
PNY Prevail Elite 120GB Hitachi 7K1000.C 1TB LG GH24LS50 Noctua NH-C12P SE14 
OSOSMonitorKeyboard
Windows 8 Pro x64 Linux Mint 14 x64 Samsung BX2250 Logitech Illuminated 
PowerCaseMouseAudio
Be Quiet! S.P. E⁷ 600W Fractal Design Core 3000 Logitech Pilot Optical AKG K240 Studio 
CPUCoolingPowerCase
Haswell Thermalright Macho Rev.A B/W Silverstone ST60F-PS Silverstone SG10 
  hide details  
Reply
post #7 of 14
Quote:
Originally Posted by NoDoubtFilms View Post

I'm currently learning Java this semester then going to C next semester.
I understand just about every basic idea of Java (printing, DateFormats, DecimalFormats, if, else, switch, while, do-while, for, Arrays, Stacks, classes, methods, etc etc etc)
How easy will C be? Or is it a completely different world?

Coming from Java, it will be easier than learning C from scratch - I can tell you that much.
But in the world of C, you get to do most things yourself.
Quote:
Originally Posted by Plan9 View Post

You learning C or C++? C doesn't have strings nor classes. Where as C++ does.
Either one would be easier to learn once you know the basics of Java though as Java's syntax is very much C-like

+1
Quote:
Originally Posted by Sisaroth View Post

There is no OOP in C. So no classes, private variables, objects.
Small command prompt programs are easier in C but once you want to use a GUI or send messsages over a network you have to write a lot more code to get this done.
the syntax is mostly the same, for/if/switchcase is all the same.
and like cdoublejj said, C doesn't run on a virtual machine so it doesn't has garbage collection.
if you do something like
char *array = malloc(32);
*array = malloc(32);
then you have 32 bytes allocated in your memory that you can't access and will stay there until you close the program. This is called a memory leak.
To solve this you have to release the memory before allocating more memory.
char *array = malloc(32);
free(array);
*array = malloc(32);
This very often leads to bugs because you freed something too early and then you tried reading data that was no longer allocated.
Those * are used to declarate pointers. Pointers are probably the hardest thing to get used to. In java everything is automaticly a pointer except the primitive types (int/char/double/etc). In C you have to write yourself if something is gonna be a pointer. After 3 years of learning C at school i still don't know when i have to use * or & or nothing. Luckily the compiler usually catches those errors.

typedefs solve the not knowing when to use a pointer problem/confusion.
Code:
typedef struct _my_type
{
        int val1;
        int val2;
} my_type, *p_my_type;

Then just use p_my_type everywhere in the code. No need for "*" or "&".

Also you can use realloc(). No need to free and then release to allocate memory at the same address.
Quote:
Originally Posted by Makyl View Post

The thing is if you can learn one language its pretty easy to switch to another language you just have to read the syntax.
So it won't be hard. I myself learned Java then C++ then C(weird right?).

Bit more than just reading the syntax, but sure tongue.gif

Quote:
Originally Posted by adridu59 View Post

The fact that Java runs in a virtual machine isn't correlated with the presence of GC at all.
See, the D language has GC and it actually doesn't run in a VM.
Also, there is actually a GC algorithm for C: Hans-Böhm, which works as a plugin and gets compiled with your code.
Not necessarily weird to start with Java since its a good starter language and the syntax is more easy-to-use.
But sure from a programming standpoint its a bit in reverse order. tongue.gif

The problem is that without the managed type of VM like in Java, the GC doesn't know enough about the program to be efficient enough so this is why you typically see the managed runtime and GC association. Garbage collection is just not something that is well suited to C or C++, though it is quite neat I must say. A virtual machine is different to a runtime - the runtime is where the GC lives.

Although arguably, the Java GC is pretty crap.
Edited by tompsonn - 11/2/12 at 12:55am
My System
(30 items)
 
"Zeus"
(13 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i5 2500K (4.5ghz @ 1.320v) Gigabyte Z68X-UD3R-B3 MSI R7970 Lightning Corsair 16GB (4x4GB) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Crucial M4 128GB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 7 Ultimate 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2212HM Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Microsoft IntelliMouse Optical  XTRAC Ripper XXL 
AudioAudioAudioAudio
Westone W3 IEMs RE-272 IEMs Shure SE-215 IEMs Schiit Bifrost DAC 
AudioAudio
Schiit Asgard 2 amp HiVi Swan M50W 2.1 
CPUMotherboardGraphicsRAM
Intel Core i7 950 GA-X58-UD3R Radeon HD 5450  24GB Corsair @ 1333mhz 
Hard DriveOSPowerCase
4x WD Cavair Red 1TB in RAID 0 Windows Server 2008 R2 x64 Corsair HX-520 LianLi LanCool 
  hide details  
Reply
My System
(30 items)
 
"Zeus"
(13 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i5 2500K (4.5ghz @ 1.320v) Gigabyte Z68X-UD3R-B3 MSI R7970 Lightning Corsair 16GB (4x4GB) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Crucial M4 128GB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 7 Ultimate 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2212HM Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Microsoft IntelliMouse Optical  XTRAC Ripper XXL 
AudioAudioAudioAudio
Westone W3 IEMs RE-272 IEMs Shure SE-215 IEMs Schiit Bifrost DAC 
AudioAudio
Schiit Asgard 2 amp HiVi Swan M50W 2.1 
CPUMotherboardGraphicsRAM
Intel Core i7 950 GA-X58-UD3R Radeon HD 5450  24GB Corsair @ 1333mhz 
Hard DriveOSPowerCase
4x WD Cavair Red 1TB in RAID 0 Windows Server 2008 R2 x64 Corsair HX-520 LianLi LanCool 
  hide details  
Reply
post #8 of 14
Quote:
Originally Posted by tompsonn View Post

Bit more than just reading the syntax, but sure tongue.gif.

Yeah but it would be easy to learn another language of you know one of the languages. It becomes quite easy,actually.
post #9 of 14
WOAH, i never said any thin at all about Garbage Collection or VM. What i'm saying is some stuff that is done for you in C++ has to be done by hand (more or less).
Chris-PC
(16 items)
 
Core 2 Haf
(15 items)
 
Acer 5920G
(13 items)
 
CPUMotherboardGraphicsGraphics
Phenom II 1100T AsRock Extreme4 990FX HD4850 HD4850 
RAMHard DriveHard DriveHard Drive
Kingston HyperX DDR3 KHX1600C9D3K2/8G Barracuda 7200.10 WD Green Crucial M4 
CoolingOSMonitorMonitor
EVGA Superclock CPU Cooler Win 7 Ultimate 64bit Hanns,G Hi221 Dell E198WFP 
KeyboardPowerCaseAudio
Saitek Eclipse Corsair TX850W NZXT M59 Asus Xonar D1 
CPUMotherboardGraphicsRAM
C2Q Q9550 ASUS P5E3 Deluxe Wifi-AP GTX 570 Samsung Green 
Hard DriveCoolingOSOS
55gb, 320Gb, 500GB, 1TB Hyper 212 EVO Win 7 Ultimate 64bit Lubuntu 12.10 x64 
OSPowerCase
OS X 10.6.8 TX750 Haf 912 
CPUGraphicsRAMHard Drive
T9300 GT 240M DDR2  WD10JPVT 
OS
Win 7 Ultimate 64bit 
  hide details  
Reply
Chris-PC
(16 items)
 
Core 2 Haf
(15 items)
 
Acer 5920G
(13 items)
 
CPUMotherboardGraphicsGraphics
Phenom II 1100T AsRock Extreme4 990FX HD4850 HD4850 
RAMHard DriveHard DriveHard Drive
Kingston HyperX DDR3 KHX1600C9D3K2/8G Barracuda 7200.10 WD Green Crucial M4 
CoolingOSMonitorMonitor
EVGA Superclock CPU Cooler Win 7 Ultimate 64bit Hanns,G Hi221 Dell E198WFP 
KeyboardPowerCaseAudio
Saitek Eclipse Corsair TX850W NZXT M59 Asus Xonar D1 
CPUMotherboardGraphicsRAM
C2Q Q9550 ASUS P5E3 Deluxe Wifi-AP GTX 570 Samsung Green 
Hard DriveCoolingOSOS
55gb, 320Gb, 500GB, 1TB Hyper 212 EVO Win 7 Ultimate 64bit Lubuntu 12.10 x64 
OSPowerCase
OS X 10.6.8 TX750 Haf 912 
CPUGraphicsRAMHard Drive
T9300 GT 240M DDR2  WD10JPVT 
OS
Win 7 Ultimate 64bit 
  hide details  
Reply
post #10 of 14
I learned C and Java at the same time. The procedural aspect of C gave me a more rewarding feeling as you had to do a bit more programming to achieve similar results. You also have to manage the memory manually if you are dealing with pointers which can be tricky; whenever you use the keyword new, you also use a corresponding delete to deallocate the memory. Structs in C are essentially classes without methods. Also when you end a character array in C you have to use the null character '\0'.

Also, the first thing you should learn are how to use scanf and printf statements as they will be used very frequently. Also, learn about the precompiled headers that are often used.

There are vast amount of libraries in java that can do complex things in one statement, in C it is not like that. Coming from Java and knowing the basics, you should pick up C quickly.
Edited by surfbumb - 11/3/12 at 1:07am
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 8 Samsung S23A700D 120Hz 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 8 Samsung S23A700D 120Hz 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › How well does Java translate to C?